fixed login error handling
This commit is contained in:
parent
f69946cb00
commit
ef17636bb1
|
@ -187,7 +187,7 @@ public class LoginActivity extends AppCompatActivity implements OnClickListener
|
||||||
*
|
*
|
||||||
* @param error Twitter exception
|
* @param error Twitter exception
|
||||||
*/
|
*/
|
||||||
public void onError(TwitterError error) {
|
public void onError(@Nullable TwitterError error) {
|
||||||
ErrorHandler.handleFailure(this, error);
|
ErrorHandler.handleFailure(this, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,38 +50,43 @@ public class Registration extends AsyncTask<String, Void, String> {
|
||||||
@Override
|
@Override
|
||||||
protected String doInBackground(String... param) {
|
protected String doInBackground(String... param) {
|
||||||
try {
|
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
|
// no PIN means we need to request a token to login
|
||||||
if (param.length == 0) {
|
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();
|
return twitter.getRequestToken();
|
||||||
}
|
}
|
||||||
// login with pin
|
// login with pin and access token
|
||||||
User user = twitter.login(param[0], param[1]);
|
User user = twitter.login(param[0], param[1]);
|
||||||
|
// save new user information
|
||||||
database.storeUser(user);
|
database.storeUser(user);
|
||||||
|
accountDB.setLogin(user.getId(), settings.getAccessToken(), settings.getTokenSecret());
|
||||||
return "";
|
return "";
|
||||||
} catch (TwitterException exception) {
|
} catch (TwitterException exception) {
|
||||||
this.exception = exception;
|
this.exception = exception;
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(String redirectionURL) {
|
protected void onPostExecute(String result) {
|
||||||
LoginActivity activity = callback.get();
|
LoginActivity activity = callback.get();
|
||||||
if (activity != null) {
|
if (activity != null) {
|
||||||
if (redirectionURL != null) {
|
// redirect to Twitter login page
|
||||||
if (!redirectionURL.isEmpty()) {
|
if (result != null) {
|
||||||
activity.connect(redirectionURL);
|
if (result.isEmpty()) {
|
||||||
} else if (exception != null) {
|
|
||||||
activity.onError(exception);
|
|
||||||
} else {
|
|
||||||
activity.onSuccess();
|
activity.onSuccess();
|
||||||
|
} else {
|
||||||
|
activity.connect(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// notify when an error occured
|
||||||
|
else {
|
||||||
|
activity.onError(exception);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -184,6 +184,7 @@ public class Twitter implements GlobalSettings.SettingsListener {
|
||||||
Response response = post(REQUEST_TOKEN, new ArrayList<>(1));
|
Response response = post(REQUEST_TOKEN, new ArrayList<>(1));
|
||||||
if (response.code() == 200 && response.body() != null) {
|
if (response.code() == 200 && response.body() != null) {
|
||||||
String res = response.body().string();
|
String res = response.body().string();
|
||||||
|
// extrect oauth_token from url
|
||||||
Uri uri = Uri.parse(AUTHENTICATE + "?" + res);
|
Uri uri = Uri.parse(AUTHENTICATE + "?" + res);
|
||||||
return uri.getQueryParameter("oauth_token");
|
return uri.getQueryParameter("oauth_token");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue