Skip to content

Precise error message password change #5544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
49 changes: 49 additions & 0 deletions app/src/main/java/fr/free/nrw/commons/CommonsApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import static org.acra.ReportField.USER_COMMENT;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.os.Build;
Expand All @@ -22,6 +24,7 @@
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.imagepipeline.core.ImagePipeline;
import com.facebook.imagepipeline.core.ImagePipelineConfig;
import fr.free.nrw.commons.auth.LoginActivity;
import fr.free.nrw.commons.auth.SessionManager;
import fr.free.nrw.commons.bookmarks.items.BookmarkItemsDao.Table;
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao;
Expand Down Expand Up @@ -339,4 +342,50 @@ public interface LogoutListener {

void onLogoutComplete();
}

public static class BaseLogoutListener implements CommonsApplication.LogoutListener {

final String loginMessageIntentKey = "loginMessage";
final String loginUsernameIntentKey = "loginUsername";
Activity activity;
Context ctx;
String loginMessage, userName;

public BaseLogoutListener(final Context ctx) {
this.ctx = ctx;
}

public BaseLogoutListener(final Activity activity, final Context ctx) {
this.activity = activity;
this.ctx = ctx;
}

public BaseLogoutListener(final Activity activity, final Context ctx, final String loginMessage, final String loginUsername) {
this.activity = activity;
this.ctx = ctx;
this.loginMessage = loginMessage;
this.userName = loginUsername;
}

@Override
public void onLogoutComplete() {
Timber.d("Logout complete callback received.");
final Intent loginIntent = new Intent(ctx, LoginActivity.class);
loginIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

if (loginMessage != null) {
loginIntent.putExtra(loginMessageIntentKey, loginMessage);
}
if (userName != null) {
loginIntent.putExtra(loginUsernameIntentKey, userName);
}

ctx.startActivity(loginIntent);

if (activity != null) {
activity.finish();
}
}
}
}
12 changes: 12 additions & 0 deletions app/src/main/java/fr/free/nrw/commons/auth/LoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import android.view.inputmethod.InputMethodManager;

import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.ColorRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -80,6 +81,8 @@ public class LoginActivity extends AccountAuthenticatorActivity {
final String saveErrorMessage ="errorMessage";
final String saveUsername="username";
final String savePassword="password";
final String loginUsername = "loginUsername";
final String loginMessage = "loginMessage";

@Override
public void onCreate(Bundle savedInstanceState) {
Expand All @@ -97,6 +100,9 @@ public void onCreate(Bundle savedInstanceState) {
binding = ActivityLoginBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());

String message = getIntent().getStringExtra(loginMessage);
String username = getIntent().getStringExtra(loginUsername);

binding.loginUsername.addTextChangedListener(textWatcher);
binding.loginPassword.addTextChangedListener(textWatcher);
binding.loginTwoFactor.addTextChangedListener(textWatcher);
Expand All @@ -115,6 +121,12 @@ public void onCreate(Bundle savedInstanceState) {
} else {
binding.loginCredentials.setVisibility(View.GONE);
}
if (message != null) {
showMessage(message, R.color.secondaryDarkColor);
}
if (username != null) {
binding.loginUsername.setText(username);
}
}
/**
* Hides the keyboard if the user's focus is not on the password (hasFocus is false).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class CsrfTokenClient(
private var retries = 0
private var csrfTokenCall: Call<MwQueryResponse?>? = null


@Throws(Throwable::class)
fun getTokenBlocking(): String {
var token = ""
Expand Down Expand Up @@ -56,7 +57,7 @@ class CsrfTokenClient(
}

if (token.isEmpty() || token == ANON_TOKEN) {
throw IOException("Invalid token, or login failure.")
throw IOException(INVALID_TOKEN_ERROR_MESSAGE)
}
return token
}
Expand Down Expand Up @@ -159,5 +160,6 @@ class CsrfTokenClient(
private const val ANON_TOKEN = "+\\"
private const val MAX_RETRIES = 1
private const val MAX_RETRIES_OF_LOGIN_BLOCKING = 2
const val INVALID_TOKEN_ERROR_MESSAGE = "Invalid token, or login failure."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import fr.free.nrw.commons.AboutActivity;
import fr.free.nrw.commons.BuildConfig;
import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.CommonsApplication.BaseLogoutListener;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.WelcomeActivity;
import fr.free.nrw.commons.actions.PageEditClient;
Expand Down Expand Up @@ -122,7 +123,7 @@ protected void onLogoutClicked() {
.setPositiveButton(R.string.yes, (dialog, which) -> {
final CommonsApplication app = (CommonsApplication)
requireContext().getApplicationContext();
app.clearApplicationData(requireContext(), new BaseLogoutListener());
app.clearApplicationData(requireContext(), new BaseLogoutListener(requireActivity(), getContext()));
})
.setNegativeButton(R.string.no, (dialog, which) -> dialog.cancel())
.show();
Expand Down Expand Up @@ -221,19 +222,5 @@ protected void onProfileClicked() {
protected void onPeerReviewClicked() {
ReviewActivity.startYourself(getActivity(), getString(R.string.title_activity_review));
}

private class BaseLogoutListener implements CommonsApplication.LogoutListener {

@Override
public void onLogoutComplete() {
Timber.d("Logout complete callback received.");
final Intent nearbyIntent = new Intent(
getContext(), LoginActivity.class);
nearbyIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
nearbyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(nearbyIntent);
requireActivity().finish();
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.CommonsApplication.BaseLogoutListener;
import fr.free.nrw.commons.MapController.NearbyPlacesInfo;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.Utils;
Expand Down Expand Up @@ -1408,7 +1409,7 @@ public void displayLoginSkippedWarning() {
.setMessage(R.string.login_alert_message)
.setPositiveButton(R.string.login, (dialog, which) -> {
// logout of the app
BaseLogoutListener logoutListener = new BaseLogoutListener();
BaseLogoutListener logoutListener = new BaseLogoutListener(getActivity(), getActivity());
CommonsApplication app = (CommonsApplication) getActivity().getApplication();
app.clearApplicationData(getContext(), logoutListener);
})
Expand Down Expand Up @@ -1455,18 +1456,18 @@ public boolean backButtonClicked() {
* onLogoutComplete is called after shared preferences and data stored in local database are
* cleared.
*/
private class BaseLogoutListener implements CommonsApplication.LogoutListener {

@Override
public void onLogoutComplete() {
Timber.d("Logout complete callback received.");
final Intent nearbyIntent = new Intent(getActivity(), LoginActivity.class);
nearbyIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
nearbyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(nearbyIntent);
getActivity().finish();
}
}
// private class BaseLogoutListener implements CommonsApplication.LogoutListener {
//
// @Override
// public void onLogoutComplete() {
// Timber.d("Logout complete callback received.");
// final Intent nearbyIntent = new Intent(getActivity(), LoginActivity.class);
// nearbyIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
// nearbyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// startActivity(nearbyIntent);
// getActivity().finish();
// }
// }

@Override
public void setFABPlusAction(final View.OnClickListener onClickListener) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package fr.free.nrw.commons.upload

data class StashUploadResult(
val state: StashUploadState,
val fileKey: String?
val fileKey: String?,
val errorMessage : String?
)

enum class StashUploadState {
Expand Down
17 changes: 10 additions & 7 deletions app/src/main/java/fr/free/nrw/commons/upload/UploadClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class UploadClient @Inject constructor(
): Observable<StashUploadResult> {
if (contribution.isCompleted()) {
return Observable.just(
StashUploadResult(StashUploadState.SUCCESS, contribution.fileKey)
StashUploadResult(StashUploadState.SUCCESS, contribution.fileKey,null)
)
}

Expand All @@ -76,12 +76,13 @@ class UploadClient @Inject constructor(

val index = AtomicInteger()
val failures = AtomicBoolean()
val errorMessage = AtomicReference<String>()
compositeDisposable.add(
Observable.fromIterable(fileChunks).forEach { chunkFile: File ->
if (canProcess(contribution, failures)) {
processChunk(
filename, contribution, notificationUpdater, chunkFile,
failures, chunkInfo, index, mediaType!!, file!!, fileChunks.size
failures, chunkInfo, index, errorMessage, mediaType!!, file!!, fileChunks.size
)
}
}
Expand All @@ -90,24 +91,25 @@ class UploadClient @Inject constructor(
return when {
contribution.isPaused() -> {
Timber.d("Upload stash paused %s", contribution.pageId)
Observable.just(StashUploadResult(StashUploadState.PAUSED, null))
Observable.just(StashUploadResult(StashUploadState.PAUSED, null, null))
}
failures.get() -> {
Timber.d("Upload stash contains failures %s", contribution.pageId)
Observable.just(StashUploadResult(StashUploadState.FAILED, null))
Observable.just(StashUploadResult(StashUploadState.FAILED, null, errorMessage.get()))
}
chunkInfo.get() != null -> {
Timber.d("Upload stash success %s", contribution.pageId)
Observable.just(
StashUploadResult(
StashUploadState.SUCCESS,
chunkInfo.get()!!.uploadResult!!.filekey
chunkInfo.get()!!.uploadResult!!.filekey,
"success"
)
)
}
else -> {
Timber.d("Upload stash failed %s", contribution.pageId)
Observable.just(StashUploadResult(StashUploadState.FAILED, null))
Observable.just(StashUploadResult(StashUploadState.FAILED, null,null))
}
}
}
Expand All @@ -116,7 +118,7 @@ class UploadClient @Inject constructor(
filename: String, contribution: Contribution,
notificationUpdater: NotificationUpdateProgressListener, chunkFile: File,
failures: AtomicBoolean, chunkInfo: AtomicReference<ChunkInfo?>, index: AtomicInteger,
mediaType: MediaType, file: File, totalChunks: Int
errorMessage : AtomicReference<String>, mediaType: MediaType, file: File, totalChunks: Int
) {
if (shouldSkip(chunkInfo, index)) {
index.incrementAndGet()
Expand Down Expand Up @@ -150,6 +152,7 @@ class UploadClient @Inject constructor(
notificationUpdater.onChunkUploaded(contribution, chunkInfo.get())
}, { throwable: Throwable? ->
Timber.e(throwable, "Received error in chunk upload")
errorMessage.set(throwable?.message)
failures.set(true)
}
)
Expand Down
Loading