Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sign out from all devices option when changing password #6262

Merged
merged 13 commits into from
Jun 13, 2022
10 changes: 10 additions & 0 deletions Riot/Assets/en.lproj/Untranslated.strings
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,13 @@
"leave_space_selection_title" = "SELECT ROOMS";
"leave_space_selection_all_rooms" = "Select all rooms";
"leave_space_selection_no_rooms" = "Select no rooms";

// MARK: Password Validation
"password_validation_info_header" = "Your password should meet the criteria below:";
"password_validation_error_header" = "Given password does not meet the criteria below:";
"password_validation_error_min_length" = "At least %d characters.";
"password_validation_error_max_length" = "Not exceed %d characters.";
"password_validation_error_contain_lowercase_letter" = "Contain a lower-case letter.";
"password_validation_error_contain_uppercase_letter" = "Contain an upper-case letter.";
"password_validation_error_contain_number" = "Contain a number.";
"password_validation_error_contain_symbol" = "Contain a symbol.";
9 changes: 9 additions & 0 deletions Riot/Categories/MXRestClient+Async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ extension MXRestClient {
resetPassword(parameters: parameters, completion: completion)
}
}

// MARK: - Change Password

/// An async version of `changePassword(from:to:logoutDevices:completion:)`.
func changePassword(from oldPassword: String, to newPassword: String, logoutDevices: Bool) async throws {
try await getResponse { completion in
changePassword(from: oldPassword, to: newPassword, logoutDevices: logoutDevices, completion: completion)
}
}

// MARK: - Private

Expand Down
32 changes: 32 additions & 0 deletions Riot/Generated/UntranslatedStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,38 @@ public extension VectorL10n {
static var leaveSpaceSelectionTitle: String {
return VectorL10n.tr("Untranslated", "leave_space_selection_title")
}
/// Contain a lower-case letter.
static var passwordValidationErrorContainLowercaseLetter: String {
return VectorL10n.tr("Untranslated", "password_validation_error_contain_lowercase_letter")
}
/// Contain a number.
static var passwordValidationErrorContainNumber: String {
return VectorL10n.tr("Untranslated", "password_validation_error_contain_number")
}
/// Contain a symbol.
static var passwordValidationErrorContainSymbol: String {
return VectorL10n.tr("Untranslated", "password_validation_error_contain_symbol")
}
/// Contain an upper-case letter.
static var passwordValidationErrorContainUppercaseLetter: String {
return VectorL10n.tr("Untranslated", "password_validation_error_contain_uppercase_letter")
}
/// Given password does not meet the criteria below:
static var passwordValidationErrorHeader: String {
return VectorL10n.tr("Untranslated", "password_validation_error_header")
}
/// Not exceed %d characters.
static func passwordValidationErrorMaxLength(_ p1: Int) -> String {
return VectorL10n.tr("Untranslated", "password_validation_error_max_length", p1)
}
/// At least %d characters.
static func passwordValidationErrorMinLength(_ p1: Int) -> String {
return VectorL10n.tr("Untranslated", "password_validation_error_min_length", p1)
}
/// Your password should meet the criteria below:
static var passwordValidationInfoHeader: String {
return VectorL10n.tr("Untranslated", "password_validation_info_header")
}
/// This feature isn't available here. For now, you can do this with %@ on your computer.
static func spacesFeatureNotAvailable(_ p1: String) -> String {
return VectorL10n.tr("Untranslated", "spaces_feature_not_available", p1)
Expand Down
8 changes: 6 additions & 2 deletions Riot/Modules/MatrixKit/Models/Account/MXKAccount.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,15 @@ typedef BOOL (^MXKAccountOnCertificateChange)(MXKAccount *mxAccount, NSData *cer

@param oldPassword the old password.
@param newPassword the new password.

@param logoutDevices flag to logout from all devices.
@param success A block object called when the operation succeeds.
@param failure A block object called when the operation fails.
*/
- (void)changePassword:(NSString*)oldPassword with:(NSString*)newPassword success:(void (^)(void))success failure:(void (^)(NSError *error))failure;
- (void)changePassword:(NSString*)oldPassword
with:(NSString*)newPassword
logoutDevices:(BOOL)logoutDevices
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure;

/**
Load the 3PIDs linked to this account.
Expand Down
3 changes: 2 additions & 1 deletion Riot/Modules/MatrixKit/Models/Account/MXKAccount.m
Original file line number Diff line number Diff line change
Expand Up @@ -582,12 +582,13 @@ - (void)setUserAvatarUrl:(NSString*)avatarUrl success:(void (^)(void))success fa
}
}

- (void)changePassword:(NSString*)oldPassword with:(NSString*)newPassword success:(void (^)(void))success failure:(void (^)(NSError *error))failure
- (void)changePassword:(NSString*)oldPassword with:(NSString*)newPassword logoutDevices:(BOOL)logoutDevices success:(void (^)(void))success failure:(void (^)(NSError *error))failure
{
if (mxSession)
{
[mxRestClient changePassword:oldPassword
with:newPassword
logoutDevices:logoutDevices
success:^{

if (success) {
Expand Down
Loading