Search in sources :

Example 1 with IAuthenticationManager

use of org.eyeseetea.malariacare.domain.boundary.IAuthenticationManager in project pictureapp by EyeSeeTea.

the class PushServiceStrategy method push.

@Override
public void push() {
    IAuthenticationManager authenticationManager = new AuthenticationManager(PreferencesState.getInstance().getContext());
    IMainExecutor mainExecutor = new UIThreadExecutor();
    IAsyncExecutor asyncExecutor = new AsyncExecutor();
    ICredentialsRepository credentialsLocalDataSoruce = new CredentialsLocalDataSource();
    IOrganisationUnitRepository organisationDataSource = new OrganisationUnitRepository();
    IInvalidLoginAttemptsRepository iInvalidLoginAttemptsRepository = new InvalidLoginAttemptsRepositoryLocalDataSource();
    LoginUseCase loginUseCase = new LoginUseCase(authenticationManager, mainExecutor, asyncExecutor, organisationDataSource, credentialsLocalDataSoruce, iInvalidLoginAttemptsRepository);
    final Credentials oldCredentials = credentialsLocalDataSoruce.getOrganisationCredentials();
    loginUseCase.execute(oldCredentials, new ALoginUseCase.Callback() {

        @Override
        public void onLoginSuccess() {
            PushServiceStrategy.this.onCorrectCredentials();
        }

        @Override
        public void onServerURLNotValid() {
            Log.e(TAG, "Error getting user credentials: URL not valid ");
        }

        @Override
        public void onInvalidCredentials() {
            logout();
        }

        @Override
        public void onNetworkError() {
            Log.e(TAG, "Error getting user credentials: NetworkError");
        }

        @Override
        public void onConfigJsonInvalid() {
            Log.e(TAG, "Error getting user credentials: JsonInvalid");
        }

        @Override
        public void onUnexpectedError() {
            Log.e(TAG, "Error getting user credentials: unexpectedError ");
        }

        @Override
        public void onMaxLoginAttemptsReachedError() {
        }
    });
}
Also used : OrganisationUnitRepository(org.eyeseetea.malariacare.data.repositories.OrganisationUnitRepository) IOrganisationUnitRepository(org.eyeseetea.malariacare.domain.boundary.repositories.IOrganisationUnitRepository) IAuthenticationManager(org.eyeseetea.malariacare.domain.boundary.IAuthenticationManager) ALoginUseCase(org.eyeseetea.malariacare.domain.usecase.ALoginUseCase) IAsyncExecutor(org.eyeseetea.malariacare.domain.boundary.executors.IAsyncExecutor) LoginUseCase(org.eyeseetea.malariacare.domain.usecase.LoginUseCase) ALoginUseCase(org.eyeseetea.malariacare.domain.usecase.ALoginUseCase) CredentialsLocalDataSource(org.eyeseetea.malariacare.data.database.CredentialsLocalDataSource) IMainExecutor(org.eyeseetea.malariacare.domain.boundary.executors.IMainExecutor) ICredentialsRepository(org.eyeseetea.malariacare.domain.boundary.repositories.ICredentialsRepository) IAuthenticationManager(org.eyeseetea.malariacare.domain.boundary.IAuthenticationManager) AuthenticationManager(org.eyeseetea.malariacare.data.authentication.AuthenticationManager) UIThreadExecutor(org.eyeseetea.malariacare.presentation.executors.UIThreadExecutor) IOrganisationUnitRepository(org.eyeseetea.malariacare.domain.boundary.repositories.IOrganisationUnitRepository) InvalidLoginAttemptsRepositoryLocalDataSource(org.eyeseetea.malariacare.data.database.InvalidLoginAttemptsRepositoryLocalDataSource) IInvalidLoginAttemptsRepository(org.eyeseetea.malariacare.domain.boundary.repositories.IInvalidLoginAttemptsRepository) Credentials(org.eyeseetea.malariacare.domain.entity.Credentials) IAsyncExecutor(org.eyeseetea.malariacare.domain.boundary.executors.IAsyncExecutor) AsyncExecutor(org.eyeseetea.malariacare.presentation.executors.AsyncExecutor)

Example 2 with IAuthenticationManager

use of org.eyeseetea.malariacare.domain.boundary.IAuthenticationManager in project pictureapp by EyeSeeTea.

the class PushServiceStrategy method logout.

public void logout() {
    IAuthenticationManager authenticationManager;
    LogoutUseCase logoutUseCase;
    authenticationManager = new AuthenticationManager(mPushService);
    logoutUseCase = new LogoutUseCase(authenticationManager);
    AlarmPushReceiver.cancelPushAlarm(mPushService);
    logoutUseCase.execute(new LogoutUseCase.Callback() {

        @Override
        public void onLogoutSuccess() {
            if (!EyeSeeTeaApplication.getInstance().isAppWentToBg()) {
                Intent loginIntent = new Intent(mPushService, LoginActivity.class);
                loginIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                mPushService.startActivity(loginIntent);
            }
        }

        @Override
        public void onLogoutError(String message) {
            Log.d(TAG, message);
        }
    });
}
Also used : IAuthenticationManager(org.eyeseetea.malariacare.domain.boundary.IAuthenticationManager) AuthenticationManager(org.eyeseetea.malariacare.data.authentication.AuthenticationManager) IAuthenticationManager(org.eyeseetea.malariacare.domain.boundary.IAuthenticationManager) LoginActivity(org.eyeseetea.malariacare.LoginActivity) LogoutUseCase(org.eyeseetea.malariacare.domain.usecase.LogoutUseCase) Intent(android.content.Intent)

Example 3 with IAuthenticationManager

use of org.eyeseetea.malariacare.domain.boundary.IAuthenticationManager in project pictureapp by EyeSeeTea.

the class DashboardActivity method executeLogout.

public void executeLogout() {
    IAuthenticationManager iAuthenticationManager = new AuthenticationManager(this);
    LogoutUseCase logoutUseCase = new LogoutUseCase(iAuthenticationManager);
    AlarmPushReceiver.cancelPushAlarm(this);
    logoutUseCase.execute(new LogoutUseCase.Callback() {

        @Override
        public void onLogoutSuccess() {
            DashboardActivityStrategy.onLogoutSuccess();
        }

        @Override
        public void onLogoutError(String message) {
            Log.e("." + this.getClass().getSimpleName(), message);
        }
    });
}
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)

Example 4 with IAuthenticationManager

use of org.eyeseetea.malariacare.domain.boundary.IAuthenticationManager 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

AuthenticationManager (org.eyeseetea.malariacare.data.authentication.AuthenticationManager)4 IAuthenticationManager (org.eyeseetea.malariacare.domain.boundary.IAuthenticationManager)4 LogoutUseCase (org.eyeseetea.malariacare.domain.usecase.LogoutUseCase)3 CredentialsLocalDataSource (org.eyeseetea.malariacare.data.database.CredentialsLocalDataSource)2 ICredentialsRepository (org.eyeseetea.malariacare.domain.boundary.repositories.ICredentialsRepository)2 Credentials (org.eyeseetea.malariacare.domain.entity.Credentials)2 Intent (android.content.Intent)1 LoginActivity (org.eyeseetea.malariacare.LoginActivity)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 ALoginUseCase (org.eyeseetea.malariacare.domain.usecase.ALoginUseCase)1 LoginUseCase (org.eyeseetea.malariacare.domain.usecase.LoginUseCase)1 AsyncExecutor (org.eyeseetea.malariacare.presentation.executors.AsyncExecutor)1 UIThreadExecutor (org.eyeseetea.malariacare.presentation.executors.UIThreadExecutor)1