Commit 1f70f720 authored by Anthony Léonard's avatar Anthony Léonard Committed by Kateryna Kostiuk

account: add password change modal in settings

A button is added in the Ring account setting panel which trigger a
sliding modal enabling a user to change the password used to encrypt
the master key archive (its Ring “account”).

To prevent mistakes, the old password is not required if we know that
there isn't any. The new password is also asked twice for confirmation.

Change-Id: Ibbc0a87f1d108b7fdb66382e8f8f491461eeaccf
Reviewed-by: Kateryna Kostiuk's avatarKateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
parent 7f56bdeb
......@@ -170,6 +170,8 @@ SET(ringclient_CONTROLLERS
src/AccBannedContactsVC.mm
src/MessagesVC.h
src/MessagesVC.mm
src/PasswordChangeWC.h
src/PasswordChangeWC.mm
)
SET(ringclient_BACKENDS
......@@ -262,6 +264,7 @@ SET(ringclient_XIBS
ContactRequestList
ContactRequest
AccBannedContacts
PasswordChange
)
# Icons
......
......@@ -22,6 +22,7 @@
#import <qitemselectionmodel.h>
#import "RegisterNameWC.h"
#import "PasswordChangeWC.h"
@interface AccRingVC () <RegisterNameDelegate>
......@@ -41,6 +42,7 @@
@property (unsafe_unretained) IBOutlet NSButton *allowContacts;
@property AbstractLoadingWC* accountModal;
@property PasswordChangeWC* passwordModal;
@end
......@@ -133,6 +135,21 @@ typedef NS_ENUM(NSInteger, TagViews) {
self.accountModal = registerWC;
}
- (IBAction)changePassword:(id)sender
{
auto passwordWC = [[PasswordChangeWC alloc] initWithAccount:AccountModel::instance().selectedAccount()];
#if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_9
[self.view.window beginSheet:passwordWC.window completionHandler:nil];
#else
[NSApp beginSheet: passwordWC.window
modalForWindow: self.view.window
modalDelegate: self
didEndSelector: nil
contextInfo: nil];
#endif
self.passwordModal = passwordWC;
}
- (IBAction)toggleUpnp:(NSButton *)sender {
AccountModel::instance().selectedAccount()->setUpnpEnabled([sender state] == NSOnState);
}
......
/*
* Copyright (C) 2017 Savoir-faire Linux Inc.
* Author: Anthony Léonard <anthony.leonard@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#import <Cocoa/Cocoa.h>
#import <account.h>
@interface PasswordChangeWC : NSWindowController <NSTextFieldDelegate>
-(id)initWithAccount:(Account*)acc;
@end
/*
* Copyright (C) 2017 Savoir-faire Linux Inc.
* Author: Anthony Léonard <anthony.leonard@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#import "PasswordChangeWC.h"
#import <accountmodel.h>
@implementation PasswordChangeWC
{
Account* account;
__unsafe_unretained IBOutlet NSSecureTextField *oldPassword;
__unsafe_unretained IBOutlet NSSecureTextField *newPassword;
__unsafe_unretained IBOutlet NSSecureTextField *repeatedPassword;
__unsafe_unretained IBOutlet NSImageView *repeatPasswordValid;
__unsafe_unretained IBOutlet NSButton *acceptButton;
IBOutlet NSPopover *wrongPasswordPopover;
}
-(id)initWithAccount:(Account*)acc
{
account = acc;
return [super initWithWindowNibName:@"PasswordChange"];
}
-(void)windowDidLoad
{
[super windowDidLoad];
if (account != nullptr) {
const auto hasPassword = account->archiveHasPassword();
[oldPassword setEnabled:hasPassword];
[oldPassword setPlaceholderString:(hasPassword)?@"":NSLocalizedString(@"Account has no password", @"No password on this account text field placeholder")];
}
}
-(IBAction)accept:(id)sender
{
if (account->changePassword(QString::fromNSString([oldPassword stringValue]), QString::fromNSString([newPassword stringValue])))
{
AccountModel::instance().save();
[self close];
} else {
[oldPassword setStringValue:@""];
[wrongPasswordPopover showRelativeToRect:oldPassword.visibleRect ofView:oldPassword preferredEdge:NSMinYEdge];
}
}
-(IBAction)cancel:(id)sender
{
[self close];
}
#pragma mark - NSTextFieldDelegate methods
-(void)controlTextDidChange:(NSNotification *)obj
{
if ([[newPassword stringValue] isEqualToString: [repeatedPassword stringValue]]) {
[repeatPasswordValid setHidden:NO];
[acceptButton setEnabled:YES];
} else {
[repeatPasswordValid setHidden:YES];
[acceptButton setEnabled:NO];
}
}
@end
This diff is collapsed.
......@@ -160,4 +160,5 @@
/* Contextual menu alert remove contact {Name} */
"Are you sure you want to delete contact \"%@\"" = "Are you sure you want to delete contact \"%@\"";
/* No password on this account text field placeholder */
"Account has no password" = "Account has no password";
/* Class = "NSTextFieldCell"; title = "Repeat"; ObjectID = "8KO-IO-ykP"; */
"8KO-IO-ykP.title" = "Repeat";
/* Class = "NSButtonCell"; title = "Accept"; ObjectID = "Ggu-EQ-cqC"; */
"Ggu-EQ-cqC.title" = "Accept";
/* Class = "NSButtonCell"; title = "Cancel"; ObjectID = "MZw-ep-8aW"; */
"MZw-ep-8aW.title" = "Cancel";
/* Class = "NSTextFieldCell"; title = "Password is incorrect"; ObjectID = "WyU-Dx-U1u"; */
"WyU-Dx-U1u.title" = "Password is incorrect";
/* Class = "NSTextFieldCell"; title = "Enter your old password"; ObjectID = "gPw-Jf-0M7"; */
"gPw-Jf-0M7.title" = "Enter your old password";
/* Class = "NSTextFieldCell"; title = "Chose a new password"; ObjectID = "pZe-DO-jWp"; */
"pZe-DO-jWp.title" = "Chose a new password";
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment