Merge branch 'privacy' into riot_2659

This commit is contained in:
manuroe 2019-09-04 09:40:27 +02:00 committed by GitHub
commit be6dd988bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 129 additions and 90 deletions

View file

@ -17,6 +17,7 @@ Improvements:
* Privacy: Use the hashed v2 lookup API for 3PIDs (#2652).
* Privacy: Prompt to accept identity server policies on firt use (#2602).
* Privacy: Settings: Allow adding 3pids when no IS (#2659).
* Privacy: Allow password reset when no IS (#2658).
Changes in 0.9.2 (2019-08-08)
===============================================

View file

@ -113,6 +113,7 @@
"auth_reset_password_next_step_button" = "I have verified my email address";
"auth_reset_password_error_unauthorized" = "Failed to verify email address: make sure you clicked the link in the email";
"auth_reset_password_error_not_found" = "Your email address does not appear to be associated with a Matrix ID on this homeserver.";
"auth_reset_password_error_is_required" = "No identity server is configured: add one in server options to reset your password.";
"auth_reset_password_success_message" = "Your password has been reset.\n\nYou have been logged out of all devices and will no longer receive push notifications. To re-enable notifications, re-log in on each device.";
"auth_add_email_and_phone_warning" = "Registration with email and phone number at once is not supported yet until the api exists. Only the phone number will be taken into account. You may add your email to your profile in settings.";
"auth_accept_policies" = "Please review and accept the policies of this homeserver:";

View file

@ -194,6 +194,10 @@ internal enum VectorL10n {
internal static func authResetPasswordEmailValidationMessage(_ p1: String) -> String {
return VectorL10n.tr("Vector", "auth_reset_password_email_validation_message", p1)
}
/// No identity server is configured: add one in server options to reset your password.
internal static var authResetPasswordErrorIsRequired: String {
return VectorL10n.tr("Vector", "auth_reset_password_error_is_required")
}
/// Your email address does not appear to be associated with a Matrix ID on this homeserver.
internal static var authResetPasswordErrorNotFound: String {
return VectorL10n.tr("Vector", "auth_reset_password_error_not_found")

View file

@ -237,98 +237,108 @@
if (restClient)
{
// Launch email validation
NSString *clientSecret = [MXTools generateSecret];
[self checkIdentityServerRequirement:restClient success:^{
__weak typeof(self) weakSelf = self;
[restClient forgetPasswordForEmail:self.emailTextField.text
clientSecret:clientSecret
sendAttempt:1
success:^(NSString *sid)
{
typeof(weakSelf) strongSelf = weakSelf;
if (strongSelf) {
strongSelf.didPrepareParametersCallback = callback;
// Launch email validation
NSString *clientSecret = [MXTools generateSecret];
NSURL *identServerURL = [NSURL URLWithString:restClient.identityServer];
strongSelf.parameters = @{
@"auth": @{
@"threepid_creds": @{
@"client_secret": clientSecret,
@"id_server": identServerURL.host,
@"sid": sid
},
@"type": kMXLoginFlowTypeEmailIdentity
},
@"new_password": strongSelf.passWordTextField.text
};
[strongSelf hideInputsContainer];
strongSelf.messageLabel.text = [NSString stringWithFormat:NSLocalizedStringFromTable(@"auth_reset_password_email_validation_message", @"Vector", nil), strongSelf.emailTextField.text];
strongSelf.messageLabel.hidden = NO;
[strongSelf.nextStepButton addTarget:strongSelf
action:@selector(didCheckEmail:)
forControlEvents:UIControlEventTouchUpInside];
strongSelf.nextStepButton.hidden = NO;
}
}
failure:^(NSError *error)
{
NSLog(@"[ForgotPasswordInputsView] Failed to request email token");
// Ignore connection cancellation error
if (([error.domain isEqualToString:NSURLErrorDomain] && error.code == NSURLErrorCancelled))
__weak typeof(self) weakSelf = self;
[restClient forgetPasswordForEmail:self.emailTextField.text
clientSecret:clientSecret
sendAttempt:1
success:^(NSString *sid)
{
return;
typeof(weakSelf) strongSelf = weakSelf;
if (strongSelf) {
strongSelf.didPrepareParametersCallback = callback;
NSMutableDictionary *threepidCreds = [NSMutableDictionary dictionaryWithDictionary:@{
@"client_secret": clientSecret,
@"sid": sid
}];
if (restClient.identityServer)
{
NSURL *identServerURL = [NSURL URLWithString:restClient.identityServer];
threepidCreds[@"id_server"] = identServerURL.host;
}
strongSelf.parameters = @{
@"auth": @{
@"threepid_creds": threepidCreds,
@"type": kMXLoginFlowTypeEmailIdentity
},
@"new_password": strongSelf.passWordTextField.text
};
[strongSelf hideInputsContainer];
strongSelf.messageLabel.text = [NSString stringWithFormat:NSLocalizedStringFromTable(@"auth_reset_password_email_validation_message", @"Vector", nil), strongSelf.emailTextField.text];
strongSelf.messageLabel.hidden = NO;
[strongSelf.nextStepButton addTarget:strongSelf
action:@selector(didCheckEmail:)
forControlEvents:UIControlEventTouchUpInside];
strongSelf.nextStepButton.hidden = NO;
}
}
NSString *errorMessage;
// Translate the potential MX error.
MXError *mxError = [[MXError alloc] initWithNSError:error];
if (mxError && [mxError.errcode isEqualToString:kMXErrCodeStringThreePIDNotFound])
errorMessage = NSLocalizedStringFromTable(@"auth_email_not_found", @"Vector", nil);
else if (mxError && [mxError.errcode isEqualToString:kMXErrCodeStringServerNotTrusted])
errorMessage = NSLocalizedStringFromTable(@"auth_untrusted_id_server", @"Vector", nil);
else if (error.userInfo[@"error"])
errorMessage = error.userInfo[@"error"];
else
errorMessage = error.localizedDescription;
if (weakSelf)
failure:^(NSError *error)
{
typeof(self) self = weakSelf;
NSLog(@"[ForgotPasswordInputsView] Failed to request email token");
if (self->inputsAlert)
// Ignore connection cancellation error
if (([error.domain isEqualToString:NSURLErrorDomain] && error.code == NSURLErrorCancelled))
{
[self->inputsAlert dismissViewControllerAnimated:NO completion:nil];
return;
}
self->inputsAlert = [UIAlertController alertControllerWithTitle:[NSBundle mxk_localizedStringForKey:@"error"] message:errorMessage preferredStyle:UIAlertControllerStyleAlert];
NSString *errorMessage;
[self->inputsAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"ok"]
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
// Translate the potential MX error.
MXError *mxError = [[MXError alloc] initWithNSError:error];
if (mxError && [mxError.errcode isEqualToString:kMXErrCodeStringThreePIDNotFound])
errorMessage = NSLocalizedStringFromTable(@"auth_email_not_found", @"Vector", nil);
else if (mxError && [mxError.errcode isEqualToString:kMXErrCodeStringServerNotTrusted])
errorMessage = NSLocalizedStringFromTable(@"auth_untrusted_id_server", @"Vector", nil);
else if (error.userInfo[@"error"])
errorMessage = error.userInfo[@"error"];
else
errorMessage = error.localizedDescription;
if (weakSelf)
{
typeof(self) self = weakSelf;
self->inputsAlert = nil;
if (self.delegate && [self.delegate respondsToSelector:@selector(authInputsViewDidCancelOperation:)])
if (weakSelf)
{
typeof(self) self = weakSelf;
if (self->inputsAlert)
{
[self->inputsAlert dismissViewControllerAnimated:NO completion:nil];
}
self->inputsAlert = [UIAlertController alertControllerWithTitle:[NSBundle mxk_localizedStringForKey:@"error"] message:errorMessage preferredStyle:UIAlertControllerStyleAlert];
[self->inputsAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"ok"]
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
if (weakSelf)
{
[self.delegate authInputsViewDidCancelOperation:self];
typeof(self) self = weakSelf;
self->inputsAlert = nil;
if (self.delegate && [self.delegate respondsToSelector:@selector(authInputsViewDidCancelOperation:)])
{
[self.delegate authInputsViewDidCancelOperation:self];
}
}
}
}]];
}]];
[self.delegate authInputsView:self presentAlertController:self->inputsAlert];
}
}];
[self.delegate authInputsView:self presentAlertController:self->inputsAlert];
}
}];
} failure:^(NSError *error) {
callback(nil, error);
}];
// Async response
return;
@ -400,6 +410,29 @@
[self layoutIfNeeded];
}
- (void)checkIdentityServerRequirement:(MXRestClient*)mxRestClient success:(void (^)(void))success failure:(void (^)(NSError *))failure
{
[mxRestClient supportedMatrixVersions:^(MXMatrixVersions *matrixVersions) {
NSLog(@"[ForgotPasswordInputsView] checkIdentityServerRequirement: %@", matrixVersions.doesServerRequireIdentityServerParam ? @"YES": @"NO");
if (matrixVersions.doesServerRequireIdentityServerParam
&& !mxRestClient.credentials.identityServer)
{
failure([NSError errorWithDomain:MXKAuthErrorDomain
code:0
userInfo:@{
NSLocalizedDescriptionKey:[NSBundle mxk_localizedStringForKey:@"auth_reset_password_error_is_required"]
}]);
}
else
{
success();
}
} failure:failure];
}
#pragma mark - actions
- (void)didCheckEmail:(id)sender