logout fixes #1

Merged
snehalathad merged 1 commits from snehalatha_dev into dev 2024-10-09 08:57:48 +00:00
2 changed files with 42 additions and 6 deletions
Showing only changes of commit 8893cc4740 - Show all commits

View File

@ -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<void> 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);
}
}

View File

@ -38,6 +38,7 @@ class _LoginScreenState extends State<LoginScreen> {
late Future<String> _domain;
late Future<String> _key;
late Future<bool> _login;
late Future<bool> _logout;
String platform = "android";
var provider;
@override
@ -63,13 +64,16 @@ class _LoginScreenState extends State<LoginScreen> {
// _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<LoginScreen> {
if (textFieldsValidation(provider).isEmpty) {
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) {
provider.email = emailTextController.text;
String encoded =
@ -291,6 +318,7 @@ class _LoginScreenState extends State<LoginScreen> {
secretKeyTextConrtroller.text = provider.code!;
});
}
// }
//_joinMeeting(roomText.text, "demo meet2");
// _saveprefs(
@ -334,6 +362,7 @@ class _LoginScreenState extends State<LoginScreen> {
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<LoginScreen> {
_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);