diff --git a/app/src/main/java/org/mifos/mobilebanking/presenters/LoginPresenter.java b/app/src/main/java/org/mifos/mobilebanking/presenters/LoginPresenter.java index 1716ab9299..9de55ad575 100644 --- a/app/src/main/java/org/mifos/mobilebanking/presenters/LoginPresenter.java +++ b/app/src/main/java/org/mifos/mobilebanking/presenters/LoginPresenter.java @@ -75,7 +75,7 @@ public void detachView() { */ public void login(final String username, final String password) { checkViewAttached(); - if (isCredentialsValid(username, password)) { + if ((isUsernameValid(username) | isPasswordValid(password)) == 0) { getMvpView().showProgress(); compositeDisposable.add(dataManager.login(username, password) .observeOn(AndroidSchedulers.mainThread()) @@ -173,38 +173,42 @@ public void onNext(Page clientPage) { ); } - - private boolean isCredentialsValid(final String username, final String password) { - + private int isUsernameValid(final String username) { final Resources resources = context.getResources(); final String correctUsername = username.replaceFirst("\\s++$", "").trim(); - if (username == null || username.matches("\\s*") || username.isEmpty()) { + if (username.matches("\\s*") || username.isEmpty()) { getMvpView().showUsernameError(context.getString(R.string.error_validation_blank, context.getString(R.string.username))); - return false; + return 1; } else if (username.length() < 5) { getMvpView().showUsernameError(context.getString(R.string.error_validation_minimum_chars , resources.getString(R.string.username), resources.getInteger(R.integer. username_minimum_length))); - return false; + return 1; } else if (correctUsername.contains(" ")) { getMvpView().showUsernameError(context.getString( R.string.error_validation_cannot_contain_spaces, resources.getString(R.string.username), context.getString(R.string.not_contain_username))); - return false; - } else if (password == null || password.isEmpty()) { + return 1; + } + return 0; + } + + private int isPasswordValid(final String password) { + final Resources resources = context.getResources(); + if (password == null || password.isEmpty()) { getMvpView().showPasswordError(context.getString(R.string.error_validation_blank, context.getString(R.string.password))); - return false; + return 1; } else if (password.length() < 6) { getMvpView().showPasswordError(context.getString(R.string.error_validation_minimum_chars , resources.getString(R.string.password), resources.getInteger(R.integer. password_minimum_length))); - return false; + return 1; } - return true; + return 0; } /**