This commit is contained in:
@ -4,14 +4,14 @@ import 'package:get/get.dart';
|
||||
import 'package:encrypt_shared_preferences/provider.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import 'package:f0ckapp/models/user.dart';
|
||||
|
||||
class AuthController extends GetxController {
|
||||
final EncryptedSharedPreferencesAsync storage =
|
||||
EncryptedSharedPreferencesAsync.getInstance();
|
||||
|
||||
RxnString token = RxnString();
|
||||
RxnInt userId = RxnInt();
|
||||
RxnString avatarUrl = RxnString();
|
||||
RxnString username = RxnString();
|
||||
Rxn<User> user = Rxn<User>();
|
||||
RxBool isLoading = false.obs;
|
||||
RxnString error = RxnString();
|
||||
|
||||
@ -47,9 +47,7 @@ class AuthController extends GetxController {
|
||||
} catch (_) {}
|
||||
}
|
||||
token.value = null;
|
||||
userId.value = null;
|
||||
avatarUrl.value = null;
|
||||
username.value = null;
|
||||
user.value = null;
|
||||
await storage.remove('token');
|
||||
}
|
||||
|
||||
@ -66,11 +64,7 @@ class AuthController extends GetxController {
|
||||
final dynamic data = json.decode(response.body);
|
||||
if (data['token'] != null) {
|
||||
await saveToken(data['token']);
|
||||
userId.value = data['userid'];
|
||||
avatarUrl.value = data['avatar'] != null
|
||||
? 'https://f0ck.me/t/${data['avatar']}.webp'
|
||||
: null;
|
||||
this.username.value = data['user'];
|
||||
user.value = User.fromJson(data);
|
||||
return true;
|
||||
} else {
|
||||
error.value = 'Kein Token erhalten';
|
||||
@ -95,13 +89,7 @@ class AuthController extends GetxController {
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
final dynamic data = json.decode(response.body);
|
||||
userId.value = data['userid'] != null
|
||||
? int.tryParse(data['userid'].toString())
|
||||
: null;
|
||||
avatarUrl.value = data['avatar'] != null
|
||||
? 'https://f0ck.me/t/${data['avatar']}.webp'
|
||||
: null;
|
||||
username.value = data['user'];
|
||||
user.value = User.fromJson(data);
|
||||
} else {
|
||||
await logout();
|
||||
}
|
||||
|
Reference in New Issue
Block a user