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;
}
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);
}
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");
}
});
}
});
}
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;
}
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);
}
Aggregations