use of com.fastaccess.data.dao.AccessTokenModel in project FastHub by k0shk0sh.
the class LoginPresenter method login.
@Override
public void login(@NonNull String username, @NonNull String password, @Nullable String twoFactorCode, boolean isBasicAuth, @Nullable String endpoint) {
boolean usernameIsEmpty = InputHelper.isEmpty(username);
boolean passwordIsEmpty = InputHelper.isEmpty(password);
boolean endpointIsEmpty = InputHelper.isEmpty(endpoint) && isEnterprise();
if (getView() == null)
return;
getView().onEmptyUserName(usernameIsEmpty);
getView().onEmptyPassword(passwordIsEmpty);
getView().onEmptyEndpoint(endpointIsEmpty);
if ((!usernameIsEmpty && !passwordIsEmpty)) {
try {
String authToken = Credentials.basic(username, password);
if (isBasicAuth && !isEnterprise()) {
AuthModel authModel = new AuthModel();
authModel.setScopes(Arrays.asList("user", "repo", "gist", "notifications", "read:org"));
authModel.setNote(BuildConfig.APPLICATION_ID);
authModel.setClientSecret(GithubConfigHelper.getSecret());
authModel.setClientId(GithubConfigHelper.getClientId());
authModel.setNoteUrl(GithubConfigHelper.getRedirectUrl());
if (!InputHelper.isEmpty(twoFactorCode)) {
authModel.setOtpCode(twoFactorCode);
}
makeRestCall(LoginProvider.getLoginRestService(authToken, twoFactorCode, null).login(authModel), accessTokenModel -> {
if (!InputHelper.isEmpty(twoFactorCode)) {
PrefGetter.setOtpCode(twoFactorCode);
}
onTokenResponse(accessTokenModel);
});
} else {
accessTokenLogin(password, endpoint, twoFactorCode, authToken);
}
} catch (Exception e) {
sendToView(view -> view.showMessage("Error", "The app was about to crash!!(" + e.getMessage() + ")"));
}
}
}
Aggregations