mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2025-01-31 19:42:44 +01:00
Clean data user on bad user credentials (#138)
This commit is contained in:
parent
7b7be1eef1
commit
072c504d2b
@ -47,4 +47,10 @@ public class Repository implements RepositoryContract {
|
|||||||
public SyncContract getSyncRepo() {
|
public SyncContract getSyncRepo() {
|
||||||
return synchronization;
|
return synchronization;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cleanAllData() {
|
||||||
|
sharedPref.cleanSharedPref();
|
||||||
|
database.recreateDatabase();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,4 +17,6 @@ public interface RepositoryContract {
|
|||||||
DbContract getDbRepo();
|
DbContract getDbRepo();
|
||||||
|
|
||||||
SyncContract getSyncRepo();
|
SyncContract getSyncRepo();
|
||||||
|
|
||||||
|
void cleanAllData();
|
||||||
}
|
}
|
||||||
|
@ -30,4 +30,6 @@ public interface DbContract {
|
|||||||
long getCurrentSemesterId();
|
long getCurrentSemesterId();
|
||||||
|
|
||||||
int getCurrentSemesterName();
|
int getCurrentSemesterName();
|
||||||
|
|
||||||
|
void recreateDatabase();
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
package io.github.wulkanowy.data.db.dao;
|
package io.github.wulkanowy.data.db.dao;
|
||||||
|
|
||||||
|
import org.greenrobot.greendao.database.Database;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import io.github.wulkanowy.data.db.dao.entities.DaoMaster;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.DaoSession;
|
import io.github.wulkanowy.data.db.dao.entities.DaoSession;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.DiaryDao;
|
import io.github.wulkanowy.data.db.dao.entities.DiaryDao;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.Grade;
|
import io.github.wulkanowy.data.db.dao.entities.Grade;
|
||||||
@ -109,4 +112,12 @@ public class DbRepository implements DbContract {
|
|||||||
SemesterDao.Properties.Current.eq(true)
|
SemesterDao.Properties.Current.eq(true)
|
||||||
).unique();
|
).unique();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void recreateDatabase() {
|
||||||
|
Database database = daoSession.getDatabase();
|
||||||
|
|
||||||
|
DaoMaster.dropAllTables(database, true);
|
||||||
|
DaoMaster.createAllTables(database, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,4 +28,6 @@ public interface SharedPrefContract {
|
|||||||
boolean isServicesEnable();
|
boolean isServicesEnable();
|
||||||
|
|
||||||
boolean isNotifyEnable();
|
boolean isNotifyEnable();
|
||||||
|
|
||||||
|
void cleanSharedPref();
|
||||||
}
|
}
|
||||||
|
@ -88,4 +88,10 @@ public class SharedPrefRepository implements SharedPrefContract {
|
|||||||
public boolean isMobileDisable() {
|
public boolean isMobileDisable() {
|
||||||
return settingsSharedPref.getBoolean(SettingsFragment.SHARED_KEY_SERVICES_MOBILE_DISABLED, false);
|
return settingsSharedPref.getBoolean(SettingsFragment.SHARED_KEY_SERVICES_MOBILE_DISABLED, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cleanSharedPref() {
|
||||||
|
appSharedPref.edit().clear().apply();
|
||||||
|
settingsSharedPref.edit().clear().apply();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ import javax.inject.Inject;
|
|||||||
|
|
||||||
import dagger.android.AndroidInjection;
|
import dagger.android.AndroidInjection;
|
||||||
import io.github.wulkanowy.R;
|
import io.github.wulkanowy.R;
|
||||||
|
import io.github.wulkanowy.api.login.BadCredentialsException;
|
||||||
import io.github.wulkanowy.data.RepositoryContract;
|
import io.github.wulkanowy.data.RepositoryContract;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.Grade;
|
import io.github.wulkanowy.data.db.dao.entities.Grade;
|
||||||
import io.github.wulkanowy.data.sync.NotRegisteredUserException;
|
import io.github.wulkanowy.data.sync.NotRegisteredUserException;
|
||||||
@ -82,6 +83,12 @@ public class SyncJob extends SimpleJobService {
|
|||||||
logError(e);
|
logError(e);
|
||||||
stop(getApplicationContext());
|
stop(getApplicationContext());
|
||||||
|
|
||||||
|
return JobService.RESULT_FAIL_NORETRY;
|
||||||
|
} catch (BadCredentialsException e) {
|
||||||
|
logError(e);
|
||||||
|
repository.cleanAllData();
|
||||||
|
stop(getApplicationContext());
|
||||||
|
|
||||||
return JobService.RESULT_FAIL_NORETRY;
|
return JobService.RESULT_FAIL_NORETRY;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logError(e);
|
logError(e);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user