Detect when 2FA is needed and error nicely

Fixes #507
This commit is contained in:
addshore 2017-05-13 11:57:16 +02:00
parent 516a5839a3
commit e8bbbe78d8
3 changed files with 11 additions and 2 deletions

View file

@ -18,7 +18,8 @@ public class MWApi extends org.mediawiki.api.MWApi {
* @param username String
* @param password String
* @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
* @throws IOException On api request IO issue
*/
@ -45,9 +46,14 @@ public class MWApi extends org.mediawiki.api.MWApi {
if (status.equals("PASS")) {
this.isLoggedIn = true;
return status;
} else if (status.equals("FAIL")) {
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

View file

@ -119,6 +119,8 @@ public class LoginActivity extends AccountAuthenticatorActivity {
} else if (result.toLowerCase().contains("userblocked".toLowerCase())) {
// Matches login-userblocked
response = R.string.login_failed_blocked;
} else if (result.equals("2FA")){
response = R.string.login_failed_2fa_not_supported;
} else {
// Occurs with unhandled login failure codes
Timber.d("Login failed with reason: %s", result);

View file

@ -42,6 +42,7 @@
<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_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="share_upload_button">Upload</string>
<string name="multiple_share_base_title">Name this set</string>