fixed login error handling

This commit is contained in:
nuclearfog 2022-01-23 21:06:26 +01:00
parent f69946cb00
commit ef17636bb1
No known key found for this signature in database
GPG Key ID: AA0271FBE406DB98
3 changed files with 20 additions and 14 deletions

View File

@ -187,7 +187,7 @@ public class LoginActivity extends AppCompatActivity implements OnClickListener
*
* @param error Twitter exception
*/
public void onError(TwitterError error) {
public void onError(@Nullable TwitterError error) {
ErrorHandler.handleFailure(this, error);
}

View File

@ -50,38 +50,43 @@ public class Registration extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... param) {
try {
// check if we need to backup current session
if (settings.isLoggedIn() && !accountDB.exists(settings.getCurrentUserId())) {
accountDB.setLogin(settings.getCurrentUserId(), settings.getAccessToken(), settings.getTokenSecret());
}
// no PIN means we need to request a token to login
if (param.length == 0) {
// backup current login if exist
if (settings.isLoggedIn() && !accountDB.exists(settings.getCurrentUserId())) {
accountDB.setLogin(settings.getCurrentUserId(), settings.getAccessToken(), settings.getTokenSecret());
}
return twitter.getRequestToken();
}
// login with pin
// login with pin and access token
User user = twitter.login(param[0], param[1]);
// save new user information
database.storeUser(user);
accountDB.setLogin(user.getId(), settings.getAccessToken(), settings.getTokenSecret());
return "";
} catch (TwitterException exception) {
this.exception = exception;
return null;
}
return null;
}
@Override
protected void onPostExecute(String redirectionURL) {
protected void onPostExecute(String result) {
LoginActivity activity = callback.get();
if (activity != null) {
if (redirectionURL != null) {
if (!redirectionURL.isEmpty()) {
activity.connect(redirectionURL);
} else if (exception != null) {
activity.onError(exception);
} else {
// redirect to Twitter login page
if (result != null) {
if (result.isEmpty()) {
activity.onSuccess();
} else {
activity.connect(result);
}
}
// notify when an error occured
else {
activity.onError(exception);
}
}
}
}

View File

@ -184,6 +184,7 @@ public class Twitter implements GlobalSettings.SettingsListener {
Response response = post(REQUEST_TOKEN, new ArrayList<>(1));
if (response.code() == 200 && response.body() != null) {
String res = response.body().string();
// extrect oauth_token from url
Uri uri = Uri.parse(AUTHENTICATE + "?" + res);
return uri.getQueryParameter("oauth_token");
}