Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:added credentials verification check #233

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ protected void onCreate(Bundle savedInstanceState) {
void onLogin() {

String tenantIdentifier = etTenant.getEditableText().toString();
if (!TextUtils.isEmpty(tenantIdentifier)) {
if (!TextUtils.isEmpty(tenantIdentifier.trim())) {
preferencesHelper.putTenantIdentifier(tenantIdentifier);
} else {
etTenant.setError(getString(R.string.error_tenant_identifier_required));
return;
}

String username = etUsername.getEditableText().toString();
if (TextUtils.isEmpty(username)) {
if (TextUtils.isEmpty(username.trim())) {
etUsername.setError(getString(R.string.error_username_required));
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.apache.fineract.data.remote.BaseApiManager.retrofit;

import android.content.Context;
import android.content.res.Resources;
import android.util.Log;

import org.apache.fineract.R;
Expand Down Expand Up @@ -62,53 +63,73 @@ public void detachView() {
@Override
public void login(String username, String password) {
checkViewAttached();
getMvpView().showProgressDialog();
compositeDisposable.add(dataManagerAuth.login(username, password)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableObserver<Authentication>() {
@Override
public void onNext(Authentication user) {
getMvpView().hideProgressDialog();
getMvpView().showUserLoginSuccessfully(user);
}

@Override
public void onError(Throwable throwable) {
getMvpView().hideProgressDialog();
if (throwable instanceof NoConnectivityException) {
getMvpView().showNoInternetConnection();
if (isCredentialsValid(username, password)) {
getMvpView().showProgressDialog();
compositeDisposable.add(dataManagerAuth.login(username, password)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableObserver<Authentication>() {
@Override
public void onNext(Authentication user) {
getMvpView().hideProgressDialog();
getMvpView().showUserLoginSuccessfully(user);
}

MifosError mifosError = new MifosError();
Converter<ResponseBody, MifosError> errorConverter =
retrofit.responseBodyConverter(MifosError.class, new Annotation[0]);
if (throwable instanceof HttpException) {
HttpException httpException = (HttpException) throwable;
Response response = httpException.response();

if (response.errorBody() != null) {
try {
mifosError = errorConverter.convert(response.errorBody());
} catch (IOException e) {
Log.d(LOG_TAG, e.getLocalizedMessage());
}
@Override
public void onError(Throwable throwable) {
getMvpView().hideProgressDialog();
if (throwable instanceof NoConnectivityException) {
getMvpView().showNoInternetConnection();
}

if (mifosError.getMessage() == null) {
getMvpView().showError(
context.getString(R.string.wrong_username_or_password));
} else {
getMvpView().showError(mifosError.getMessage());
MifosError mifosError = new MifosError();
Converter<ResponseBody, MifosError> errorConverter =
retrofit.responseBodyConverter(MifosError.class,
new Annotation[0]);
if (throwable instanceof HttpException) {
HttpException httpException = (HttpException) throwable;
Response response = httpException.response();

if (response.errorBody() != null) {
try {
mifosError = errorConverter.convert(response.errorBody());
} catch (IOException e) {
Log.d(LOG_TAG, e.getLocalizedMessage());
}
}

if (mifosError.getMessage() == null) {
getMvpView().showError(
context.getString(R.string.wrong_username_or_password));
} else {
getMvpView().showError(mifosError.getMessage());
}
}
}
}

@Override
public void onComplete() {
@Override
public void onComplete() {

}
})
);
}
}

}
})
);
private boolean isCredentialsValid(String username, String password) {

final Resources resources = context.getResources();
if (username.trim().contains(" ")) {
getMvpView().showError(context.getString(R.string.error_validation_cannot_contain_spaces
, username.trim(), context.getString(R.string.spaces) ));
return false;
} else if (password.length() < 6) {
getMvpView().showError(context.getString(R.string.error_validation_minimum_chars,
context.getString(R.string.password), resources
.getInteger(R.integer.password_minimum_length)));
return false;
}

return true;
}
}
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
<string name="payment_cycle_week">Repay every %1$d %2$s on %3$s</string>
<string name="payment_cycle_year_day">Repay every %1$d %2$s on the %3$s day in %4$s</string>
<string name="payment_cycle_year_day_week">Repay every %1$d %2$s on the %3$s %4$s in %5$s</string>
<string name="error_validation_minimum_chars">%1$s cannot be less than %2$d characters</string>
<string name="error_validation_cannot_contain_spaces">%1$s cannot contain %2$s</string>
<string name="spaces">Spaces</string>

<string name="account">Account</string>
<string name="balance">Balance</string>
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/values/validation.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<integer name="password_minimum_length">6</integer>

</resources>