Precise error message password change (#5544)

* Precise Error Message and Action When Password is Changed

* Make message persistent

* code cleanup and fixes

* removed unnecessary string resource

* removed unnecessary string resource

* fix

* fix

* Upload Client to kotlin

* Remove Redundant Code

* Remove Redundant Code

* code cleanup and Improvements

* Improved Java doc

* Improved Java doc

* Improved Javadoc
This commit is contained in:
Shashank Kumar 2024-03-21 23:21:53 +05:30 committed by GitHub
parent 152e824aa6
commit 2a6ab66c11
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 171 additions and 54 deletions

View file

@ -24,7 +24,6 @@ import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.core.app.NavUtils;
import androidx.core.content.ContextCompat;
import fr.free.nrw.commons.auth.login.LoginClient;
import fr.free.nrw.commons.auth.login.LoginResult;
import fr.free.nrw.commons.databinding.ActivityLoginBinding;
@ -51,6 +50,8 @@ import timber.log.Timber;
import static android.view.KeyEvent.KEYCODE_ENTER;
import static android.view.View.VISIBLE;
import static android.view.inputmethod.EditorInfo.IME_ACTION_DONE;
import static fr.free.nrw.commons.CommonsApplication.loginMessageIntentKey;
import static fr.free.nrw.commons.CommonsApplication.loginUsernameIntentKey;
public class LoginActivity extends AccountAuthenticatorActivity {
@ -93,6 +94,9 @@ public class LoginActivity extends AccountAuthenticatorActivity {
binding = ActivityLoginBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
String message = getIntent().getStringExtra(loginMessageIntentKey);
String username = getIntent().getStringExtra(loginUsernameIntentKey);
binding.loginUsername.addTextChangedListener(textWatcher);
binding.loginPassword.addTextChangedListener(textWatcher);
binding.loginTwoFactor.addTextChangedListener(textWatcher);
@ -111,6 +115,12 @@ public class LoginActivity extends AccountAuthenticatorActivity {
} else {
binding.loginCredentials.setVisibility(View.GONE);
}
if (message != null) {
showMessage(message, R.color.secondaryDarkColor);
}
if (username != null) {
binding.loginUsername.setText(username);
}
}
/**
* Hides the keyboard if the user's focus is not on the password (hasFocus is false).

View file

@ -23,6 +23,7 @@ class CsrfTokenClient(
private var retries = 0
private var csrfTokenCall: Call<MwQueryResponse?>? = null
@Throws(Throwable::class)
fun getTokenBlocking(): String {
var token = ""
@ -56,7 +57,7 @@ class CsrfTokenClient(
}
if (token.isEmpty() || token == ANON_TOKEN) {
throw IOException("Invalid token, or login failure.")
throw IOException(INVALID_TOKEN_ERROR_MESSAGE)
}
return token
}
@ -159,5 +160,6 @@ class CsrfTokenClient(
private const val ANON_TOKEN = "+\\"
private const val MAX_RETRIES = 1
private const val MAX_RETRIES_OF_LOGIN_BLOCKING = 2
const val INVALID_TOKEN_ERROR_MESSAGE = "Invalid token, or login failure."
}
}