|
|
@ -1,173 +1,150 @@ |
|
|
|
package com.gmeremit.online.gmeremittance_native.profile.presenter.profilechange; |
|
|
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity; |
|
|
|
|
|
|
|
import com.gmeremit.online.gmeremittance_native.R; |
|
|
|
import com.gmeremit.online.gmeremittance_native.base.BasePresenter; |
|
|
|
import com.gmeremit.online.gmeremittance_native.base.BaseViewModel; |
|
|
|
import com.gmeremit.online.gmeremittance_native.common.model.FormInputStateDTO; |
|
|
|
import com.gmeremit.online.gmeremittance_native.profile.gateway.profilechange.ChangePasswordV2Gateway; |
|
|
|
import com.gmeremit.online.gmeremittance_native.profile.model.ChangePasswordActivityV2APIResponse; |
|
|
|
import com.gmeremit.online.gmeremittance_native.customwidgets.CustomAlertDialog; |
|
|
|
import com.gmeremit.online.gmeremittance_native.security.GMEAuthManager; |
|
|
|
import com.gmeremit.online.gmeremittance_native.utils.Constants; |
|
|
|
import com.gmeremit.online.gmeremittance_native.utils.Utils; |
|
|
|
import com.gmeremit.online.gmeremittance_native.utils.https.GenericApiObserverResponse; |
|
|
|
import com.gmeremit.online.gmeremittance_native.security.utils.SecurityUtils; |
|
|
|
|
|
|
|
import io.reactivex.CompletableObserver; |
|
|
|
import io.reactivex.Observable; |
|
|
|
import io.reactivex.android.schedulers.AndroidSchedulers; |
|
|
|
import io.reactivex.disposables.CompositeDisposable; |
|
|
|
import io.reactivex.disposables.Disposable; |
|
|
|
import io.reactivex.observers.DisposableObserver; |
|
|
|
import io.reactivex.schedulers.Schedulers; |
|
|
|
|
|
|
|
public class ChangePasswordV2Presenter extends BasePresenter implements ChangePasswordV2InteractorInterface, ChangePasswordV2PresenterInterface { |
|
|
|
public class ChangePasswordV2Presenter extends BaseViewModel implements ChangePasswordV2InteractorInterface, ChangePasswordV2PresenterInterface { |
|
|
|
|
|
|
|
private final ChangePasswordV2PresenterInterface.ChangePasswordV2ContractInterface view; |
|
|
|
private final ChangePasswordV2Gateway gateway; |
|
|
|
|
|
|
|
private String encCurrentPassword; |
|
|
|
private String encNewPassword; |
|
|
|
private String encConfirmPassword; |
|
|
|
private final ChangePasswordLiveData changePasswordLiveData; |
|
|
|
private final CompositeDisposable useCaseCompositeDisposable; |
|
|
|
private final CompositeDisposable viewEventCompositeDisposable; |
|
|
|
private final ChangePasswordValidator changePasswordValidator; |
|
|
|
|
|
|
|
public ChangePasswordV2Presenter(ChangePasswordV2PresenterInterface.ChangePasswordV2ContractInterface view,ChangePasswordV2Gateway gateway) { |
|
|
|
public ChangePasswordV2Presenter(ChangePasswordV2PresenterInterface.ChangePasswordV2ContractInterface view, ChangePasswordV2Gateway gateway) { |
|
|
|
this.view = view; |
|
|
|
this.gateway = gateway; |
|
|
|
|
|
|
|
this.encCurrentPassword = ""; |
|
|
|
this.encNewPassword = ""; |
|
|
|
this.encConfirmPassword = ""; |
|
|
|
this.changePasswordValidator = new ChangePasswordValidator(); |
|
|
|
changePasswordLiveData = new ChangePasswordLiveData(); |
|
|
|
useCaseCompositeDisposable = new CompositeDisposable(); |
|
|
|
viewEventCompositeDisposable = new CompositeDisposable(); |
|
|
|
} |
|
|
|
|
|
|
|
@Deprecated |
|
|
|
@Override |
|
|
|
public boolean validateData(String currentPass, String newPwd, String pwdConfrimString) { |
|
|
|
boolean currentPwdValidation = true; |
|
|
|
boolean confirmPwdValidation = true; |
|
|
|
boolean newPwdValidation = true; |
|
|
|
|
|
|
|
if (currentPass.trim().length() < 1) { |
|
|
|
this.view.setCurrentPasswordError(getStringfromStringId(R.string.password_empty_error)); |
|
|
|
currentPwdValidation = false; |
|
|
|
} |
|
|
|
|
|
|
|
if (!Utils.hasSpecialCharacters(newPwd)) { |
|
|
|
this.view.setNewPasswordError(getStringfromStringId(R.string.password_symbol_required_error)); |
|
|
|
newPwdValidation = false; |
|
|
|
} |
|
|
|
if (!Utils.hasNumbers(newPwd)) { |
|
|
|
this.view.setNewPasswordError(getStringfromStringId(R.string.password_number_required_error)); |
|
|
|
newPwdValidation = false; |
|
|
|
} |
|
|
|
if (newPwd.length() > 1 && newPwd.length() < 9) { |
|
|
|
this.view.setNewPasswordError(getStringfromStringId(R.string.password_length_error)); |
|
|
|
newPwdValidation = false; |
|
|
|
} |
|
|
|
if (!Utils.hasAtleastOnCapitalLetter(newPwd)) { |
|
|
|
this.view.setNewPasswordError(getStringfromStringId(R.string.password_capital_letter_required_error)); |
|
|
|
newPwdValidation = false; |
|
|
|
} |
|
|
|
if (newPwd.trim().length() < 1) { |
|
|
|
this.view.setNewPasswordError(getStringfromStringId(R.string.password_empty_error)); |
|
|
|
newPwdValidation = false; |
|
|
|
} |
|
|
|
|
|
|
|
if (!newPwd.equals(pwdConfrimString)) { |
|
|
|
this.view.setConfirmPasswordError(getStringfromStringId(R.string.confirm_password_mismatch_error)); |
|
|
|
confirmPwdValidation = false; |
|
|
|
} |
|
|
|
if (pwdConfrimString == null || pwdConfrimString.trim().length() < 1) { |
|
|
|
this.view.setConfirmPasswordError(getStringfromStringId(R.string.confirm_passowrd_empty_error)); |
|
|
|
confirmPwdValidation = false; |
|
|
|
} |
|
|
|
|
|
|
|
public ChangePasswordLiveData getChangePasswordRelatedViewEvents(ChangePasswordLiveData.ChangePasswordViewBindings viewBindings) { |
|
|
|
bindView(viewBindings); |
|
|
|
return changePasswordLiveData; |
|
|
|
} |
|
|
|
|
|
|
|
if (currentPwdValidation) { |
|
|
|
view.setCurrentPasswordError(null); |
|
|
|
} |
|
|
|
if (confirmPwdValidation) { |
|
|
|
view.setConfirmPasswordError(null); |
|
|
|
private void bindView(ChangePasswordLiveData.ChangePasswordViewBindings viewBindings) { |
|
|
|
viewEventCompositeDisposable.add( |
|
|
|
Observable.combineLatest( |
|
|
|
viewBindings.getCurrentPasswordInputLiveData().map(this.changePasswordValidator::isCurrentPasswordValid), |
|
|
|
viewBindings.getNewPasswordInputLiveData().map(this.changePasswordValidator::isNewPasswordValid), |
|
|
|
viewBindings.getConfirmPasswordInputLiveData().map(this.changePasswordValidator::isConfirmPasswordValid), |
|
|
|
(isCurrentPassValid, isNewPasswordValid, isConfirmPasswordValid) -> |
|
|
|
isCurrentPassValid && isNewPasswordValid && isConfirmPasswordValid) |
|
|
|
.subscribeWith(new DisposableObserver<Boolean>() { |
|
|
|
@Override |
|
|
|
public void onNext(Boolean result) { |
|
|
|
changePasswordLiveData.setAllFormValidLiveData(new FormInputStateDTO(result, "")); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onError(Throwable e) { |
|
|
|
changePasswordLiveData.setAllFormValidLiveData(new FormInputStateDTO(false, "")); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onComplete() { |
|
|
|
|
|
|
|
} |
|
|
|
})); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
@Override |
|
|
|
public void onViewReady() { |
|
|
|
|
|
|
|
if (newPwdValidation) { |
|
|
|
view.setNewPasswordError(null); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
@Override |
|
|
|
public void onViewNotReady() { |
|
|
|
|
|
|
|
return currentPwdValidation && confirmPwdValidation && newPwdValidation; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public boolean validateAll() { |
|
|
|
boolean currentPwdValidation = true; |
|
|
|
boolean confirmPwdValidation = true; |
|
|
|
boolean newPwdValidation = true; |
|
|
|
|
|
|
|
if (encCurrentPassword == null || encCurrentPassword.trim().length() < 1) { |
|
|
|
this.view.setCurrentPasswordError(getStringfromStringId(R.string.password_empty_error)); |
|
|
|
currentPwdValidation = false; |
|
|
|
} |
|
|
|
public void changePassword() { |
|
|
|
useCaseCompositeDisposable.add( |
|
|
|
this.gateway.performChangePassRequest(this.gateway.getAuth(), this.gateway.getUserID(), this.changePasswordValidator.currentPassword, this.changePasswordValidator.newPassword, this.changePasswordValidator.confirmPassword) |
|
|
|
.doOnSubscribe(d -> view.showProgressBar(true, getStringfromStringId(R.string.processing_request_text))) |
|
|
|
.subscribeOn(Schedulers.io()) |
|
|
|
.observeOn(AndroidSchedulers.mainThread()) |
|
|
|
.doFinally(() -> view.showProgressBar(false, "")) |
|
|
|
.subscribeWith(new ChangePasswordObserver(this.changePasswordValidator.newPassword))); |
|
|
|
} |
|
|
|
|
|
|
|
if (encNewPassword == null || encNewPassword.trim().length() < 1) { |
|
|
|
this.view.setNewPasswordError(getStringfromStringId(R.string.password_empty_error)); |
|
|
|
newPwdValidation = false; |
|
|
|
} |
|
|
|
|
|
|
|
if (encConfirmPassword == null || encConfirmPassword.trim().length() < 1) { |
|
|
|
this.view.setConfirmPasswordError(getStringfromStringId(R.string.confirm_passowrd_empty_error)); |
|
|
|
confirmPwdValidation = false; |
|
|
|
} |
|
|
|
private class ChangePasswordValidator { |
|
|
|
|
|
|
|
if (currentPwdValidation) { |
|
|
|
view.setCurrentPasswordError(null); |
|
|
|
} |
|
|
|
if (confirmPwdValidation) { |
|
|
|
view.setConfirmPasswordError(null); |
|
|
|
private String currentPassword; |
|
|
|
private String newPassword; |
|
|
|
private String confirmPassword; |
|
|
|
|
|
|
|
} |
|
|
|
boolean isCurrentPasswordValid(CharSequence password) { |
|
|
|
if (password != null && password.length() > 0) { |
|
|
|
this.currentPassword = password.toString(); |
|
|
|
changePasswordLiveData.setCurrentPasswordInputLiveData(new FormInputStateDTO<>(true, null)); |
|
|
|
return true; |
|
|
|
} else { |
|
|
|
this.currentPassword = null; |
|
|
|
changePasswordLiveData.setCurrentPasswordInputLiveData(new FormInputStateDTO<>(false, getStringfromStringId(R.string.password_empty_error))); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
if (newPwdValidation) { |
|
|
|
view.setNewPasswordError(null); |
|
|
|
} |
|
|
|
|
|
|
|
return currentPwdValidation && confirmPwdValidation && newPwdValidation; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void changePassword(String currentPass, String newPass) { |
|
|
|
boolean isNewPasswordValid(CharSequence password) { |
|
|
|
if (password != null && password.length() > 0) { |
|
|
|
this.newPassword = password.toString(); |
|
|
|
changePasswordLiveData.setNewPasswordInputLiveData(new FormInputStateDTO<>(true, null)); |
|
|
|
return true; |
|
|
|
} else { |
|
|
|
this.newPassword = null; |
|
|
|
changePasswordLiveData.setNewPasswordInputLiveData(new FormInputStateDTO<>(false, getStringfromStringId(R.string.password_empty_error))); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
this.gateway.performChangePassRequest(this.gateway.getAuth(), this.gateway.getUserID(), this.encCurrentPassword, this.encNewPassword, this.encConfirmPassword) |
|
|
|
.doOnSubscribe(d -> view.showProgressBar(true, getStringfromStringId(R.string.processing_request_text))) |
|
|
|
.subscribeOn(Schedulers.io()) |
|
|
|
.observeOn(AndroidSchedulers.mainThread()) |
|
|
|
.subscribe(new ChangePasswordObserver(this.encNewPassword)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void updateCurrentPassword(String encCurrentPassword) { |
|
|
|
this.encCurrentPassword = encCurrentPassword; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void updateNewPassword(String encNewPassword) { |
|
|
|
this.encNewPassword = encNewPassword; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void updateConfirmPassword(String encConfirmPassword) { |
|
|
|
this.encConfirmPassword = encConfirmPassword; |
|
|
|
} |
|
|
|
boolean isConfirmPasswordValid(CharSequence password) { |
|
|
|
if (password != null && password.length() > 0) { |
|
|
|
this.confirmPassword = password.toString(); |
|
|
|
changePasswordLiveData.setConfirmPasswordInputLiveData(new FormInputStateDTO<>(true, null)); |
|
|
|
return true; |
|
|
|
} else { |
|
|
|
this.currentPassword = null; |
|
|
|
changePasswordLiveData.setConfirmPasswordInputLiveData(new FormInputStateDTO<>(false, getStringfromStringId(R.string.password_empty_error))); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
private void encryptPassword(String newPassword, String pwdChangeMessage) { |
|
|
|
SecurityUtils.generateKey() |
|
|
|
.flatMap(key -> Observable.zip( |
|
|
|
SecurityUtils.encryptUsingAES(newPassword, key).subscribeOn(Schedulers.io()), |
|
|
|
encryptToKeyStore(key).subscribeOn(Schedulers.io()), |
|
|
|
Observable.just(pwdChangeMessage), |
|
|
|
FingerprintEncResult::new) |
|
|
|
).observeOn(AndroidSchedulers.mainThread()) |
|
|
|
.subscribe(new FingerprintEncResultObserver()); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private Observable<String> encryptToKeyStore(String data) { |
|
|
|
return SecurityUtils.encryptUsingKeyStore(view.getContext(), data) |
|
|
|
.flatMap(encKey ->Observable.just(encKey.getEncrypted())); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -181,99 +158,59 @@ public class ChangePasswordV2Presenter extends BasePresenter implements ChangePa |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void onSuccess(ChangePasswordActivityV2APIResponse changePasswordActivityV2APIResponse) { |
|
|
|
view.showProgressBar(false,""); |
|
|
|
if (changePasswordActivityV2APIResponse.getErrorCode().equalsIgnoreCase(Constants.SUCCESS_CODE_V2)) { |
|
|
|
if (SecurityUtils.checkFingerPrintUsablity(view.getContext())) { |
|
|
|
encryptPassword(newPassword, changePasswordActivityV2APIResponse.getData().getMessage()); |
|
|
|
} else { |
|
|
|
|
|
|
|
GMEAuthManager gmeAuthManager = GMEAuthManager.getGmeAuthManager((AppCompatActivity) view.getContext()); |
|
|
|
if (gmeAuthManager.isBiometricSupportedByDevice()) |
|
|
|
gmeAuthManager.persistUserCredentialForFingerprintAuth(gateway.getUserID(), this.newPassword) |
|
|
|
.subscribeOn(Schedulers.io()) |
|
|
|
.observeOn(AndroidSchedulers.mainThread()) |
|
|
|
.subscribe(new CompletableObserver() { |
|
|
|
@Override |
|
|
|
public void onSubscribe(Disposable d) { |
|
|
|
useCaseCompositeDisposable.add(d); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onComplete() { |
|
|
|
view.showPopUpMessage(changePasswordActivityV2APIResponse.getMsg(), CustomAlertDialog.AlertType.SUCCESS, alertType -> view.exitView()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onError(Throwable e) { |
|
|
|
view.showPopUpMessage(changePasswordActivityV2APIResponse.getMsg(), CustomAlertDialog.AlertType.SUCCESS, alertType -> view.exitView()); |
|
|
|
} |
|
|
|
}); |
|
|
|
else { |
|
|
|
view.showPopUpMessage(changePasswordActivityV2APIResponse.getMsg(), CustomAlertDialog.AlertType.SUCCESS, alertType -> view.exitView()); |
|
|
|
} |
|
|
|
} else |
|
|
|
view.showPopUpMessage(changePasswordActivityV2APIResponse.getMsg(), CustomAlertDialog.AlertType.FAILED, null); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailed(String message) { |
|
|
|
view.showProgressBar(false,""); |
|
|
|
view.showProgressBar(false, ""); |
|
|
|
view.showPopUpMessage(message, CustomAlertDialog.AlertType.FAILED, null); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void onConnectionNotEstablished(String message) { |
|
|
|
view.showProgressBar(false,""); |
|
|
|
view.showProgressBar(false, ""); |
|
|
|
view.showPopUpMessage(message, CustomAlertDialog.AlertType.NO_INTERNET, null); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void unauthorizedAccess(String message) { |
|
|
|
view.showProgressBar(false,""); |
|
|
|
view.showProgressBar(false, ""); |
|
|
|
gateway.clearAllUserData(); |
|
|
|
view.showPopUpMessage(message, CustomAlertDialog.AlertType.ALERT, alertType -> view.logout()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public class FingerprintEncResult { |
|
|
|
String encPwd; |
|
|
|
String key; |
|
|
|
String pwdChangeServerMessage; |
|
|
|
|
|
|
|
public FingerprintEncResult(String encPwd,String key, String pwdChangeServerMessage) { |
|
|
|
this.encPwd = encPwd; |
|
|
|
this.key=key; |
|
|
|
this.pwdChangeServerMessage = pwdChangeServerMessage; |
|
|
|
} |
|
|
|
|
|
|
|
public String getEncPwd() { |
|
|
|
return encPwd; |
|
|
|
} |
|
|
|
|
|
|
|
public String getPwdChangeServerMessage() { |
|
|
|
return pwdChangeServerMessage; |
|
|
|
} |
|
|
|
|
|
|
|
public String getKey() { |
|
|
|
return key; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String toString() { |
|
|
|
return "UserCredentialEncryptionResultDTO{" + |
|
|
|
"encPwd='" + encPwd + '\'' + |
|
|
|
", key='" + key + '\'' + |
|
|
|
", pwdChangeServerMessage='" + pwdChangeServerMessage + '\'' + |
|
|
|
'}'; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public class FingerprintEncResultObserver extends DisposableObserver<FingerprintEncResult> { |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onNext(FingerprintEncResult fingerprintEncResult) { |
|
|
|
view.showProgressBar(false,""); |
|
|
|
|
|
|
|
if (fingerprintEncResult.getEncPwd() == null) { |
|
|
|
gateway.flushBiometricData(); |
|
|
|
view.showPopUpMessage(fingerprintEncResult.getPwdChangeServerMessage(), CustomAlertDialog.AlertType.SUCCESS, alertType -> view.exitView()); |
|
|
|
} else { |
|
|
|
gateway.persistUserPwdForBiometric(fingerprintEncResult.getEncPwd()); |
|
|
|
gateway.persistSecretKeyForBiometric(fingerprintEncResult.getKey()); |
|
|
|
view.showPopUpMessage(fingerprintEncResult.getPwdChangeServerMessage(), CustomAlertDialog.AlertType.SUCCESS, alertType -> view.exitView()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onError(Throwable e) { |
|
|
|
view.showProgressBar(false,""); |
|
|
|
gateway.flushBiometricData(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onComplete() { |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|