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

@@ -203,9 +203,27 @@ class _HomePageState extends State<HomePage> {
super.dispose();
}
_logoutPinAccount() async {
setState(() {
_isLoading = true;
});
try {
await context.read<MainModel>().logoutPinAccount();
Navigator.pushNamedAndRemoveUntil(context, "/pin_login", (r) => false);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
} finally {
setState(() {
_isLoading = false;
});
}
}
@override
Widget build(BuildContext context) {
User? user = Provider.of<MainModel>(context).user;
var mainModel = context.watch<MainModel>();
User? user = mainModel.user;
if (user == null) {
Future.microtask(
@@ -213,7 +231,7 @@ class _HomePageState extends State<HomePage> {
return Container();
}
login = Provider.of<MainModel>(context).isLogin();
login = mainModel.isLogin();
LanguageModel languageModel = Provider.of<LanguageModel>(context);
final faqBtn = TaskButton("faq.btn",
@@ -357,7 +375,7 @@ class _HomePageState extends State<HomePage> {
selectedColor: Colors.white,
color: Colors.blue,
children: <Widget>[
Icon(MaterialCommunityIcons.account_tie,size: 25),
Icon(MaterialCommunityIcons.account_tie, size: 25),
],
onPressed: (i) => this.setState(() {
isFcs[0] = !isFcs[0];
@@ -387,11 +405,14 @@ class _HomePageState extends State<HomePage> {
color: buttonColor,
),
);
final pinLoginBtn = IconButton(
onPressed: () {
Navigator.of(context)
.push(CupertinoPageRoute(builder: (context) => PinLoginPage()));
Navigator.pushAndRemoveUntil(
context,
CupertinoPageRoute(
builder: (BuildContext context) => PinLoginPage()),
(r) => false);
},
iconSize: 25,
icon: Icon(
@@ -400,6 +421,19 @@ class _HomePageState extends State<HomePage> {
),
);
final pinLogoutBtn = IconButton(
onPressed: () {
showConfirmDialog(context, "home.pin.logout.confirm", () async {
await _logoutPinAccount();
});
},
iconSize: 25,
icon: Icon(
MaterialCommunityIcons.lock_open_variant_outline,
color: buttonColor,
),
);
var searchInput = Row(children: [
Expanded(
child: Padding(
@@ -478,7 +512,7 @@ class _HomePageState extends State<HomePage> {
profileBtn,
]
: <Widget>[
pinLoginBtn,
mainModel.isPinLogin ? pinLogoutBtn : pinLoginBtn,
fcsToggle,
profileBtn,
]

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();
}
}

View File

@@ -53,7 +53,11 @@ class _SplashScreenState extends State<SplashScreen> {
if (mainModel.isFirstLaunch) {
page = "/language_selection";
} else if (mainModel.isLogin()) {
page = "/home";
if (mainModel.isLockOn) {
page = "/pin_login";
} else {
page = "/home";
}
} else {
page = "/welcome";
}