85 lines
1.6 KiB
Dart
85 lines
1.6 KiB
Dart
import 'package:pcasttv/services/auth_service.dart';
|
|
import 'package:velocity_x/velocity_x.dart';
|
|
|
|
class LoginStore extends VxStore {
|
|
AuthService service = AuthService();
|
|
|
|
var isLogged = false;
|
|
|
|
String? message = '';
|
|
|
|
String email = '';
|
|
String password = '';
|
|
|
|
String? token;
|
|
int? userId;
|
|
String? userName;
|
|
String? userType;
|
|
|
|
Future<void> login() async {
|
|
try {
|
|
var response = await service.login(email, password);
|
|
AuthMessage(response.message!);
|
|
if (response.token != '' || response.message == '') {
|
|
token = response.token;
|
|
userId = response.userId;
|
|
userName = response.userName;
|
|
userType = response.userType;
|
|
isLogged = true;
|
|
AuthLogged(true);
|
|
}
|
|
} catch (e) {
|
|
AuthMessage("SETEI NA STORE UMA EXCEPTION: $e");
|
|
}
|
|
}
|
|
|
|
Future<void> logout() async {
|
|
message = null;
|
|
token = null;
|
|
userId = null;
|
|
userName = null;
|
|
userType = null;
|
|
isLogged = false;
|
|
}
|
|
}
|
|
|
|
class AuthLogged extends VxMutation<LoginStore> {
|
|
final bool value;
|
|
AuthLogged(this.value);
|
|
|
|
@override
|
|
perform() {
|
|
store!.isLogged = value;
|
|
}
|
|
}
|
|
|
|
class AuthMessage extends VxMutation<LoginStore> {
|
|
final String value;
|
|
AuthMessage(this.value);
|
|
|
|
@override
|
|
perform() {
|
|
store!.message = value;
|
|
}
|
|
}
|
|
|
|
class AuthEmail extends VxMutation<LoginStore> {
|
|
final String value;
|
|
AuthEmail(this.value);
|
|
|
|
@override
|
|
perform() {
|
|
store!.email = value;
|
|
}
|
|
}
|
|
|
|
class AuthPassword extends VxMutation<LoginStore> {
|
|
final String value;
|
|
AuthPassword(this.value);
|
|
|
|
@override
|
|
perform() {
|
|
store!.password = value;
|
|
}
|
|
}
|