Search in sources :

Example 1 with Credentials

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

the class AuthenticationManager method getServerCredentials.

public Credentials getServerCredentials(String serverUrl) {
    String username = PreferencesState.getInstance().getContext().getString(R.string.user_push);
    String password = PreferencesState.getInstance().getContext().getString(R.string.pass_push);
    Credentials credentials = new Credentials(serverUrl, username, password);
    return credentials;
}
Also used : Credentials(org.eyeseetea.malariacare.domain.entity.Credentials)

Example 2 with Credentials

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

the class LoadUserAndCredentialsUseCase method loadCredentials.

private void loadCredentials() {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
    String serverURL = sharedPreferences.getString(mContext.getString(R.string.dhis_url), "");
    String username = sharedPreferences.getString(mContext.getString(R.string.dhis_user), "");
    String password = sharedPreferences.getString(mContext.getString(R.string.dhis_password), "");
    Credentials credentials = new Credentials(serverURL, username, password);
    Session.setCredentials(credentials);
}
Also used : SharedPreferences(android.content.SharedPreferences) Credentials(org.eyeseetea.malariacare.domain.entity.Credentials)

Example 3 with Credentials

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

the class LoginActivity method login.

public void login(String serverUrl, String username, String password) {
    final Credentials credentials = new Credentials(serverUrl, username, password);
    onStartLoading();
    mLoginActivityStrategy.checkCredentials(credentials, new ALoginActivityStrategy.Callback() {

        @Override
        public void onSuccess() {
            mLoginActivityStrategy.onLoginSuccess(credentials);
        }

        @Override
        public void onSuccessDoLogin() {
            executeLoginUseCase(credentials);
        }

        @Override
        public void onError() {
            hideProgressBar();
            showError(getString(R.string.login_unexpected_error));
        }
    });
}
Also used : ALoginActivityStrategy(org.eyeseetea.malariacare.strategies.ALoginActivityStrategy) Credentials(org.eyeseetea.malariacare.domain.entity.Credentials)

Example 4 with Credentials

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

the class PreferencesState method getCredentialsFromPreferences.

/**
 * Get credentials from sharedPreferences.
 */
public static Credentials getCredentialsFromPreferences() {
    Context context = PreferencesState.getInstance().getContext();
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    String url = sharedPreferences.getString(context.getString(R.string.dhis_url), "");
    String username = sharedPreferences.getString(context.getString(R.string.dhis_user), "");
    String password = sharedPreferences.getString(context.getString(R.string.dhis_password), "");
    Credentials credentials = new Credentials(url, username, password);
    return credentials;
}
Also used : Context(android.content.Context) SharedPreferences(android.content.SharedPreferences) Credentials(org.eyeseetea.malariacare.domain.entity.Credentials)

Example 5 with Credentials

use of org.eyeseetea.malariacare.domain.entity.Credentials 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)

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