From 18fd1f60c12223d44ace1cb19cc2a0c15097f618 Mon Sep 17 00:00:00 2001 From: BanditAmit Date: Sun, 28 Jul 2024 22:38:24 +0530 Subject: [PATCH] added fixes --- .../com/BugBazaar/controller/UserAuthSave.java | 15 ++++++++++++++- app/src/main/java/com/BugBazaar/ui/Signin.java | 6 ++++-- .../BugBazaar/ui/TermsAndConditionsActivity.java | 3 ++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/BugBazaar/controller/UserAuthSave.java b/app/src/main/java/com/BugBazaar/controller/UserAuthSave.java index e511a39..10db807 100644 --- a/app/src/main/java/com/BugBazaar/controller/UserAuthSave.java +++ b/app/src/main/java/com/BugBazaar/controller/UserAuthSave.java @@ -12,6 +12,9 @@ public class UserAuthSave { private static final String KEY_USERNAME = "username"; private static final String KEY_PASSWORD = "password"; private static final String keypasscode = "passcode"; + private static final String USER_DATA = "userCred"; + private static SharedPreferences sharedPreferences1; + private static final String keypasscode_flag = "passcode_flag"; private static SharedPreferences sharedPreferences; @@ -19,7 +22,8 @@ public class UserAuthSave { public UserAuthSave(Context context) { sharedPreferences = context.getSharedPreferences(USER_PREFERENCES, Context.MODE_PRIVATE); - sessionManager = new SessionManager(context); // Initialize SessionManager in the constructor + sessionManager = new SessionManager(context); + sharedPreferences1 = context.getSharedPreferences(USER_DATA, Context.MODE_PRIVATE);// Initialize SessionManager in the constructor } public void saveUserData(String randomToken, boolean loggedIn) { @@ -64,4 +68,13 @@ public static String getSavedPassword() { public static boolean isLoggedIn() { return sharedPreferences.getBoolean(KEY_LOGGED_IN, false); } + + public void saveuserCred(String username, String password) { + SharedPreferences.Editor editor = sharedPreferences1.edit(); + editor.putString("username", username); + editor.putString("password", password); + editor.apply(); + + + } } diff --git a/app/src/main/java/com/BugBazaar/ui/Signin.java b/app/src/main/java/com/BugBazaar/ui/Signin.java index ae9c313..187b634 100644 --- a/app/src/main/java/com/BugBazaar/ui/Signin.java +++ b/app/src/main/java/com/BugBazaar/ui/Signin.java @@ -82,10 +82,12 @@ public void onClick(View v) { //This will fetch hex username and password from CredentialLoader and compare it with user provided values class. // It will return true if values are correct. Will return false if values are incorrect. boolean isLoggedin= loginController.validateLogin(username, password); - String randomToken = TokenGenerator.generateRandomToken(64); if (isLoggedin==true) { - + String randomToken = TokenGenerator.generateRandomToken(64); + sessionManager.setLoggedIn(true); + userAuthSave.saveUserData( randomToken,isLoggedin); + userAuthSave.saveuserCred(username,password); sessionManager.setLoggedIn(true); userAuthSave.saveUserData( randomToken,isLoggedin); // Successful login, do something (e.g., start a new activity) diff --git a/app/src/main/java/com/BugBazaar/ui/TermsAndConditionsActivity.java b/app/src/main/java/com/BugBazaar/ui/TermsAndConditionsActivity.java index b9a8e41..7f5d691 100644 --- a/app/src/main/java/com/BugBazaar/ui/TermsAndConditionsActivity.java +++ b/app/src/main/java/com/BugBazaar/ui/TermsAndConditionsActivity.java @@ -21,6 +21,7 @@ public class TermsAndConditionsActivity extends AppCompatActivity { WebView webView; + private SessionManager sessionManager; private String webViewUrl; @@ -77,7 +78,7 @@ else if (webViewUrl.endsWith(".bugbazaar.com")){ } private String getsessionid() { - return String.valueOf(UUID.randomUUID()); + return sessionManager.getUserToken(); } private class JavaScriptInterface {