Work on two-factor auth settings UI.

pull/1/head
Matthew Chen 8 years ago
parent e12a1e984a
commit ea783a8ad5

@ -7,9 +7,9 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSUInteger, Enable2FAMode) { typedef NS_ENUM(NSUInteger, Enable2FAMode) {
Enable2FAMode_Status = 0, OWS2FASettingsMode_Status = 0,
Enable2FAMode_SelectPIN, OWS2FASettingsMode_SelectPIN,
Enable2FAMode_ConfirmPIN, OWS2FASettingsMode_ConfirmPIN,
}; };
@interface OWS2FASettingsViewController : OWSViewController @interface OWS2FASettingsViewController : OWSViewController

@ -37,14 +37,23 @@ NS_ASSUME_NONNULL_BEGIN
self.title = NSLocalizedString(@"ENABLE_2FA_VIEW_TITLE", @"Title for the 'enable two factor auth PIN' views."); self.title = NSLocalizedString(@"ENABLE_2FA_VIEW_TITLE", @"Title for the 'enable two factor auth PIN' views.");
[self createContents];
}
- (void)createContents
{
for (UIView *subview in self.view.subviews) {
[subview removeFromSuperview];
}
switch (self.mode) { switch (self.mode) {
case Enable2FAMode_Status: case OWS2FASettingsMode_Status:
[self createStatusContents]; [self createStatusContents];
break; break;
case Enable2FAMode_SelectPIN: case OWS2FASettingsMode_SelectPIN:
[self createSelectCodeContents]; [self createSelectCodeContents];
break; break;
case Enable2FAMode_ConfirmPIN: case OWS2FASettingsMode_ConfirmPIN:
[self createConfirmCodeContents]; [self createConfirmCodeContents];
break; break;
} }
@ -52,10 +61,26 @@ NS_ASSUME_NONNULL_BEGIN
- (void)viewWillAppear:(BOOL)animated - (void)viewWillAppear:(BOOL)animated
{ {
switch (self.mode) {
case OWS2FASettingsMode_Status:
break;
case OWS2FASettingsMode_SelectPIN:
case OWS2FASettingsMode_ConfirmPIN:
OWSAssert(![OWS2FAManager.sharedManager is2FAEnabled]);
break;
}
[super viewWillAppear:animated]; [super viewWillAppear:animated];
// If we're using a table, refresh its contents. if (self.mode == OWS2FASettingsMode_Status) {
[self updateTableContents]; // Ever time we re-enter the "status" view, recreate its
// contents wholesale since we may have just enabled or
// disabled 2FA.
[self createContents];
} else {
// If we're using a table, refresh its contents.
[self updateTableContents];
}
[self updateNavigationItems]; [self updateNavigationItems];
} }
@ -86,15 +111,15 @@ NS_ASSUME_NONNULL_BEGIN
self.pinTextfield = [UITextField new]; self.pinTextfield = [UITextField new];
self.pinTextfield.textColor = [UIColor blackColor]; self.pinTextfield.textColor = [UIColor blackColor];
switch (self.mode) { switch (self.mode) {
case Enable2FAMode_SelectPIN: case OWS2FASettingsMode_SelectPIN:
self.pinTextfield.placeholder = NSLocalizedString(@"ENABLE_2FA_VIEW_SELECT_PIN_DEFAULT_TEXT", self.pinTextfield.placeholder = NSLocalizedString(@"ENABLE_2FA_VIEW_SELECT_PIN_DEFAULT_TEXT",
@"Text field placeholder for 'two factor auth pin' when selecting a pin."); @"Text field placeholder for 'two factor auth pin' when selecting a pin.");
break; break;
case Enable2FAMode_ConfirmPIN: case OWS2FASettingsMode_ConfirmPIN:
self.pinTextfield.placeholder = NSLocalizedString(@"ENABLE_2FA_VIEW_CONFIRM_PIN_DEFAULT_TEXT", self.pinTextfield.placeholder = NSLocalizedString(@"ENABLE_2FA_VIEW_CONFIRM_PIN_DEFAULT_TEXT",
@"Text field placeholder for 'two factor auth pin' when confirming a pin."); @"Text field placeholder for 'two factor auth pin' when confirming a pin.");
break; break;
case Enable2FAMode_Status: case OWS2FASettingsMode_Status:
OWSFail(@"%@ invalid mode.", self.logTag) break; OWSFail(@"%@ invalid mode.", self.logTag) break;
} }
self.pinTextfield.font = [UIFont ows_mediumFontWithSize:ScaleFromIPhone5To7Plus(30.f, 36.f)]; self.pinTextfield.font = [UIFont ows_mediumFontWithSize:ScaleFromIPhone5To7Plus(30.f, 36.f)];
@ -198,7 +223,7 @@ NS_ASSUME_NONNULL_BEGIN
// Only some modes use a table. // Only some modes use a table.
switch (self.mode) { switch (self.mode) {
case Enable2FAMode_Status: { case OWS2FASettingsMode_Status: {
OWSTableContents *contents = [OWSTableContents new]; OWSTableContents *contents = [OWSTableContents new];
OWSTableSection *section = [OWSTableSection new]; OWSTableSection *section = [OWSTableSection new];
if ([OWS2FAManager.sharedManager is2FAEnabled]) { if ([OWS2FAManager.sharedManager is2FAEnabled]) {
@ -222,8 +247,8 @@ NS_ASSUME_NONNULL_BEGIN
self.tableViewController.contents = contents; self.tableViewController.contents = contents;
break; break;
} }
case Enable2FAMode_SelectPIN: case OWS2FASettingsMode_SelectPIN:
case Enable2FAMode_ConfirmPIN: case OWS2FASettingsMode_ConfirmPIN:
return; return;
} }
} }
@ -231,10 +256,10 @@ NS_ASSUME_NONNULL_BEGIN
- (BOOL)shouldHaveNextButton - (BOOL)shouldHaveNextButton
{ {
switch (self.mode) { switch (self.mode) {
case Enable2FAMode_Status: case OWS2FASettingsMode_Status:
return NO; return NO;
case Enable2FAMode_SelectPIN: case OWS2FASettingsMode_SelectPIN:
case Enable2FAMode_ConfirmPIN: case OWS2FASettingsMode_ConfirmPIN:
return [self hasValidPin]; return [self hasValidPin];
} }
} }
@ -325,20 +350,21 @@ NS_ASSUME_NONNULL_BEGIN
DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__); DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
switch (self.mode) { switch (self.mode) {
case Enable2FAMode_Status: case OWS2FASettingsMode_Status:
OWSFail(@"%@ status mode should not have a next button.", self.logTag); OWSFail(@"%@ status mode should not have a next button.", self.logTag);
return; return;
case Enable2FAMode_SelectPIN: { case OWS2FASettingsMode_SelectPIN: {
OWSAssert(self.hasValidPin); OWSAssert(self.hasValidPin);
OWS2FASettingsViewController *vc = [OWS2FASettingsViewController new]; OWS2FASettingsViewController *vc = [OWS2FASettingsViewController new];
vc.mode = Enable2FAMode_ConfirmPIN; vc.mode = OWS2FASettingsMode_ConfirmPIN;
vc.candidatePin = self.pinTextfield.text; vc.candidatePin = self.pinTextfield.text;
vc.root2FAViewController = self; OWSAssert(self.root2FAViewController);
vc.root2FAViewController = self.root2FAViewController;
[self.navigationController pushViewController:vc animated:YES]; [self.navigationController pushViewController:vc animated:YES];
break; break;
} }
case Enable2FAMode_ConfirmPIN: { case OWS2FASettingsMode_ConfirmPIN: {
OWSAssert(self.hasValidPin); OWSAssert(self.hasValidPin);
if ([self.pinTextfield.text isEqualToString:self.candidatePin]) { if ([self.pinTextfield.text isEqualToString:self.candidatePin]) {
@ -370,7 +396,7 @@ NS_ASSUME_NONNULL_BEGIN
DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__); DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
OWS2FASettingsViewController *vc = [OWS2FASettingsViewController new]; OWS2FASettingsViewController *vc = [OWS2FASettingsViewController new];
vc.mode = Enable2FAMode_SelectPIN; vc.mode = OWS2FASettingsMode_SelectPIN;
vc.root2FAViewController = self; vc.root2FAViewController = self;
[self.navigationController pushViewController:vc animated:YES]; [self.navigationController pushViewController:vc animated:YES];
} }
@ -394,7 +420,7 @@ NS_ASSUME_NONNULL_BEGIN
} }
failure:^(NSError *error) { failure:^(NSError *error) {
[modalActivityIndicator dismissWithCompletion:^{ [modalActivityIndicator dismissWithCompletion:^{
[weakSelf updateTableContents]; [weakSelf createContents];
[OWSAlerts [OWSAlerts
showAlertWithTitle:NSLocalizedString(@"ALERT_ERROR_TITLE", @"") showAlertWithTitle:NSLocalizedString(@"ALERT_ERROR_TITLE", @"")

@ -23,7 +23,7 @@ NS_ASSUME_NONNULL_BEGIN
[self updateTableContents]; [self updateTableContents];
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[self enable2FA]; [self show2FASettings];
}); });
} }
@ -129,21 +129,20 @@ NS_ASSUME_NONNULL_BEGIN
OWSTableSection *twoFactorAuthSection = [OWSTableSection new]; OWSTableSection *twoFactorAuthSection = [OWSTableSection new];
twoFactorAuthSection.headerTitle = NSLocalizedString( twoFactorAuthSection.headerTitle = NSLocalizedString(
@"SETTINGS_TWO_FACTOR_AUTH_TITLE", @"Title for the 'two factor auth' section of the privacy settings."); @"SETTINGS_TWO_FACTOR_AUTH_TITLE", @"Title for the 'two factor auth' section of the privacy settings.");
BOOL is2FAEnabled = [OWS2FAManager.sharedManager is2FAEnabled];
[twoFactorAuthSection [twoFactorAuthSection
addItem:[OWSTableItem addItem:
disclosureItemWithText: [OWSTableItem
(is2FAEnabled ? NSLocalizedString(@"SETTINGS_TWO_FACTOR_AUTH_DISABLE", disclosureItemWithText:NSLocalizedString(@"SETTINGS_TWO_FACTOR_AUTH_ITEM",
@"Label for the 'disable two factor auth' item of the privacy settings.") @"Label for the 'two factor auth' item of the privacy settings.")
: NSLocalizedString(@"SETTINGS_TWO_FACTOR_AUTH_ENABLE", detailText:
@"Label for the 'enable two factor auth' item of the privacy settings.")) ([OWS2FAManager.sharedManager is2FAEnabled]
actionBlock:^{ ? NSLocalizedString(@"SETTINGS_TWO_FACTOR_AUTH_ENABLED",
if (is2FAEnabled) { @"Indicates that 'two factor auth' is enabled in the privacy settings.")
[weakSelf disable2FA]; : NSLocalizedString(@"SETTINGS_TWO_FACTOR_AUTH_DISABLED",
} else { @"Indicates that 'two factor auth' is disabled in the privacy settings."))
[weakSelf enable2FA]; actionBlock:^{
} [weakSelf show2FASettings];
}]]; }]];
[contents addSection:twoFactorAuthSection]; [contents addSection:twoFactorAuthSection];
self.contents = contents; self.contents = contents;
@ -239,20 +238,15 @@ NS_ASSUME_NONNULL_BEGIN
[SignalApp.sharedApp.callService createCallUIAdapter]; [SignalApp.sharedApp.callService createCallUIAdapter];
} }
- (void)enable2FA - (void)show2FASettings
{ {
DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__); DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
OWS2FASettingsViewController *vc = [OWS2FASettingsViewController new]; OWS2FASettingsViewController *vc = [OWS2FASettingsViewController new];
vc.mode = Enable2FAMode_Status; vc.mode = OWS2FASettingsMode_Status;
[self.navigationController pushViewController:vc animated:YES]; [self.navigationController pushViewController:vc animated:YES];
} }
- (void)disable2FA
{
DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
}
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

@ -1668,11 +1668,14 @@
/* No comment provided by engineer. */ /* No comment provided by engineer. */
"SETTINGS_SUPPORT" = "Support"; "SETTINGS_SUPPORT" = "Support";
/* Label for the 'disable two factor auth' item of the privacy settings. */ /* Indicates that 'two factor auth' is disabled in the privacy settings. */
"SETTINGS_TWO_FACTOR_AUTH_DISABLE" = "Disable Two-Step Verification"; "SETTINGS_TWO_FACTOR_AUTH_DISABLED" = "Disabled";
/* Label for the 'enable two factor auth' item of the privacy settings. */ /* Indicates that 'two factor auth' is enabled in the privacy settings. */
"SETTINGS_TWO_FACTOR_AUTH_ENABLE" = "Enable Two-Step Verification"; "SETTINGS_TWO_FACTOR_AUTH_ENABLED" = "Enabled";
/* Label for the 'two factor auth' item of the privacy settings. */
"SETTINGS_TWO_FACTOR_AUTH_ITEM" = "Two-Step Verification";
/* Title for the 'two factor auth' section of the privacy settings. */ /* Title for the 'two factor auth' section of the privacy settings. */
"SETTINGS_TWO_FACTOR_AUTH_TITLE" = "Two-Step Verification"; "SETTINGS_TWO_FACTOR_AUTH_TITLE" = "Two-Step Verification";

Loading…
Cancel
Save