Skip to content

Commit

Permalink
Fix sign in error handling issues
Browse files Browse the repository at this point in the history
  • Loading branch information
therealsujitk committed Oct 13, 2023
1 parent 83c75cd commit 63e9170
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public void onLoading(boolean isLoading) {
}
}

@Override
public void onForceSignOut() {
// User is already signed out so do nothing
}

@Override
public void onComplete() {
startMainActivity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ private void restartActivity() {
finish();
}

private void signOut() {
SettingsRepository.signOut(this);
this.startActivity(new Intent(this, LoginActivity.class));
this.finish();
}

private void getUnreadCount() {
AppDatabase appDatabase = AppDatabase.getInstance(this.getApplicationContext());
Bundle unreadCount = new Bundle();
Expand Down Expand Up @@ -340,6 +346,11 @@ public void onLoading(boolean isLoading) {
getSupportFragmentManager().setFragmentResult("syncDataState", syncDataState);
}

@Override
public void onForceSignOut() {
signOut();
}

@Override
public void onComplete() {
restartActivity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void onRequestCaptcha(int captchaType, Bitmap bitmap, WebView webView) {
.setView(captchaLayout)
.create();

Drawable background = captchaDialog.getWindow().getDecorView().getBackground();
Drawable background = Objects.requireNonNull(captchaDialog.getWindow()).getDecorView().getBackground();
if (background instanceof InsetDrawable) {
background = ((InsetDrawable) background).getDrawable();

Expand Down Expand Up @@ -248,6 +248,11 @@ public void onServiceEnd() {
initiator.onLoading(false);
}

@Override
public void onForceSignOut() {
initiator.onForceSignOut();
}

@Override
public void onComplete() {
initiator.onComplete();
Expand Down Expand Up @@ -311,6 +316,8 @@ public boolean isBound() {
public interface Initiator {
void onLoading(boolean isLoading);

void onForceSignOut();

void onComplete();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -512,24 +512,25 @@ public void signIn(final String captcha) {
" return;" +
" }" +
" var pageContent = res.toLowerCase();" +
" if (pageContent.includes('invalid captcha')) {" +
" var invalidCaptchaRegex = new RegExp(/invalid\\s*captcha/);" +
" var invalidCredentialsRegex = new RegExp(/invalid\\s*(user\\s*name|login\\s*id|user\\s*id)\\s*\\/\\s*password/);" +
" var accountLockedRegex = new RegExp(/account\\s*is\\s*locked/);" +
" var maxFailAttemptsRegex = new RegExp(/maximum\\s*fail\\s*attempts\\s*reached/);" +
" if (invalidCaptchaRegex.test(pageContent)) {" +
" response.error_message = 'Invalid Captcha';" +
" response.error_code = 1;" +
" } else if(pageContent.includes('invalid user id / password')) {" +
" response.error_message = 'Invalid User ID / Password';" +
" } else if(invalidCredentialsRegex.test(pageContent)) {" +
" response.error_message = 'Invalid Username / Password';" +
" response.error_code = 2;" +
" } else if(pageContent.includes('user id not available')) {" +
" response.error_message = 'Invalid User ID';" +
" response.error_code = 3;" +
" } else if(pageContent.includes('your account is locked')) {" +
" } else if(accountLockedRegex.test(pageContent)) {" +
" response.error_message = 'Your Account is Locked';" +
" response.error_code = 3;" +
" } else if(maxFailAttemptsRegex.test(pageContent)) {" +
" response.error_message = 'Maximum login attempts reached, open VTOP in your browser to reset your password';" +
" response.error_code = 4;" +
" } else if(pageContent.includes('maximum fail attempts reached')) {" +
" response.error_message = 'Maximum login attempts reached, open VTOP in your browser to reset password';" +
" response.error_code = 5;" +
" } else {" +
" response.error_message = 'Unknown error';" +
" response.error_code = 6;" +
" response.error_code = 5;" +
" }" +
" }" +
" }" +
Expand All @@ -550,6 +551,12 @@ public void signIn(final String captcha) {
if (errorCode == 1) {
this.reloadPage("/login", false);
} else {
if (errorCode == 2) {
try {
this.callback.onForceSignOut();
} catch (Exception ignored) {}
}

this.endService(true);
}
}
Expand Down Expand Up @@ -2505,6 +2512,8 @@ public interface Callback {

void onServiceEnd();

void onForceSignOut();

void onComplete();
}

Expand Down

0 comments on commit 63e9170

Please sign in to comment.