mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Merge pull request #560 from commons-app/prehack2faError
Detect when 2FA is needed and error nicely
This commit is contained in:
commit
a99ae9e8bb
3 changed files with 11 additions and 2 deletions
|
|
@ -18,7 +18,8 @@ public class MWApi extends org.mediawiki.api.MWApi {
|
||||||
* @param username String
|
* @param username String
|
||||||
* @param password String
|
* @param password String
|
||||||
* @return String On success: "PASS"
|
* @return String On success: "PASS"
|
||||||
* failure: A failure message code (deifned by mediawiki)
|
* continue: "2FA" (More information required for 2FA)
|
||||||
|
* failure: A failure message code (defined by mediawiki)
|
||||||
* misc: genericerror-UI, genericerror-REDIRECT, genericerror-RESTART
|
* misc: genericerror-UI, genericerror-REDIRECT, genericerror-RESTART
|
||||||
* @throws IOException On api request IO issue
|
* @throws IOException On api request IO issue
|
||||||
*/
|
*/
|
||||||
|
|
@ -45,9 +46,14 @@ public class MWApi extends org.mediawiki.api.MWApi {
|
||||||
if (status.equals("PASS")) {
|
if (status.equals("PASS")) {
|
||||||
this.isLoggedIn = true;
|
this.isLoggedIn = true;
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
} else if (status.equals("FAIL")) {
|
} else if (status.equals("FAIL")) {
|
||||||
return loginData.getString("/api/clientlogin/@messagecode");
|
return loginData.getString("/api/clientlogin/@messagecode");
|
||||||
|
} else if (
|
||||||
|
status.equals("UI")
|
||||||
|
&& loginData.getString("/api/clientlogin/requests/_v/@id").equals("TOTPAuthenticationRequest")
|
||||||
|
&& loginData.getString("/api/clientlogin/requests/_v/@provider").equals("Two-factor authentication (OATH).")
|
||||||
|
) {
|
||||||
|
return "2FA";
|
||||||
}
|
}
|
||||||
|
|
||||||
// UI, REDIRECT, RESTART
|
// UI, REDIRECT, RESTART
|
||||||
|
|
|
||||||
|
|
@ -119,6 +119,8 @@ public class LoginActivity extends AccountAuthenticatorActivity {
|
||||||
} else if (result.toLowerCase().contains("userblocked".toLowerCase())) {
|
} else if (result.toLowerCase().contains("userblocked".toLowerCase())) {
|
||||||
// Matches login-userblocked
|
// Matches login-userblocked
|
||||||
response = R.string.login_failed_blocked;
|
response = R.string.login_failed_blocked;
|
||||||
|
} else if (result.equals("2FA")){
|
||||||
|
response = R.string.login_failed_2fa_not_supported;
|
||||||
} else {
|
} else {
|
||||||
// Occurs with unhandled login failure codes
|
// Occurs with unhandled login failure codes
|
||||||
Timber.d("Login failed with reason: %s", result);
|
Timber.d("Login failed with reason: %s", result);
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@
|
||||||
<string name="login_failed_password">Unable to login - please check your password</string>
|
<string name="login_failed_password">Unable to login - please check your password</string>
|
||||||
<string name="login_failed_throttled">Too many unsuccessful attempts. Please try again in a few minutes.</string>
|
<string name="login_failed_throttled">Too many unsuccessful attempts. Please try again in a few minutes.</string>
|
||||||
<string name="login_failed_blocked">Sorry, this user has been blocked on Commons</string>
|
<string name="login_failed_blocked">Sorry, this user has been blocked on Commons</string>
|
||||||
|
<string name="login_failed_2fa_not_supported">The app doesn\'t currently support 2 Factor Authentication.</string>
|
||||||
<string name="login_failed_generic">Login failed</string>
|
<string name="login_failed_generic">Login failed</string>
|
||||||
<string name="share_upload_button">Upload</string>
|
<string name="share_upload_button">Upload</string>
|
||||||
<string name="multiple_share_base_title">Name this set</string>
|
<string name="multiple_share_base_title">Name this set</string>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue