From 8893cc4740a403fc9b82b3986b4a299ef04bfe9e Mon Sep 17 00:00:00 2001 From: "snehalathad@aissel.com" Date: Wed, 9 Oct 2024 14:23:25 +0530 Subject: [PATCH] logout fixes --- lib/utils/sessionmanager.dart | 6 ++++- lib/view/login.dart | 42 ++++++++++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/lib/utils/sessionmanager.dart b/lib/utils/sessionmanager.dart index 75fedf3..7f0c92e 100644 --- a/lib/utils/sessionmanager.dart +++ b/lib/utils/sessionmanager.dart @@ -2,7 +2,7 @@ import 'package:shared_preferences/shared_preferences.dart'; class SessionManager { static final SessionManager _instance = SessionManager._(); - static const String _loggedInKey = 'loggedIn'; + static const String _loggedInKey = 'isloggedin'; factory SessionManager() { return _instance; @@ -27,6 +27,10 @@ class SessionManager { Future logoutSession(bool value) async { final prefs = await SharedPreferences.getInstance(); + //secretkey + await prefs.setBool("isloggedin", value); + await prefs.setBool("isloggedout", true); + await prefs.setBool(_loggedInKey, value); } } diff --git a/lib/view/login.dart b/lib/view/login.dart index af3b2b9..bbd276f 100644 --- a/lib/view/login.dart +++ b/lib/view/login.dart @@ -38,6 +38,7 @@ class _LoginScreenState extends State { late Future _domain; late Future _key; late Future _login; + late Future _logout; String platform = "android"; var provider; @override @@ -63,13 +64,16 @@ class _LoginScreenState extends State { // _domain = _prefs.then((SharedPreferences prefs) { // return prefs.getString('domain') ?? ""; // }); - _key = _prefs.then((SharedPreferences prefs) { - secretKeyTextConrtroller.text = prefs.getString('secretkey') ?? ""; - return prefs.getString('secretkey') ?? ""; - }); + // _key = _prefs.then((SharedPreferences prefs) { + // secretKeyTextConrtroller.text = prefs.getString('secretkey') ?? ""; + // return prefs.getString('secretkey') ?? ""; + // }); _login = _prefs.then((SharedPreferences prefs) { return prefs.getBool('isloggedin') ?? false; }); + _logout = _prefs.then((SharedPreferences prefs) { + return prefs.getBool('isloggedout') ?? false; + }); } init() async { @@ -240,6 +244,29 @@ class _LoginScreenState extends State { if (textFieldsValidation(provider).isEmpty) { print("email:${emailTextController.text}"); + // if (await _logout) { + // print("LOGOUT"); + // provider.code = secretKeyTextConrtroller.text; + // Map resp = await provider.verifyCode( + // emailTextController.text, secretKeyTextConrtroller.text); + // if (resp["code"] == "1200") { + // provider.loading = false; + // provider.showCodeField = false; + // provider.showMessage = true; + // _displaySnackBar("You have logged in successfully"); + // _saveprefs(resp["token"], emailTextController.text, + // secretKeyTextConrtroller.text, true) + // .then((value) { + // Navigator.of(context).pushReplacement( + // MaterialPageRoute( + // builder: (context) => NavigationHomeScreen()), + // ); + // }); + // } else { + // provider.message = resp["message"]; + // } + // } else { + print("FIRST LOGIN"); if (!provider.showCodeField) { provider.email = emailTextController.text; String encoded = @@ -291,6 +318,7 @@ class _LoginScreenState extends State { secretKeyTextConrtroller.text = provider.code!; }); } + // } //_joinMeeting(roomText.text, "demo meet2"); // _saveprefs( @@ -334,6 +362,7 @@ class _LoginScreenState extends State { final String secretkey = (prefs.getString('secretkey') ?? ''); final bool isloggedin = (prefs.getBool('isloggedin') ?? false); + final bool isloggedout = (prefs.getBool('isloggedout') ?? false); setState(() { _useremail = prefs.setString('useremail', email).then((bool success) { return useremail; @@ -348,8 +377,11 @@ class _LoginScreenState extends State { _login = prefs.setBool('isloggedin', login).then((bool success) { return isloggedin; }); - SessionManager().setLoggedIn(isloggedin); + _logout = prefs.setBool('isloggedout', false).then((bool success) { + return isloggedout; + }); }); + await SessionManager().setLoggedIn(isloggedin); // UserData userData = // UserData(email: email, name: token, domainUrl: domain, secretkey: key); // await provider.saveUserData(userData);