1
0
mirror of https://framagit.org/tom79/fedilab-tube synced 2025-02-19 13:30:39 +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"; String oauthUrl = "/api/v1/users/token";
try { try {
String responseLogin = new HttpsConnection(LoginActivity.this).post("https://" + finalInstance + oauthUrl, 30, parameters, null); String responseLogin = new HttpsConnection(LoginActivity.this).post("https://" + finalInstance + oauthUrl, 30, parameters, null);
runOnUiThread(() -> { proceedLogin(responseLogin, host);
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));
}
});
} catch (final Exception e) { } catch (final Exception e) {
e.printStackTrace(); parameters.remove("username");
runOnUiThread(() -> { parameters.put("username", login_uid.getText().toString().trim().toLowerCase());
connectionButton.setEnabled(true); try {
String message; String responseLogin = new HttpsConnection(LoginActivity.this).post("https://" + finalInstance + oauthUrl, 30, parameters, null);
if (e.getLocalizedMessage() != null && e.getLocalizedMessage().trim().length() > 0) proceedLogin(responseLogin, host);
message = e.getLocalizedMessage(); }catch (final Exception e2) {
else if (e.getMessage() != null && e.getMessage().trim().length() > 0) e2.printStackTrace();
message = e.getMessage(); runOnUiThread(() -> {
else connectionButton.setEnabled(true);
message = getString(R.string.client_error); String message;
Toasty.error(LoginActivity.this, message, Toast.LENGTH_LONG).show(); 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) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
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 @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();