Commit 624b1a8e authored by Alexandre Lision's avatar Alexandre Lision Committed by Alexandre Lision

multi-device: add account migration

Prompt user to add a password for each of his Ring accounts in order to
use the new multi-device system.

Change-Id: I7a75b04330eabc3d229f8fd613cad69ed8d66eb5
Tuleap: #960
parent 45f1f548
......@@ -144,6 +144,8 @@ SET(ringclient_CONTROLLERS
src/AccDevicesVC.h
src/ExportPasswordWC.mm
src/ExportPasswordWC.h
src/MigrateRingAccountsWC.mm
src/MigrateRingAccountsWC.h
)
SET(ringclient_BACKENDS
......@@ -201,6 +203,7 @@ SET(ringclient_XIBS
CertificateWindow
PathPasswordWindow
ExportPasswordWindow
MigrateRingAccountsWindow
PersonLinker
Broker
Conversation
......
/*
* Copyright (C) 2015-2016 Savoir-faire Linux Inc.
* Author: Loïc Siret <loic.siret@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 <Foundation/Foundation.h>
#import "LoadingWCDelegate.h"
@protocol LoadingWCProtocol <NSObject>
- (id)initWithDelegate:(id <LoadingWCDelegate>) del
actionCode:(NSInteger) code;
- (IBAction)completeAction:(id)sender;
- (IBAction)cancelPressed:(id)sender;
@optional
/*
* Display an error message to the user
*/
- (void)showError:(NSString*) error;
/*
* Show progress during action completion
*/
- (void)showLoading;
/*
* Show final state after action completion
*/
- (void)showFinal;
@end
/*
* Copyright (C) 2016 Savoir-faire Linux Inc.
* Author: Alexandre Lision <alexandre.lision@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>
//LRC
#import <account.h>
//RING
#import "LoadingWCProtocol.h"
#import "LoadingWCDelegate.h"
#import "AbstractLoadingWC.h"
@protocol MigrateRingAccountsDelegate <LoadingWCDelegate>
-(void) migrationDidCompleteWithError;
-(void) migrationDidComplete;
@end
@interface MigrateRingAccountsWC : AbstractLoadingWC <LoadingWCProtocol>
/**
* password string contained in passwordField.
*/
@property (retain) NSString* password;
/**
* passwordConfirmation string contained in passwordConfirmationField.
*/
@property (retain) NSString* passwordConfirmation;
/**
* computed properties calculated by password string contained in
* passwordField and passwordCOnfirmation string contained
* inpasswordConfirmationField
* This is a KVO method to bind the text with the OK Button
* if password.length is > 0 AND passwordConfirmation.length > 0
* AND password isEqualsToString passwordCOnfirmationbutton is enabled,
* otherwise disabled
*/
@property (readonly) BOOL validatePasswords;
@property Account* account;
@end
/*
* Copyright (C) 2016 Savoir-faire Linux Inc.
* Author: Alexandre Lision <alexandre.lision@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 "MigrateRingAccountsWC.h"
//LRC
#import <accountmodel.h>
//RING
#import "views/ITProgressIndicator.h"
@interface MigrateRingAccountsWC() <NSTextFieldDelegate>{
__unsafe_unretained IBOutlet NSSecureTextField* passwordField;
__unsafe_unretained IBOutlet NSSecureTextField* passwordConfirmField;
__unsafe_unretained IBOutlet NSTextField* infoField;
__unsafe_unretained IBOutlet NSTextField* errorField;
__unsafe_unretained IBOutlet ITProgressIndicator* progressIndicator;
}
- (IBAction)onClickComplete:(id)sender;
@end
@implementation MigrateRingAccountsWC{
struct {
unsigned int didComplete:1;
unsigned int didCompleteWithError:1;
} delegateRespondsTo;
}
NSTimer* errorTimer;
QMetaObject::Connection stateChanged;
#pragma mark - Initialise / Setters
- (id)initWithDelegate:(id <MigrateRingAccountsDelegate>) del actionCode:(NSInteger) code
{
return [super initWithWindowNibName:@"MigrateRingAccountsWindow" delegate:del actionCode:code];
}
- (void) awakeFromNib{
[self setInfoMessageForAccount];
}
- (void)setDelegate:(id <MigrateRingAccountsDelegate>)aDelegate
{
if (super.delegate != aDelegate) {
[super setDelegate: aDelegate];
delegateRespondsTo.didCompleteWithError = [self.delegate respondsToSelector:@selector(migrationDidCompleteWithError)];
delegateRespondsTo.didComplete = [self.delegate respondsToSelector:@selector(migrationDidComplete)];
}
}
- (void) setAccount:(Account *)aAccount
{
_account = aAccount;
}
- (void) setInfoMessageForAccount
{
NSMutableAttributedString* infoMessage = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"The following account needs to be migrated to the new Ring account format:",@"Text shown to the user")];
[infoMessage appendAttributedString:[[NSAttributedString alloc] initWithString:@"\n"]];
[infoMessage appendAttributedString:[[NSAttributedString alloc] initWithString:NSLocalizedString(@"Alias : ",@"Text shown to the user")]];
const CGFloat fontSize = 13;
NSDictionary *attrs = @{
NSFontAttributeName:[NSFont boldSystemFontOfSize:fontSize]
};
[infoMessage appendAttributedString:[[NSAttributedString alloc] initWithString:self.account->alias().toNSString() attributes:attrs]];
[infoMessage appendAttributedString:[[NSAttributedString alloc] initWithString:@"\n"]];
[infoMessage appendAttributedString:[[NSAttributedString alloc] initWithString:NSLocalizedString(@"ID : ",@"Text shown to the user")]];
[infoMessage appendAttributedString:[[NSAttributedString alloc] initWithString:@(self.account->id().constData()) attributes:attrs]];
[infoMessage appendAttributedString:[[NSAttributedString alloc] initWithString:@"\n"]];
[infoMessage appendAttributedString:[[NSAttributedString alloc] initWithString:NSLocalizedString(@"To proceed with the migration, you must choose a password for your account. This password will be used to encrypt your master key. It will be required for adding new devices to your Ring account. If you are not ready to choose a password, you may close Ring and resume the migration later.",@"Text shown to the user")]];
[infoField setAttributedStringValue:infoMessage];
}
- (void) showError:(NSString*) errorMessage
{
[errorField setStringValue:errorMessage];
[super showError];
}
- (void)showLoading
{
[progressIndicator setNumberOfLines:30];
[progressIndicator setWidthOfLine:2];
[progressIndicator setLengthOfLine:5];
[progressIndicator setInnerMargin:20];
[super showLoading];
}
#pragma mark - Events Handlers
- (IBAction)removeAccount:(id)sender
{
AccountModel::instance().remove(self.account);
AccountModel::instance().save();
[self cancelPressed:sender];
}
- (IBAction)startMigration:(NSButton *)sender
{
if (![self validatePasswords]) {
[self showError:NSLocalizedString(@"Password and confirmation mismatch.",@"Text show to the user when password didn't match")];
} else {
[self showLoading];
errorTimer = [NSTimer scheduledTimerWithTimeInterval:30
target:self
selector:@selector(didCompleteWithError) userInfo:nil
repeats:NO];
stateChanged = QObject::connect(
self.account, &Account::stateChanged,
[=](Account::RegistrationState state){
switch(state){
case Account::RegistrationState::READY:
case Account::RegistrationState::TRYING:
case Account::RegistrationState::UNREGISTERED:{
self.account<< Account::EditAction::RELOAD;
QObject::disconnect(stateChanged);
[self didComplete];
break;
}
case Account::RegistrationState::ERROR:
case Account::RegistrationState::INITIALIZING:
case Account::RegistrationState::COUNT__:{
//DO Nothing
break;
}
}
});
self.account->setArchivePassword(QString::fromNSString(self.password));
self.account->performAction(Account::EditAction::SAVE);
}
}
- (BOOL)validatePasswords
{
BOOL result = (self.password.length != 0 && [self.password isEqualToString:self.passwordConfirmation]);
NSLog(@"ValidatesPasswords : %s", result ? "true" : "false");
return result;
}
+ (NSSet *)keyPathsForValuesAffectingValidatePasswords
{
return [NSSet setWithObjects:@"password", @"passwordConfirmation", nil];
}
#pragma mark - Delegates
- (void)didComplete
{
[errorTimer invalidate];
errorTimer = nil;
[self showFinal];
}
- (void)onClickComplete:(id)sender
{
[self cancelPressed:sender];
if (delegateRespondsTo.didComplete)
[((id<MigrateRingAccountsDelegate>)self.delegate) migrationDidComplete];
}
- (void)didCompleteWithError
{
[self showError:NSLocalizedString(@"Failed to migrate your account. You can retry by pressing Ok or delete your account.",@"Error message shown to user when it is impossible to migrate account")];
}
@end
......@@ -31,15 +31,22 @@
#import <call.h>
#import <recentmodel.h>
// Ring
#import "AppDelegate.h"
#import "Constants.h"
#import "CurrentCallVC.h"
#import "MigrateRingAccountsWC.h"
#import "ConversationVC.h"
#import "PreferencesWC.h"
#import "views/IconButton.h"
#import "views/NSColor+RingTheme.h"
@interface RingWindowController () <MigrateRingAccountsDelegate>
@property (retain) MigrateRingAccountsWC* migrateWC;
@end
@implementation RingWindowController {
__unsafe_unretained IBOutlet NSLayoutConstraint* centerYQRCodeConstraint;
......@@ -55,6 +62,7 @@
ConversationVC* offlineVC;
}
QMetaObject::Connection accountUpdate;
static NSString* const kPreferencesIdentifier = @"PreferencesIdentifier";
- (void)windowDidLoad {
......@@ -74,21 +82,18 @@ static NSString* const kPreferencesIdentifier = @"PreferencesIdentifier";
[currentCallVC initFrame];
[offlineVC initFrame];
// Fresh run, we need to make sure RingID appears
[self updateRingID];
[shareButton sendActionOn:NSLeftMouseDownMask];
[self connect];
[self checkAccountsToMigrate];
}
- (void) connect
{
// Update Ring ID label based on account model changes
QObject::connect(&AccountModel::instance(),
&AccountModel::dataChanged,
[=] {
[self updateRingID];
});
QObject::disconnect(accountUpdate);
accountUpdate = QObject::connect(&AccountModel::instance(),
&AccountModel::dataChanged,
[=] {
[self updateRingID];
});
QObject::connect(RecentModel::instance().selectionModel(),
&QItemSelectionModel::currentChanged,
......@@ -265,4 +270,46 @@ static NSString* const kPreferencesIdentifier = @"PreferencesIdentifier";
[preferencesWC.window makeKeyAndOrderFront:preferencesWC.window];
}
#pragma mark - Ring account migration
- (void) migrateRingAccount:(Account*) acc
{
self.migrateWC = [[MigrateRingAccountsWC alloc] initWithDelegate:self actionCode:1];
self.migrateWC.account = acc;
#if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_9
[self.window beginSheet:self.migrateWC.window completionHandler:nil];
#else
[NSApp beginSheet: self.migrateWC.window
modalForWindow: self.window
modalDelegate: self
didEndSelector: nil
contextInfo: nil];
#endif
}
- (void)checkAccountsToMigrate
{
auto ringList = AccountModel::instance().accountsToMigrate();
if (ringList.length() > 0){
Account* acc = ringList.value(0);
[self migrateRingAccount:acc];
} else {
// Fresh run, we need to make sure RingID appears
[self updateRingID];
[shareButton sendActionOn:NSLeftMouseDownMask];
[self connect];
}
}
- (void)migrationDidComplete
{
[self checkAccountsToMigrate];
}
- (void)migrationDidCompleteWithError
{
[self checkAccountsToMigrate];
}
@end
/* Class = "NSTextFieldCell"; title = "Account migration completed"; ObjectID = "1ob-x1-u74"; */
"1ob-x1-u74.title" = "Account migration completed";
/* Class = "NSTextFieldCell"; placeholderString = "RingID"; ObjectID = "859-10-HEb"; */
"859-10-HEb.placeholderString" = "RingID";
/* Class = "NSTextFieldCell"; title = "The following account needs to be migrated to the new Ring account format:\\n Alias : \\nID:\\n To proceed with the migration, you must choose a password for your account. This password will be used to encrypt your master key. It will be required for adding new devices to your Ring account. If you are not ready to choose a password, you may close Ring and resume the migration later."; ObjectID = "859-10-HEb"; */
"859-10-HEb.title" = "The following account needs to be migrated to the new Ring account format:\\n Alias : \\nID:\\n To proceed with the migration, you must choose a password for your account. This password will be used to encrypt your master key. It will be required for adding new devices to your Ring account. If your not ready to choose a password, you may close Ring and resume the migration later.";
/* Class = "NSTextFieldCell"; title = "Account migration error"; ObjectID = "8K3-9Z-MKH"; */
"8K3-9Z-MKH.title" = "Account migration error";
/* Class = "NSTextFieldCell"; title = "Congratulations, your account has been migrated with Success."; ObjectID = "C2l-rz-Gqt"; */
"C2l-rz-Gqt.title" = "Congratulations, your account has been migrated with Success.";
/* Class = "NSButtonCell"; title = "Delete this account"; ObjectID = "ITE-yD-CTb"; */
"ITE-yD-CTb.title" = "Delete this account";
/* Class = "NSSecureTextFieldCell"; placeholderString = "Confirm your new password..."; ObjectID = "KuO-oT-zhY"; */
"KuO-oT-zhY.placeholderString" = "Confirm your new password...";
/* Class = "NSButtonCell"; title = "OK"; ObjectID = "PT7-XI-WDR"; */
"PT7-XI-WDR.title" = "OK";
/* Class = "NSWindow"; title = "Window"; ObjectID = "QvC-M9-y7g"; */
"QvC-M9-y7g.title" = "Window";
/* Class = "NSButtonCell"; title = "OK"; ObjectID = "VN1-A3-RIh"; */
"VN1-A3-RIh.title" = "OK";
/* Class = "NSTextFieldCell"; title = "Confirmation"; ObjectID = "aOa-1q-AZe"; */
"aOa-1q-AZe.title" = "Confirmation";
/* Class = "NSTextFieldCell"; placeholderString = "error label"; ObjectID = "e7n-Ev-bK7"; */
"e7n-Ev-bK7.placeholderString" = "error label";
/* Class = "NSButtonCell"; title = "Migrate"; ObjectID = "rW5-Il-5YD"; */
"rW5-Il-5YD.title" = "Migrate";
/* Class = "NSTextFieldCell"; title = "Password"; ObjectID = "vwh-K9-3O9"; */
"vwh-K9-3O9.title" = "Password";
/* Class = "NSTextFieldCell"; title = "Account migration required"; ObjectID = "wmv-sA-Mlh"; */
"wmv-sA-Mlh.title" = "Account migration required";
/* Class = "NSSecureTextFieldCell"; placeholderString = "Password..."; ObjectID = "xqz-Uz-hqU"; */
"xqz-Uz-hqU.placeholderString" = "Password...";
This diff is collapsed.
......@@ -24,7 +24,7 @@
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="351" height="131"/>
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="877"/>
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="900"/>
<view key="contentView" id="EiT-Mj-1SZ">
<rect key="frame" x="0.0" y="0.0" width="351" height="131"/>
<autoresizingMask key="autoresizingMask"/>
......
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