Search in sources :

Example 11 with Credentials

use of org.eyeseetea.malariacare.domain.entity.Credentials in project pictureapp by EyeSeeTea.

the class LoginActivityStrategy method checkCredentials.

@Override
public void checkCredentials(Credentials credentials, final Callback callback) {
    ICredentialsRepository credentialsLocalDataSource = new CredentialsLocalDataSource();
    Credentials savedCredentials = credentialsLocalDataSource.getOrganisationCredentials();
    if (savedCredentials == null || savedCredentials.isEmpty() || savedCredentials.getUsername().equals(credentials.getUsername()) && (!savedCredentials.getPassword().equals(credentials.getPassword()) || !savedCredentials.getServerURL().equals(credentials.getServerURL()))) {
        callback.onSuccessDoLogin();
    } else if (savedCredentials.getUsername().equals(credentials.getUsername()) && savedCredentials.getPassword().equals(credentials.getPassword()) && savedCredentials.getServerURL().equals(credentials.getServerURL())) {
        callback.onSuccess();
    } else {
        IAuthenticationManager iAuthenticationManager = new AuthenticationManager(loginActivity);
        LogoutUseCase logoutUseCase = new LogoutUseCase(iAuthenticationManager);
        AlarmPushReceiver.cancelPushAlarm(loginActivity);
        logoutUseCase.execute(new LogoutUseCase.Callback() {

            @Override
            public void onLogoutSuccess() {
                callback.onSuccessDoLogin();
            }

            @Override
            public void onLogoutError(String message) {
                callback.onError();
            }
        });
    }
}
Also used : IAuthenticationManager(org.eyeseetea.malariacare.domain.boundary.IAuthenticationManager) AuthenticationManager(org.eyeseetea.malariacare.data.authentication.AuthenticationManager) IAuthenticationManager(org.eyeseetea.malariacare.domain.boundary.IAuthenticationManager) LogoutUseCase(org.eyeseetea.malariacare.domain.usecase.LogoutUseCase) CredentialsLocalDataSource(org.eyeseetea.malariacare.data.database.CredentialsLocalDataSource) Credentials(org.eyeseetea.malariacare.domain.entity.Credentials) ICredentialsRepository(org.eyeseetea.malariacare.domain.boundary.repositories.ICredentialsRepository)

Aggregations

Credentials (org.eyeseetea.malariacare.domain.entity.Credentials)11 SharedPreferences (android.content.SharedPreferences)3 Context (android.content.Context)2 AuthenticationManager (org.eyeseetea.malariacare.data.authentication.AuthenticationManager)2 CredentialsLocalDataSource (org.eyeseetea.malariacare.data.database.CredentialsLocalDataSource)2 IAuthenticationManager (org.eyeseetea.malariacare.domain.boundary.IAuthenticationManager)2 ICredentialsRepository (org.eyeseetea.malariacare.domain.boundary.repositories.ICredentialsRepository)2 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 IOException (java.io.IOException)1 InvalidLoginAttemptsRepositoryLocalDataSource (org.eyeseetea.malariacare.data.database.InvalidLoginAttemptsRepositoryLocalDataSource)1 OrganisationUnitRepository (org.eyeseetea.malariacare.data.repositories.OrganisationUnitRepository)1 IAsyncExecutor (org.eyeseetea.malariacare.domain.boundary.executors.IAsyncExecutor)1 IMainExecutor (org.eyeseetea.malariacare.domain.boundary.executors.IMainExecutor)1 IInvalidLoginAttemptsRepository (org.eyeseetea.malariacare.domain.boundary.repositories.IInvalidLoginAttemptsRepository)1 IOrganisationUnitRepository (org.eyeseetea.malariacare.domain.boundary.repositories.IOrganisationUnitRepository)1 OrganisationUnit (org.eyeseetea.malariacare.domain.entity.OrganisationUnit)1 ApiCallException (org.eyeseetea.malariacare.domain.exception.ApiCallException)1 ConfigJsonIOException (org.eyeseetea.malariacare.domain.exception.ConfigJsonIOException)1 NetworkException (org.eyeseetea.malariacare.domain.exception.NetworkException)1