Privacy: Settings: Allow adding 3pids when no IS

#2659

And display an error if an IS is required
This commit is contained in:
manuroe 2019-09-03 16:35:18 +02:00
parent 1e39cc6dd9
commit 3d8f9f606c
4 changed files with 150 additions and 102 deletions

View file

@ -16,6 +16,7 @@ Improvements:
* Privacy: Support identity server v2 API authentication (#2603).
* 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).
Changes in 0.9.2 (2019-08-08)
===============================================

View file

@ -92,6 +92,8 @@
"auth_missing_email_or_phone" = "Missing email address or phone number";
"auth_email_in_use" = "This email address is already in use";
"auth_phone_in_use" = "This phone number is already in use";
"auth_email_is_required" = "No identity server is configured so you cannot add an email address in order to reset your password in the future.";
"auth_phone_is_required" = "No identity server is configured so you cannot add a phone number in order to reset your password in the future.";
"auth_untrusted_id_server" = "The identity server is not trusted";
"auth_password_dont_match" = "Passwords don't match";
"auth_username_in_use" = "Username in use";

View file

@ -54,6 +54,10 @@ internal enum VectorL10n {
internal static var authEmailInUse: String {
return VectorL10n.tr("Vector", "auth_email_in_use")
}
/// No identity server is configured so you cannot add an email address in order to reset your password in the future.
internal static var authEmailIsRequired: String {
return VectorL10n.tr("Vector", "auth_email_is_required")
}
/// Failed to send email: This email address was not found
internal static var authEmailNotFound: String {
return VectorL10n.tr("Vector", "auth_email_not_found")
@ -162,6 +166,10 @@ internal enum VectorL10n {
internal static var authPhoneInUse: String {
return VectorL10n.tr("Vector", "auth_phone_in_use")
}
/// No identity server is configured so you cannot add a phone number in order to reset your password in the future.
internal static var authPhoneIsRequired: String {
return VectorL10n.tr("Vector", "auth_phone_is_required")
}
/// Phone number
internal static var authPhonePlaceholder: String {
return VectorL10n.tr("Vector", "auth_phone_placeholder")

View file

@ -1242,8 +1242,6 @@ SingleImagePickerPresenterDelegate>
userSettingsNightModeSepIndex = -1;
userSettingsNightModeIndex = -1;
if (self.mainSession.matrixRestClient.identityServer.length)
{
userSettingsEmailStartIndex = 3;
userSettingsNewEmailIndex = userSettingsEmailStartIndex + account.linkedEmails.count;
userSettingsPhoneStartIndex = userSettingsNewEmailIndex + 1;
@ -1251,16 +1249,6 @@ SingleImagePickerPresenterDelegate>
count = userSettingsNewPhoneIndex + 1;
}
else
{
userSettingsEmailStartIndex = -1;
userSettingsNewEmailIndex = -1;
userSettingsPhoneStartIndex = -1;
userSettingsNewPhoneIndex = -1;
count = userSettingsChangePasswordIndex + 1;
}
}
else if (section == SETTINGS_SECTION_NOTIFICATIONS_SETTINGS_INDEX)
{
count = NOTIFICATION_SETTINGS_COUNT;
@ -3613,6 +3601,8 @@ SingleImagePickerPresenterDelegate>
MXSession* session = [AppDelegate theDelegate].mxSessions[0];
[self checkIdentityServerRequirement:session.matrixRestClient forMedium:kMX3PIDMediumEmail success:^{
MXK3PID *new3PID = [[MXK3PID alloc] initWithMedium:kMX3PIDMediumEmail andAddress:newEmailTextField.text];
[new3PID requestValidationTokenWithMatrixRestClient:session.matrixRestClient isDuringRegistration:NO nextLink:nil success:^{
@ -3659,6 +3649,12 @@ SingleImagePickerPresenterDelegate>
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKErrorNotification object:error userInfo:myUserId ? @{kMXKErrorUserIdKey: myUserId} : nil];
}];
} failure:^(NSError *error) {
// Notify user
NSString *myUserId = session.myUser.userId; // TODO: Hanlde multi-account
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKErrorNotification object:error userInfo:myUserId ? @{kMXKErrorUserIdKey: myUserId} : nil];
}];
}
- (IBAction)onAddNewPhone:(id)sender
@ -3715,6 +3711,8 @@ SingleImagePickerPresenterDelegate>
msisdn = [e164 substringFromIndex:2];
}
[self checkIdentityServerRequirement:session.matrixRestClient forMedium:kMX3PIDMediumMSISDN success:^{
MXK3PID *new3PID = [[MXK3PID alloc] initWithMedium:kMX3PIDMediumMSISDN andAddress:msisdn];
[new3PID requestValidationTokenWithMatrixRestClient:session.matrixRestClient isDuringRegistration:NO nextLink:nil success:^{
@ -3762,6 +3760,45 @@ SingleImagePickerPresenterDelegate>
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKErrorNotification object:error userInfo:myUserId ? @{kMXKErrorUserIdKey: myUserId} : nil];
}];
} failure:^(NSError *error) {
// Notify user
NSString *myUserId = session.myUser.userId; // TODO: Hanlde multi-account
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKErrorNotification object:error userInfo:myUserId ? @{kMXKErrorUserIdKey: myUserId} : nil];
}];
}
- (void)checkIdentityServerRequirement:(MXRestClient*)mxRestClient forMedium:(NSString*)medium success:(void (^)(void))success failure:(void (^)(NSError *))failure
{
[mxRestClient supportedMatrixVersions:^(MXMatrixVersions *matrixVersions) {
NSLog(@"[SettingsViewController] checkIdentityServerRequirement: %@", matrixVersions.doesServerRequireIdentityServerParam ? @"YES": @"NO");
if (matrixVersions.doesServerRequireIdentityServerParam
&& !mxRestClient.credentials.identityServer)
{
NSString *message;
if ([medium isEqualToString:kMX3PIDMediumMSISDN])
{
message = [NSBundle mxk_localizedStringForKey:@"auth_phone_is_required"];
}
else
{
[NSBundle mxk_localizedStringForKey:@"auth_email_is_required"];
}
failure([NSError errorWithDomain:MXKAuthErrorDomain
code:0
userInfo:@{
NSLocalizedDescriptionKey:message
}]);
}
else
{
success();
}
} failure:failure];
}
- (void)updateSaveButtonStatus