From 99f6f9a9c1c910478b29bde50578e5e1837f95a3 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Sat, 21 Apr 2018 14:40:41 +0300 Subject: [PATCH] Minor auth and activity improvements --- app/src/main/AndroidManifest.xml | 2 +- .../mthmmy/activities/LoginActivity.java | 6 ++++ .../thmmy/mthmmy/session/SessionManager.java | 34 +++++++++++++------ 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 118026f0..bf5256cd 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -61,7 +61,7 @@ android:windowSoftInputMode="adjustPan" /> 0) { //Wrong username Timber.i("Wrong Username"); return WRONG_USER; } error = document.select("body:contains(Password incorrect)"); - if (error.size() == 1) { //Wrong password + if (error.size() > 0) { //Wrong password Timber.i("Wrong Password"); return WRONG_PASSWORD; } + error = document.select("body:contains(you are banned from using this forum!),body:contains(έχετε αποκλειστεί από αυτή τη δημόσια συζήτηση!)"); + if (error.size() > 0) { //User is banned + Timber.i("User is banned"); + return BANNED_USER; + } + //Other error e.g. session was reset server-side clearSessionData(); //Clear invalid saved data return FAILURE; @@ -180,7 +187,7 @@ public class SessionManager { } else if (isLoginScreenDefault()) return; - sharedPrefs.edit().putBoolean(LOGIN_SCREEN_AS_DEFAULT, true).apply(); + setLoginScreenAsDefault(true); clearSessionData(); } @@ -190,7 +197,7 @@ public class SessionManager { public void guestLogin() { Timber.i("Continuing as a guest, as chosen by the user."); clearSessionData(); - sharedPrefs.edit().putBoolean(LOGIN_SCREEN_AS_DEFAULT, false).apply(); + setLoginScreenAsDefault(false); } @@ -219,7 +226,7 @@ public class SessionManager { return FAILURE; } } catch (IOException e) { - Timber.w("Logout IOException", e); + Timber.w(e, "Logout IOException"); return CONNECTION_ERROR; } catch (Exception e) { Timber.e(e, "Logout Exception"); @@ -253,16 +260,17 @@ public class SessionManager { return sharedPrefs.getBoolean(LOGIN_SCREEN_AS_DEFAULT, true); } - public String getCookieHeader() { - return cookiePersistor.loadAll().get(0).toString(); - } - //--------------------------------------GETTERS END--------------------------------------------- //------------------------------------OTHER FUNCTIONS------------------------------------------- private boolean validateRetrievedCookies() { List cookieList = cookieJar.loadForRequest(indexUrl); - return (cookieList.size() == 2) && (cookieList.get(0).name().equals("THMMYgrC00ki3")) && (cookieList.get(1).name().equals("PHPSESSID")); + for(Cookie cookie: cookieList) + { + if(cookie.name().equals("THMMYgrC00ki3")) + return true; + } + return false; } // Call validateRetrievedCookies() first @@ -288,6 +296,10 @@ public class SessionManager { Timber.i("Session data cleared."); } + private void setLoginScreenAsDefault(boolean b){ + sharedPrefs.edit().putBoolean(LOGIN_SCREEN_AS_DEFAULT, b).apply(); + } + @NonNull private String extractUserName(@NonNull Document doc) { //Scribbles2 Theme