Add logout security

This commit is contained in:
Mieszko Wrzeszczyński 2019-01-12 20:22:30 +01:00
parent 085dc1e4d6
commit 0ec0e95798
5 changed files with 51 additions and 14 deletions

View File

@ -126,17 +126,9 @@ public abstract class BaseActivity
if(PrefUtils.isBackgroundLocationServiceRunning(getApplicationContext())) { if(PrefUtils.isBackgroundLocationServiceRunning(getApplicationContext())) {
stopBackgroundLocalizationTask(); 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))) { } else if (itemName.equals(getResources().getString(R.string.navigation_item_feedback))) {
feedbackUtils.showNoteDialog("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() { protected void checkPermissions() {
final List<String> missingPermissions = new ArrayList<String>(); final List<String> missingPermissions = new ArrayList<String>();

View File

@ -148,10 +148,10 @@ public class LoginActivity extends AppCompatActivity {
} }
private void loginProcess(String email, String password) { private void loginProcess(String email, String password) {
ValidateUser user = new ValidateUser(email, password); //ValidateUser user = new ValidateUser(email, password);
// LdapUser fakeUser = new LdapUser(email, password,"wmi","tutor",email,"Fałszywy",email); LdapUser fakeUser = new LdapUser(email, password,"wmi","tutor",email,"Fałszywy",email);
disposable.add(ldapService.validate(user) //disposable.add(ldapService.validate(user)
//disposable.add(ldapService.fakeValidate(fakeUser) disposable.add(ldapService.fakeValidate(fakeUser)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(this::handleResponse, this::handleError)); .subscribe(this::handleResponse, this::handleError));

View File

@ -127,6 +127,7 @@ public class MapActivity extends BaseActivity
mStatusChecker = () -> { mStatusChecker = () -> {
try { try {
if (shouldFetchNewCoords) { if (shouldFetchNewCoords) {
checkIfUsesCanBeTutor();
fetchTopCoords(); fetchTopCoords();
} }
} finally { } finally {
@ -404,6 +405,30 @@ Log.e("LOCALE",PrefUtils.getLocale(getApplicationContext()));
PrefUtils.putCurrentManualLocation(getApplicationContext(), resp.getPredefinedCoordinateId()); 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() { private void fetchTopCoords() {
disposable.add( disposable.add(

View File

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

View File

@ -6,7 +6,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
public class Const { public class Const {
public final static String BASE_URL = "https://s416084.projektstudencki.pl/master/"; public final static String BASE_URL = "https://s416084.projektstudencki.pl/develop/";
public final static Integer mapRefreshInterval = 6000; public final static Integer mapRefreshInterval = 6000;
public final static Integer onlineBackgroundLocationInterval = 7000; public final static Integer onlineBackgroundLocationInterval = 7000;
public final static Integer offlineBackgroundLocationInterval = 360000; public final static Integer offlineBackgroundLocationInterval = 360000;