Search in sources :

Example 1 with AuthenticationManager

use of org.eyeseetea.malariacare.data.authentication.AuthenticationManager in project pictureapp by EyeSeeTea.

the class ProgressActivity method initializeDependencies.

private void initializeDependencies() {
    AuthenticationManager authenticationManager = new AuthenticationManager(this);
    IPullController pullController = new PullController(this);
    IAsyncExecutor asyncExecutor = new AsyncExecutor();
    IMainExecutor mainExecutor = new UIThreadExecutor();
    mLogoutUseCase = new LogoutUseCase(authenticationManager);
    mPullUseCase = new PullUseCase(pullController, asyncExecutor, mainExecutor);
}
Also used : AuthenticationManager(org.eyeseetea.malariacare.data.authentication.AuthenticationManager) IPullController(org.eyeseetea.malariacare.domain.boundary.IPullController) PullUseCase(org.eyeseetea.malariacare.domain.usecase.pull.PullUseCase) UIThreadExecutor(org.eyeseetea.malariacare.presentation.executors.UIThreadExecutor) IAsyncExecutor(org.eyeseetea.malariacare.domain.boundary.executors.IAsyncExecutor) LogoutUseCase(org.eyeseetea.malariacare.domain.usecase.LogoutUseCase) PullController(org.eyeseetea.malariacare.data.sync.importer.PullController) IPullController(org.eyeseetea.malariacare.domain.boundary.IPullController) IAsyncExecutor(org.eyeseetea.malariacare.domain.boundary.executors.IAsyncExecutor) AsyncExecutor(org.eyeseetea.malariacare.presentation.executors.AsyncExecutor) IMainExecutor(org.eyeseetea.malariacare.domain.boundary.executors.IMainExecutor)

Example 2 with AuthenticationManager

use of org.eyeseetea.malariacare.data.authentication.AuthenticationManager 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 3 with AuthenticationManager

use of org.eyeseetea.malariacare.data.authentication.AuthenticationManager 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 4 with AuthenticationManager

use of org.eyeseetea.malariacare.data.authentication.AuthenticationManager in project pictureapp by EyeSeeTea.

the class SettingsActivityStrategy method onCreate.

@Override
public void onCreate() {
    mAuthenticationManager = new AuthenticationManager(settingsActivity);
    mLogoutUseCase = new LogoutUseCase(mAuthenticationManager);
    IntentFilter screenStateFilter = new IntentFilter();
    screenStateFilter.addAction(Intent.ACTION_SCREEN_ON);
    screenStateFilter.addAction(Intent.ACTION_SCREEN_OFF);
    settingsActivity.registerReceiver(mScreenOffReceiver, screenStateFilter);
}
Also used : IAuthenticationManager(org.eyeseetea.malariacare.domain.boundary.IAuthenticationManager) AuthenticationManager(org.eyeseetea.malariacare.data.authentication.AuthenticationManager) IntentFilter(android.content.IntentFilter) LogoutUseCase(org.eyeseetea.malariacare.domain.usecase.LogoutUseCase)

Example 5 with AuthenticationManager

use of org.eyeseetea.malariacare.data.authentication.AuthenticationManager in project pictureapp by EyeSeeTea.

the class LogoutAndLoginRequiredOnPreferenceClickListener method logout.

private void logout() {
    Log.d(TAG, "Logging out...");
    AuthenticationManager authenticationManager = new AuthenticationManager(settingsActivity);
    LogoutUseCase logoutUseCase = new LogoutUseCase(authenticationManager);
    logoutUseCase.execute(new LogoutUseCase.Callback() {

        @Override
        public void onLogoutSuccess() {
            Intent loginIntent = new Intent(settingsActivity, LoginActivity.class);
            settingsActivity.finish();
            settingsActivity.startActivity(loginIntent);
        }

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

Aggregations

AuthenticationManager (org.eyeseetea.malariacare.data.authentication.AuthenticationManager)8 LogoutUseCase (org.eyeseetea.malariacare.domain.usecase.LogoutUseCase)7 IAuthenticationManager (org.eyeseetea.malariacare.domain.boundary.IAuthenticationManager)6 Intent (android.content.Intent)2 LoginActivity (org.eyeseetea.malariacare.LoginActivity)2 CredentialsLocalDataSource (org.eyeseetea.malariacare.data.database.CredentialsLocalDataSource)2 IAsyncExecutor (org.eyeseetea.malariacare.domain.boundary.executors.IAsyncExecutor)2 IMainExecutor (org.eyeseetea.malariacare.domain.boundary.executors.IMainExecutor)2 ICredentialsRepository (org.eyeseetea.malariacare.domain.boundary.repositories.ICredentialsRepository)2 Credentials (org.eyeseetea.malariacare.domain.entity.Credentials)2 AsyncExecutor (org.eyeseetea.malariacare.presentation.executors.AsyncExecutor)2 UIThreadExecutor (org.eyeseetea.malariacare.presentation.executors.UIThreadExecutor)2 IntentFilter (android.content.IntentFilter)1 InvalidLoginAttemptsRepositoryLocalDataSource (org.eyeseetea.malariacare.data.database.InvalidLoginAttemptsRepositoryLocalDataSource)1 OrganisationUnitRepository (org.eyeseetea.malariacare.data.repositories.OrganisationUnitRepository)1 PullController (org.eyeseetea.malariacare.data.sync.importer.PullController)1 IPullController (org.eyeseetea.malariacare.domain.boundary.IPullController)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