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..26c8234419 100644 --- a/app/src/main/java/org/mifos/mobilebanking/presenters/LoginPresenter.java +++ b/app/src/main/java/org/mifos/mobilebanking/presenters/LoginPresenter.java @@ -34,6 +34,8 @@ public class LoginPresenter extends BasePresenter { private final DataManager dataManager; private PreferencesHelper preferencesHelper; private CompositeDisposable compositeDisposable; + private Resources resources; + private boolean fieldNotValidated; /** * Initialises the LoginPresenter by automatically injecting an instance of @@ -50,6 +52,7 @@ public LoginPresenter(DataManager dataManager, @ApplicationContext Context conte this.dataManager = dataManager; preferencesHelper = this.dataManager.getPreferencesHelper(); compositeDisposable = new CompositeDisposable(); + resources = context.getResources(); } @Override @@ -175,36 +178,45 @@ public void onNext(Page clientPage) { private boolean isCredentialsValid(final String username, final String password) { + fieldNotValidated = false; + validateUsername(username); + validatePassword(password); - final Resources resources = context.getResources(); + return !fieldNotValidated; + } + + private void validateUsername(final String username) { final String correctUsername = username.replaceFirst("\\s++$", "").trim(); + if (username == null || username.matches("\\s*") || username.isEmpty()) { getMvpView().showUsernameError(context.getString(R.string.error_validation_blank, context.getString(R.string.username))); - return false; + fieldNotValidated = true; } 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; + fieldNotValidated = true; } 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()) { + fieldNotValidated = true; + } + } + + private void validatePassword(final String password) { + if (password == null || password.isEmpty()) { getMvpView().showPasswordError(context.getString(R.string.error_validation_blank, context.getString(R.string.password))); - return false; + fieldNotValidated = true; } 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; + fieldNotValidated = true; } - - return true; } /** diff --git a/build.gradle b/build.gradle index 640f95077c..7df47c0372 100644 --- a/build.gradle +++ b/build.gradle @@ -19,8 +19,8 @@ buildscript { allprojects { repositories { - jcenter() google() + jcenter() maven { url "https://www.jitpack.io" } maven { url 'https://maven.fabric.io/public' } }