Skip to content

Commit 306f23d

Browse files
Vivek Maskaramisaochan
authored andcommitted
Force login when no active session is found while uploading an image (commons-app#1684)
* Force login when no active session is found while uploading an image * Updated not logged in message
1 parent 8859ff9 commit 306f23d

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

app/src/main/java/fr/free/nrw/commons/auth/SessionManager.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import android.content.Context;
66
import android.content.SharedPreferences;
77

8+
import javax.annotation.Nullable;
9+
810
import fr.free.nrw.commons.mwapi.MediaWikiApi;
911
import io.reactivex.Completable;
1012
import io.reactivex.Observable;
@@ -31,6 +33,7 @@ public SessionManager(Context context, MediaWikiApi mediaWikiApi, SharedPreferen
3133
/**
3234
* @return Account|null
3335
*/
36+
@Nullable
3437
public Account getCurrentAccount() {
3538
if (currentAccount == null) {
3639
AccountManager accountManager = AccountManager.get(context);

app/src/main/java/fr/free/nrw/commons/upload/UploadController.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package fr.free.nrw.commons.upload;
22

3+
import android.accounts.Account;
34
import android.content.ComponentName;
45
import android.content.ContentResolver;
56
import android.content.Context;
@@ -13,6 +14,7 @@
1314
import android.os.IBinder;
1415
import android.provider.MediaStore;
1516
import android.text.TextUtils;
17+
import android.widget.Toast;
1618

1719
import java.io.BufferedInputStream;
1820
import java.io.IOException;
@@ -22,9 +24,11 @@
2224

2325
import fr.free.nrw.commons.CommonsApplication;
2426
import fr.free.nrw.commons.HandlerService;
27+
import fr.free.nrw.commons.R;
2528
import fr.free.nrw.commons.auth.SessionManager;
2629
import fr.free.nrw.commons.contributions.Contribution;
2730
import fr.free.nrw.commons.settings.Prefs;
31+
import fr.free.nrw.commons.utils.ViewUtil;
2832
import timber.log.Timber;
2933

3034
public class UploadController {
@@ -95,8 +99,15 @@ public void startUpload(String title, Uri mediaUri, String description, String m
9599
Contribution contribution;
96100

97101
//TODO: Modify this to include coords
102+
Account currentAccount = sessionManager.getCurrentAccount();
103+
if(currentAccount == null) {
104+
Timber.d("Current account is null");
105+
ViewUtil.showLongToast(context, context.getString(R.string.user_not_logged_in));
106+
sessionManager.forceLogin(context);
107+
return;
108+
}
98109
contribution = new Contribution(mediaUri, null, title, description, -1,
99-
null, null, sessionManager.getCurrentAccount().name,
110+
null, null, currentAccount.name,
100111
CommonsApplication.DEFAULT_EDIT_SUMMARY, decimalCoords);
101112

102113
contribution.setTag("mimeType", mimeType);

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,6 @@
287287
<string name="wikidata_edit_failure">Failed to update corresponding Wikidata entity!</string>
288288
<string name="menu_set_wallpaper">Set wallpaper</string>
289289
<string name="wallpaper_set_successfully">Wallpaper set successfully!</string>
290+
291+
<string name="user_not_logged_in">Login session expired, please log in again.</string>
290292
</resources>

0 commit comments

Comments
 (0)