You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.3 KiB
71 lines
1.3 KiB
import 'dart:async';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:mobx/mobx.dart';
|
|
import 'package:cake_wallet/src/domain/services/user_service.dart';
|
|
|
|
part 'authentication_store.g.dart';
|
|
|
|
class AuthenticationStore = AuthenticationStoreBase with _$AuthenticationStore;
|
|
|
|
enum AuthenticationState {
|
|
uninitialized,
|
|
allowed,
|
|
denied,
|
|
authenticated,
|
|
unauthenticated,
|
|
active,
|
|
loading,
|
|
created,
|
|
restored,
|
|
readyToLogin
|
|
}
|
|
|
|
abstract class AuthenticationStoreBase with Store {
|
|
AuthenticationStoreBase({@required this.userService}) {
|
|
state = AuthenticationState.uninitialized;
|
|
}
|
|
|
|
final UserService userService;
|
|
|
|
@observable
|
|
AuthenticationState state;
|
|
|
|
// @observable
|
|
// String errorMessage;
|
|
|
|
Future started() async {
|
|
final canAuth = await userService.canAuthenticate();
|
|
state = canAuth ? AuthenticationState.allowed : AuthenticationState.denied;
|
|
}
|
|
|
|
@action
|
|
void created() {
|
|
state = AuthenticationState.created;
|
|
}
|
|
|
|
@action
|
|
void restored() {
|
|
state = AuthenticationState.restored;
|
|
}
|
|
|
|
@action
|
|
void loggedIn() {
|
|
state = AuthenticationState.authenticated;
|
|
}
|
|
|
|
@action
|
|
void inactive() {
|
|
state = AuthenticationState.unauthenticated;
|
|
}
|
|
|
|
@action
|
|
void active() {
|
|
state = AuthenticationState.active;
|
|
}
|
|
|
|
@action
|
|
void loggedOut() {
|
|
state = AuthenticationState.uninitialized;
|
|
}
|
|
}
|