Search in sources :

Example 6 with Credentials

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

the class PreferencesEReferral method getUserCredentialsFromPreferences.

/**
 * Get logged user credentials from sharedPreferences.
 */
public static Credentials getUserCredentialsFromPreferences() {
    Context context = PreferencesState.getInstance().getContext();
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    String url = sharedPreferences.getString(context.getString(R.string.dhis_url), null);
    String username = sharedPreferences.getString(context.getString(R.string.logged_user_username), null);
    String password = sharedPreferences.getString(context.getString(R.string.logged_user_pin), null);
    if (url == null || username == null || password == null)
        return null;
    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 7 with Credentials

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

the class CredentialsLocalDataSource method clearOrganisationCredentials.

@Override
public void clearOrganisationCredentials() {
    Credentials credentials = getOrganisationCredentials();
    credentials.clear();
    saveOrganisationCredentials(credentials);
}
Also used : Credentials(org.eyeseetea.malariacare.domain.entity.Credentials)

Example 8 with Credentials

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

the class LoginActivityStrategy method addDemoButton.

private void addDemoButton() {
    final ViewGroup loginViewsContainer = (ViewGroup) loginActivity.findViewById(R.id.login_dynamic_views_container);
    loginActivity.getLayoutInflater().inflate(R.layout.demo_login_button, loginViewsContainer, true);
    FontButton demoButton = (FontButton) loginActivity.findViewById(R.id.demo_login_button);
    demoButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Credentials demoCrededentials = Credentials.createDemoCredentials();
            loginActivity.showProgressBar();
            loginActivity.mLoginUseCase.execute(demoCrededentials, new ALoginUseCase.Callback() {

                @Override
                public void onLoginSuccess() {
                    executePullDemo();
                }

                @Override
                public void onServerURLNotValid() {
                    Log.e(this.getClass().getSimpleName(), "Server url not valid");
                }

                @Override
                public void onInvalidCredentials() {
                    Log.e(this.getClass().getSimpleName(), "Invalid credentials");
                }

                @Override
                public void onNetworkError() {
                    Log.e(this.getClass().getSimpleName(), "Network Error");
                }

                @Override
                public void onConfigJsonInvalid() {
                    Log.d(TAG, "onConfigJsonInvalid");
                }

                @Override
                public void onUnexpectedError() {
                    Log.e(this.getClass().getSimpleName(), "Config Json file not found");
                }

                @Override
                public void onMaxLoginAttemptsReachedError() {
                    Log.d(TAG, "onMaxLoginAttemptsReachedError");
                }
            });
        }
    });
}
Also used : ViewGroup(android.view.ViewGroup) FontButton(org.hisp.dhis.client.sdk.ui.views.FontButton) View(android.view.View) Credentials(org.eyeseetea.malariacare.domain.entity.Credentials)

Example 9 with Credentials

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

the class AuthenticationManager method getHardcodedServerCredentials.

public Credentials getHardcodedServerCredentials(String serverUrl) throws ConfigJsonIOException {
    String username = CredentialsReader.getInstance().getUser();
    String password = CredentialsReader.getInstance().getPassword();
    Credentials credentials = new Credentials(serverUrl, username, password);
    return credentials;
}
Also used : Credentials(org.eyeseetea.malariacare.domain.entity.Credentials)

Example 10 with Credentials

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

the class LoginUseCase method pullOrganisationCredentials.

private void pullOrganisationCredentials() {
    Credentials orgUnitCredentials = null;
    try {
        OrganisationUnit orgUnit = mOrgUnitDataSource.getUserOrgUnit(insertedCredentials);
        if (orgUnit == null) {
            notifyInvalidCredentials();
            return;
        }
        orgUnitCredentials = new Credentials(insertedCredentials.getServerURL(), orgUnit.getCode(), orgUnit.getPin());
    } catch (ApiCallException e) {
        if (e.getCause() instanceof IOException) {
            notifyUnexpectedError();
        } else {
            e.printStackTrace();
            notifyConfigJsonNotPresent();
        }
    } catch (NetworkException e) {
        e.printStackTrace();
        checkUserCredentialsWithOrgUnit(mCredentialsLocalDataSource.getOrganisationCredentials(), true);
    }
    mCredentialsLocalDataSource.saveOrganisationCredentials(orgUnitCredentials);
    checkUserCredentialsWithOrgUnit(orgUnitCredentials, false);
}
Also used : OrganisationUnit(org.eyeseetea.malariacare.domain.entity.OrganisationUnit) ApiCallException(org.eyeseetea.malariacare.domain.exception.ApiCallException) IOException(java.io.IOException) ConfigJsonIOException(org.eyeseetea.malariacare.domain.exception.ConfigJsonIOException) NetworkException(org.eyeseetea.malariacare.domain.exception.NetworkException) Credentials(org.eyeseetea.malariacare.domain.entity.Credentials)

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