Merge branch 'add-beta-student-security' of s416084/find-my-tutor-android into develop

This commit is contained in:
Mieszko Wrzeszczyński 2019-01-12 19:23:39 +00:00 committed by Gogs
commit f46d9cc60e
3 changed files with 46 additions and 9 deletions

View File

@ -126,17 +126,9 @@ public abstract class BaseActivity
if(PrefUtils.isBackgroundLocationServiceRunning(getApplicationContext())) {
stopBackgroundLocalizationTask();
}
logout();
storeBackgroundLocationStatus(getApplication(), false);
PrefUtils.storeIsLoggedIn(getApplicationContext(), false);
Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage(getBaseContext().getPackageName());
if (i != null) {
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}
startActivity(i);
finish();
} else if (itemName.equals(getResources().getString(R.string.navigation_item_feedback))) {
feedbackUtils.showNoteDialog("FEEDBACK");
@ -165,6 +157,20 @@ public abstract class BaseActivity
}
}
protected void logout(){
storeBackgroundLocationStatus(getApplication(), false);
PrefUtils.storeIsLoggedIn(getApplicationContext(), false);
Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage(getBaseContext().getPackageName());
if (i != null) {
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}
startActivity(i);
finish();
}
protected void checkPermissions() {
final List<String> missingPermissions = new ArrayList<String>();

View File

@ -127,6 +127,7 @@ public class MapActivity extends BaseActivity
mStatusChecker = () -> {
try {
if (shouldFetchNewCoords) {
checkIfUsesCanBeTutor();
fetchTopCoords();
}
} finally {
@ -404,6 +405,30 @@ Log.e("LOCALE",PrefUtils.getLocale(getApplicationContext()));
PrefUtils.putCurrentManualLocation(getApplicationContext(), resp.getPredefinedCoordinateId());
}
private void checkIfUsesCanBeTutor(){
disposable.add(
userService.getSelf(myId)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableSingleObserver<User>() {
@Override
public void onSuccess(User user) {
boolean tutorFromBackend = user.getTitle().equals("tutor");
if(tutorFromBackend != PrefUtils.getIsTutor(getApplicationContext())){
logout();
}
}
@Override
public void onError(Throwable e) {
showError(e);
}
}));
}
private void fetchTopCoords() {
disposable.add(

View File

@ -39,6 +39,9 @@ public interface UserService {
@GET("api/users/tutors/active")
Single <List<User>> getAllActiveTutors();
@GET("api/users/tutors/offline")
Single <List<User>> getAllOfflineTutors();
@ -60,6 +63,9 @@ public interface UserService {
@GET("api/users/{id}")
Single <User> getUserById(@Path("id") String userID);
@GET("api/users/self/{id}")
Single <User> getSelf(@Path("id") String userID);
@PUT("api/users/{id}")
Completable updateUserByID(@Path("id") String userID, @Body User user);