Compare commits

...

2 Commits

Author SHA1 Message Date
snehalathad a1484c6d4f Merge pull request 'logout fixes' (#1) from snehalatha_dev into dev
Reviewed-on: #1
2024-10-09 08:57:48 +00:00
snehalathad@aissel.com 8893cc4740 logout fixes 2024-10-09 14:23:25 +05:30
2 changed files with 42 additions and 6 deletions

View File

@ -2,7 +2,7 @@ import 'package:shared_preferences/shared_preferences.dart';
class SessionManager { class SessionManager {
static final SessionManager _instance = SessionManager._(); static final SessionManager _instance = SessionManager._();
static const String _loggedInKey = 'loggedIn'; static const String _loggedInKey = 'isloggedin';
factory SessionManager() { factory SessionManager() {
return _instance; return _instance;
@ -27,6 +27,10 @@ class SessionManager {
Future<void> logoutSession(bool value) async { Future<void> logoutSession(bool value) async {
final prefs = await SharedPreferences.getInstance(); final prefs = await SharedPreferences.getInstance();
//secretkey
await prefs.setBool("isloggedin", value); await prefs.setBool("isloggedin", value);
await prefs.setBool("isloggedout", true);
await prefs.setBool(_loggedInKey, value);
} }
} }

View File

@ -38,6 +38,7 @@ class _LoginScreenState extends State<LoginScreen> {
late Future<String> _domain; late Future<String> _domain;
late Future<String> _key; late Future<String> _key;
late Future<bool> _login; late Future<bool> _login;
late Future<bool> _logout;
String platform = "android"; String platform = "android";
var provider; var provider;
@override @override
@ -63,13 +64,16 @@ class _LoginScreenState extends State<LoginScreen> {
// _domain = _prefs.then((SharedPreferences prefs) { // _domain = _prefs.then((SharedPreferences prefs) {
// return prefs.getString('domain') ?? ""; // return prefs.getString('domain') ?? "";
// }); // });
_key = _prefs.then((SharedPreferences prefs) { // _key = _prefs.then((SharedPreferences prefs) {
secretKeyTextConrtroller.text = prefs.getString('secretkey') ?? ""; // secretKeyTextConrtroller.text = prefs.getString('secretkey') ?? "";
return prefs.getString('secretkey') ?? ""; // return prefs.getString('secretkey') ?? "";
}); // });
_login = _prefs.then((SharedPreferences prefs) { _login = _prefs.then((SharedPreferences prefs) {
return prefs.getBool('isloggedin') ?? false; return prefs.getBool('isloggedin') ?? false;
}); });
_logout = _prefs.then((SharedPreferences prefs) {
return prefs.getBool('isloggedout') ?? false;
});
} }
init() async { init() async {
@ -240,6 +244,29 @@ class _LoginScreenState extends State<LoginScreen> {
if (textFieldsValidation(provider).isEmpty) { if (textFieldsValidation(provider).isEmpty) {
print("email:${emailTextController.text}"); print("email:${emailTextController.text}");
// if (await _logout) {
// print("LOGOUT");
// provider.code = secretKeyTextConrtroller.text;
// Map<String, dynamic> 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) { if (!provider.showCodeField) {
provider.email = emailTextController.text; provider.email = emailTextController.text;
String encoded = String encoded =
@ -291,6 +318,7 @@ class _LoginScreenState extends State<LoginScreen> {
secretKeyTextConrtroller.text = provider.code!; secretKeyTextConrtroller.text = provider.code!;
}); });
} }
// }
//_joinMeeting(roomText.text, "demo meet2"); //_joinMeeting(roomText.text, "demo meet2");
// _saveprefs( // _saveprefs(
@ -334,6 +362,7 @@ class _LoginScreenState extends State<LoginScreen> {
final String secretkey = (prefs.getString('secretkey') ?? ''); final String secretkey = (prefs.getString('secretkey') ?? '');
final bool isloggedin = (prefs.getBool('isloggedin') ?? false); final bool isloggedin = (prefs.getBool('isloggedin') ?? false);
final bool isloggedout = (prefs.getBool('isloggedout') ?? false);
setState(() { setState(() {
_useremail = prefs.setString('useremail', email).then((bool success) { _useremail = prefs.setString('useremail', email).then((bool success) {
return useremail; return useremail;
@ -348,8 +377,11 @@ class _LoginScreenState extends State<LoginScreen> {
_login = prefs.setBool('isloggedin', login).then((bool success) { _login = prefs.setBool('isloggedin', login).then((bool success) {
return isloggedin; return isloggedin;
}); });
SessionManager().setLoggedIn(isloggedin); _logout = prefs.setBool('isloggedout', false).then((bool success) {
return isloggedout;
});
}); });
await SessionManager().setLoggedIn(isloggedin);
// UserData userData = // UserData userData =
// UserData(email: email, name: token, domainUrl: domain, secretkey: key); // UserData(email: email, name: token, domainUrl: domain, secretkey: key);
// await provider.saveUserData(userData); // await provider.saveUserData(userData);