add pin login and add pin code

This commit is contained in:
tzw
2024-10-04 13:55:59 +06:30
parent b5023a4171
commit 81dfeb037d
18 changed files with 340 additions and 68 deletions

View File

@@ -17,6 +17,7 @@ class MainModel extends ChangeNotifier {
String? messagingToken;
User? user;
User? _fbUser;
PackageInfo? packageInfo;
set setMessaginToken(token) {
@@ -29,6 +30,9 @@ class MainModel extends ChangeNotifier {
bool isLoaded = false;
bool isOnline = false;
bool isFirstLaunch = false;
bool isLockOn = false;
bool get isPinLogin => user?.isPinLogin ?? false;
MainModel() {
NetworkConnectivity.instance.statusStream.listen((data) {
@@ -83,6 +87,7 @@ class MainModel extends ChangeNotifier {
await _listenSetting();
this.isFirstLaunch = await SharedPref.isFirstLaunch() ?? true;
this.packageInfo = await PackageInfo.fromPlatform();
this.isLockOn = await SharedPref.getPinLockOn() ?? false;
userListener?.cancel();
userListener =
@@ -91,6 +96,17 @@ class MainModel extends ChangeNotifier {
bool diffPrivilege =
_user != null && (user == null || user!.diffPrivileges(_user));
bool loggingOut = user != null && _user == null;
if (_user != null) {
if (!_user.isPinLogin) {
_fbUser = _user;
}
}
if ((_fbUser?.id == _user?.id)) {
_user?.pinToken = null;
}
user = _user;
if (_user != null) {
@@ -101,6 +117,7 @@ class MainModel extends ChangeNotifier {
}
}
}
if (loggingOut) {
for (final m in models) {
m.logout();
@@ -196,4 +213,13 @@ class MainModel extends ChangeNotifier {
Future<void> deleteAccount() async {
return await Services.instance.authService.deleteAccount();
}
Future<void> pinLogin({required String fcsID, required String pin}) async {
await Services.instance.authService
.pinLogin(fcsID: fcsID, pin: pin, currentUserId: _fbUser?.id ?? '');
}
Future<void> logoutPinAccount() async {
await Services.instance.authService.logoutPinAccount();
}
}