diff --git a/CHANGES.rst b/CHANGES.rst index ae4dae8dbf..b7ca2855c0 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -14,6 +14,7 @@ Features: - Privacy: Remove the bind true flag from 3PID adds in settings (#3254) - Privacy: Remove the ability to set an IS at login/registration (#3264) - Privacy: Allow password reset when no IS (#3261) + - Privacy: Allow email registration when no IS (#3260) Improvements: - diff --git a/vector/src/main/java/im/vector/RegistrationManager.java b/vector/src/main/java/im/vector/RegistrationManager.java index 2962b5b65c..4a00667441 100644 --- a/vector/src/main/java/im/vector/RegistrationManager.java +++ b/vector/src/main/java/im/vector/RegistrationManager.java @@ -870,78 +870,114 @@ private AuthParams getCaptchaAuthParams(final String captchaResponse) { private void requestValidationToken(final Context context, final ThreePid pid, final ThreePidRequestListener listener) { Uri identityServerUri = mHsConfig.getIdentityServerUri(); if (identityServerUri == null) { - listener.onIdentityServerMissing(); - } else { - if (getThirdPidRestClient() != null) { - switch (pid.medium) { - case ThreePid.MEDIUM_EMAIL: - String nextLink = NEXTLINK_BASE_URL + "/#/register?client_secret=" + pid.clientSecret; - nextLink += "&hs_url=" + mHsConfig.getHomeserverUri().toString(); - nextLink += "&is_url=" + identityServerUri.toString(); - nextLink += "&session_id=" + mRegistrationResponse.session; - pid.requestEmailValidationToken(getProfileRestClient(), nextLink, true, new ApiCallback() { - @Override - public void onSuccess(Void aVoid) { - listener.onThreePidRequested(pid); - } + // Check if identity server is required + new LoginRestClient(mHsConfig) + .doesServerRequireIdentityServerParam(new ApiCallback() { + @Override + public void onNetworkError(Exception e) { + listener.onThreePidRequestFailed(e.getLocalizedMessage()); + } - @Override - public void onNetworkError(final Exception e) { - warnAfterCertificateError(context, e, pid, listener); - } + @Override + public void onMatrixError(MatrixError e) { + listener.onThreePidRequestFailed(e.getLocalizedMessage()); + } + + @Override + public void onUnexpectedError(Exception e) { + listener.onThreePidRequestFailed(e.getLocalizedMessage()); + } - @Override - public void onUnexpectedError(Exception e) { - String errorMessage = build3PidErrorMessage(context, R.string.account_email_error, e.getLocalizedMessage()); - listener.onThreePidRequestFailed(errorMessage); + @Override + public void onSuccess(Boolean info) { + if (info) { + listener.onIdentityServerMissing(); + } else { + // Ok, not mandatory + doRequestValidationToken(context, pid, null, listener); } + } + }); + } else { + doRequestValidationToken(context, pid, identityServerUri.toString(), listener); + } + } - @Override - public void onMatrixError(MatrixError e) { - String errorMessage = null; - if (TextUtils.equals(MatrixError.THREEPID_IN_USE, e.errcode)) { - errorMessage = build3PidErrorMessage(context, R.string.account_email_already_used_error, null); - } else { - errorMessage = build3PidErrorMessage(context, R.string.account_email_error, e.getLocalizedMessage()); - } + private void doRequestValidationToken(final Context context, + final ThreePid pid, + final @Nullable String isUrl, + final ThreePidRequestListener listener) { + if (getThirdPidRestClient() != null) { + switch (pid.medium) { + case ThreePid.MEDIUM_EMAIL: + String nextLink = NEXTLINK_BASE_URL + "/#/register?client_secret=" + pid.clientSecret; + nextLink += "&hs_url=" + mHsConfig.getHomeserverUri().toString(); + if (isUrl != null) { + nextLink += "&is_url=" + isUrl; + } + nextLink += "&session_id=" + mRegistrationResponse.session; + pid.requestEmailValidationToken(getProfileRestClient(), nextLink, true, new ApiCallback() { + @Override + public void onSuccess(Void aVoid) { + listener.onThreePidRequested(pid); + } - listener.onThreePidRequestFailed(errorMessage); - } - }); - break; - case ThreePid.MEDIUM_MSISDN: - pid.requestPhoneNumberValidationToken(getProfileRestClient(), true, new ApiCallback() { - @Override - public void onSuccess(Void aVoid) { - mPhoneNumber = pid; - listener.onThreePidRequested(pid); - } + @Override + public void onNetworkError(final Exception e) { + warnAfterCertificateError(context, e, pid, listener); + } - @Override - public void onNetworkError(final Exception e) { - warnAfterCertificateError(context, e, pid, listener); - } + @Override + public void onUnexpectedError(Exception e) { + String errorMessage = build3PidErrorMessage(context, R.string.account_email_error, e.getLocalizedMessage()); + listener.onThreePidRequestFailed(errorMessage); + } - @Override - public void onUnexpectedError(Exception e) { - String errorMessage = build3PidErrorMessage(context, R.string.account_phone_number_error, e.getLocalizedMessage()); - listener.onThreePidRequestFailed(errorMessage); + @Override + public void onMatrixError(MatrixError e) { + String errorMessage = null; + if (TextUtils.equals(MatrixError.THREEPID_IN_USE, e.errcode)) { + errorMessage = build3PidErrorMessage(context, R.string.account_email_already_used_error, null); + } else { + errorMessage = build3PidErrorMessage(context, R.string.account_email_error, e.getLocalizedMessage()); } - @Override - public void onMatrixError(MatrixError e) { - String errorMessage = null; - if (TextUtils.equals(MatrixError.THREEPID_IN_USE, e.errcode)) { - errorMessage = build3PidErrorMessage(context, R.string.account_phone_number_already_used_error, null); - } else { - errorMessage = build3PidErrorMessage(context, R.string.account_phone_number_error, e.mReason); - } + listener.onThreePidRequestFailed(errorMessage); + } + }); + break; + case ThreePid.MEDIUM_MSISDN: + pid.requestPhoneNumberValidationToken(getProfileRestClient(), true, new ApiCallback() { + @Override + public void onSuccess(Void aVoid) { + mPhoneNumber = pid; + listener.onThreePidRequested(pid); + } + + @Override + public void onNetworkError(final Exception e) { + warnAfterCertificateError(context, e, pid, listener); + } - listener.onThreePidRequestFailed(errorMessage); + @Override + public void onUnexpectedError(Exception e) { + String errorMessage = build3PidErrorMessage(context, R.string.account_phone_number_error, e.getLocalizedMessage()); + listener.onThreePidRequestFailed(errorMessage); + } + + @Override + public void onMatrixError(MatrixError e) { + String errorMessage = null; + if (TextUtils.equals(MatrixError.THREEPID_IN_USE, e.errcode)) { + errorMessage = build3PidErrorMessage(context, R.string.account_phone_number_already_used_error, null); + } else { + errorMessage = build3PidErrorMessage(context, R.string.account_phone_number_error, e.mReason); } - }); - break; - } + + listener.onThreePidRequestFailed(errorMessage); + } + }); + break; } } } @@ -1094,63 +1130,63 @@ public void saveInstanceState(Bundle savedInstanceState) { } } - /* - * ********************************************************************************************* - * Private listeners - * ********************************************************************************************* - */ +/* + * ********************************************************************************************* + * Private listeners + * ********************************************************************************************* + */ - private interface InternalRegistrationListener { - void onRegistrationSuccess(); +private interface InternalRegistrationListener { + void onRegistrationSuccess(); - void onRegistrationFailed(String message); + void onRegistrationFailed(String message); - void onResourceLimitExceeded(MatrixError e); - } + void onResourceLimitExceeded(MatrixError e); +} - /* - * ********************************************************************************************* - * Public listeners - * ********************************************************************************************* - */ +/* + * ********************************************************************************************* + * Public listeners + * ********************************************************************************************* + */ - public interface ThreePidRequestListener { - void onIdentityServerMissing(); +public interface ThreePidRequestListener { + void onIdentityServerMissing(); - void onThreePidRequested(ThreePid pid); + void onThreePidRequested(ThreePid pid); - void onThreePidRequestFailed(String errorMessage); - } + void onThreePidRequestFailed(String errorMessage); +} - public interface ThreePidValidationListener { - void onThreePidValidated(boolean isSuccess); - } +public interface ThreePidValidationListener { + void onThreePidValidated(boolean isSuccess); +} - public interface UsernameValidityListener { - void onUsernameAvailabilityChecked(boolean isAvailable); - } +public interface UsernameValidityListener { + void onUsernameAvailabilityChecked(boolean isAvailable); +} - public interface RegistrationListener { - void onRegistrationSuccess(String warningMessage); +public interface RegistrationListener { + void onRegistrationSuccess(String warningMessage); - void onRegistrationFailed(String message); + void onRegistrationFailed(String message); - void onWaitingEmailValidation(); + void onWaitingEmailValidation(); - void onIdentityServerMissing(); + void onIdentityServerMissing(); - /** - * @param publicKey the Captcha public key - */ - void onWaitingCaptcha(String publicKey); + /** + * @param publicKey the Captcha public key + */ + void onWaitingCaptcha(String publicKey); - /** - * @param localizedFlowDataLoginTerms list of LocalizedFlowDataLoginTerms the user has to accept - */ - void onWaitingTerms(List localizedFlowDataLoginTerms); + /** + * @param localizedFlowDataLoginTerms list of LocalizedFlowDataLoginTerms the user has to accept + */ + void onWaitingTerms(List localizedFlowDataLoginTerms); - void onThreePidRequestFailed(String message); + void onThreePidRequestFailed(String message); - void onResourceLimitExceeded(MatrixError e); - } + void onResourceLimitExceeded(MatrixError e); +} } diff --git a/vector/src/main/java/im/vector/activity/LoginActivity.java b/vector/src/main/java/im/vector/activity/LoginActivity.java index 6085a6ce2f..809a3b76fe 100644 --- a/vector/src/main/java/im/vector/activity/LoginActivity.java +++ b/vector/src/main/java/im/vector/activity/LoginActivity.java @@ -2842,6 +2842,10 @@ public void run() { @Override public void onIdentityServerMissing() { + Log.d(LOG_TAG, "## onIdentityServerMissing()"); + enableLoadingScreen(false); + showMainLayout(); + refreshDisplay(); Toast.makeText(this, R.string.identity_server_not_defined, Toast.LENGTH_SHORT).show(); }