Use clientlogin API module

This is the first step to allowing 2 factor authentication #328.
This uses the new API module clientlogin instead of the login module.

We still report the same set of errors in a 'nice' way with real
error messages, how ever there are lots more that can probably be
handled, for example #507.
This commit is contained in:
addshore 2017-05-12 13:04:22 +02:00
parent 2e7aaddafb
commit d38dde0ec4
12 changed files with 80 additions and 23 deletions

View file

@ -66,7 +66,7 @@ public class LoginActivity extends AccountAuthenticatorActivity {
.param("result", result)
.log();
if (result.equals("Success")) {
if (result.equals("PASS")) {
if (dialog != null && dialog.isShowing()) {
dialog.dismiss();
}
@ -100,20 +100,27 @@ public class LoginActivity extends AccountAuthenticatorActivity {
} else {
int response;
// Match known failure message codes and provide messages
if(result.equals("NetworkFailure")) {
// Matches NetworkFailure which is created by the doInBackground method
response = R.string.login_failed_network;
} else if(result.equals("NotExists") || result.equals("Illegal") || result.equals("NotExists")) {
} else if (result.toLowerCase().contains("nosuchuser".toLowerCase()) || result.toLowerCase().contains("noname".toLowerCase())) {
// Matches nosuchuser, nosuchusershort, noname
response = R.string.login_failed_username;
passwordEdit.setText("");
} else if(result.equals("EmptyPass") || result.equals("WrongPass") || result.equals("WrongPluginPass")) {
} else if (result.toLowerCase().contains("wrongpassword".toLowerCase())) {
// Matches wrongpassword, wrongpasswordempty
response = R.string.login_failed_password;
passwordEdit.setText("");
} else if(result.equals("Throttled")) {
} else if (result.toLowerCase().contains("throttle".toLowerCase())) {
// Matches unknown throttle error codes
response = R.string.login_failed_throttled;
} else if(result.equals("Blocked")) {
} else if (result.toLowerCase().contains("userblocked".toLowerCase())) {
// Matches login-userblocked
response = R.string.login_failed_blocked;
} else {
// Should never really happen
// Occurs with unhandled login failure codes
Timber.d("Login failed with reason: %s", result);
response = R.string.login_failed_generic;
}

View file

@ -9,11 +9,10 @@ import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import org.mediawiki.api.MWApi;
import java.io.IOException;
import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.MWApi;
public class WikiAccountAuthenticator extends AbstractAccountAuthenticator {
@ -46,7 +45,7 @@ public class WikiAccountAuthenticator extends AbstractAccountAuthenticator {
private String getAuthCookie(String username, String password) throws IOException {
MWApi api = CommonsApplication.createMWApi();
String result = api.login(username, password);
if(result.equals("Success")) {
if(result.equals("PASS")) {
return api.getAuthCookie();
} else {
return null;