Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
Privacy: Allow email registration when no IS (#3260)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarty authored and BillCarsonFr committed Sep 24, 2019
1 parent 416c613 commit d0d93e5
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 103 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
-
Expand Down
242 changes: 139 additions & 103 deletions vector/src/main/java/im/vector/RegistrationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Void>() {
@Override
public void onSuccess(Void aVoid) {
listener.onThreePidRequested(pid);
}
// Check if identity server is required
new LoginRestClient(mHsConfig)
.doesServerRequireIdentityServerParam(new ApiCallback<Boolean>() {
@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<Void>() {
@Override
public void onSuccess(Void aVoid) {
listener.onThreePidRequested(pid);
}

listener.onThreePidRequestFailed(errorMessage);
}
});
break;
case ThreePid.MEDIUM_MSISDN:
pid.requestPhoneNumberValidationToken(getProfileRestClient(), true, new ApiCallback<Void>() {
@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<Void>() {
@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;
}
}
}
Expand Down Expand Up @@ -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> localizedFlowDataLoginTerms);
/**
* @param localizedFlowDataLoginTerms list of LocalizedFlowDataLoginTerms the user has to accept
*/
void onWaitingTerms(List<LocalizedFlowDataLoginTerms> localizedFlowDataLoginTerms);

void onThreePidRequestFailed(String message);
void onThreePidRequestFailed(String message);

void onResourceLimitExceeded(MatrixError e);
}
void onResourceLimitExceeded(MatrixError e);
}
}
4 changes: 4 additions & 0 deletions vector/src/main/java/im/vector/activity/LoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down

0 comments on commit d0d93e5

Please sign in to comment.