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