1
0
mirror of https://framagit.org/tom79/fedilab-tube synced 2025-02-16 12:00:42 +01:00

Fix sensitive email with double queries if necessary

This commit is contained in:
Thomas 2020-09-06 20:42:18 +02:00
parent f7eb17fd94
commit 43e6d0baeb

View File

@ -232,37 +232,28 @@ public class LoginActivity extends AppCompatActivity {
String oauthUrl = "/api/v1/users/token";
try {
String responseLogin = new HttpsConnection(LoginActivity.this).post("https://" + finalInstance + oauthUrl, 30, parameters, null);
runOnUiThread(() -> {
JSONObject resobjLogin;
try {
resobjLogin = new JSONObject(responseLogin);
String token = resobjLogin.getString("access_token");
String refresh_token = resobjLogin.getString("refresh_token");
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, token);
editor.putString(Helper.PREF_INSTANCE, host);
editor.apply();
//Update the account with the token;
new UpdateAccountInfoAsyncTask(LoginActivity.this, token, client_id, client_secret, refresh_token, host).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} catch (JSONException e) {
e.printStackTrace();
runOnUiThread(() -> connectionButton.setEnabled(true));
}
});
proceedLogin(responseLogin, host);
} catch (final Exception e) {
e.printStackTrace();
runOnUiThread(() -> {
connectionButton.setEnabled(true);
String message;
if (e.getLocalizedMessage() != null && e.getLocalizedMessage().trim().length() > 0)
message = e.getLocalizedMessage();
else if (e.getMessage() != null && e.getMessage().trim().length() > 0)
message = e.getMessage();
else
message = getString(R.string.client_error);
Toasty.error(LoginActivity.this, message, Toast.LENGTH_LONG).show();
});
parameters.remove("username");
parameters.put("username", login_uid.getText().toString().trim().toLowerCase());
try {
String responseLogin = new HttpsConnection(LoginActivity.this).post("https://" + finalInstance + oauthUrl, 30, parameters, null);
proceedLogin(responseLogin, host);
}catch (final Exception e2) {
e2.printStackTrace();
runOnUiThread(() -> {
connectionButton.setEnabled(true);
String message;
if (e2.getLocalizedMessage() != null && e2.getLocalizedMessage().trim().length() > 0)
message = e2.getLocalizedMessage();
else if (e2.getMessage() != null && e2.getMessage().trim().length() > 0)
message = e2.getMessage();
else
message = getString(R.string.client_error);
Toasty.error(LoginActivity.this, message, Toast.LENGTH_LONG).show();
});
}
}
} catch (JSONException e) {
e.printStackTrace();
e.printStackTrace();
@ -288,6 +279,27 @@ public class LoginActivity extends AppCompatActivity {
});
}
private void proceedLogin(String responseLogin, String host){
runOnUiThread(() -> {
JSONObject resobjLogin;
try {
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
resobjLogin = new JSONObject(responseLogin);
String token = resobjLogin.getString("access_token");
String refresh_token = resobjLogin.getString("refresh_token");
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, token);
editor.putString(Helper.PREF_INSTANCE, host);
editor.apply();
//Update the account with the token;
new UpdateAccountInfoAsyncTask(LoginActivity.this, token, client_id, client_secret, refresh_token, host).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} catch (JSONException e) {
e.printStackTrace();
runOnUiThread(() -> connectionButton.setEnabled(true));
}
});
}
@Override
protected void onResume() {
super.onResume();