Work on two-factor auth settings UI.

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

@ -7,9 +7,9 @@
NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSUInteger, Enable2FAMode) {
Enable2FAMode_Status = 0,
Enable2FAMode_SelectPIN,
Enable2FAMode_ConfirmPIN,
OWS2FASettingsMode_Status = 0,
OWS2FASettingsMode_SelectPIN,
OWS2FASettingsMode_ConfirmPIN,
};
@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 createContents];
}
- (void)createContents
{
for (UIView *subview in self.view.subviews) {
[subview removeFromSuperview];
}
switch (self.mode) {
case Enable2FAMode_Status:
case OWS2FASettingsMode_Status:
[self createStatusContents];
break;
case Enable2FAMode_SelectPIN:
case OWS2FASettingsMode_SelectPIN:
[self createSelectCodeContents];
break;
case Enable2FAMode_ConfirmPIN:
case OWS2FASettingsMode_ConfirmPIN:
[self createConfirmCodeContents];
break;
}
@ -52,10 +61,26 @@ NS_ASSUME_NONNULL_BEGIN
- (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];
// If we're using a table, refresh its contents.
[self updateTableContents];
if (self.mode == OWS2FASettingsMode_Status) {
// 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];
}
@ -86,15 +111,15 @@ NS_ASSUME_NONNULL_BEGIN
self.pinTextfield = [UITextField new];
self.pinTextfield.textColor = [UIColor blackColor];
switch (self.mode) {
case Enable2FAMode_SelectPIN:
case OWS2FASettingsMode_SelectPIN:
self.pinTextfield.placeholder = NSLocalizedString(@"ENABLE_2FA_VIEW_SELECT_PIN_DEFAULT_TEXT",
@"Text field placeholder for 'two factor auth pin' when selecting a pin.");
break;
case Enable2FAMode_ConfirmPIN:
case OWS2FASettingsMode_ConfirmPIN:
self.pinTextfield.placeholder = NSLocalizedString(@"ENABLE_2FA_VIEW_CONFIRM_PIN_DEFAULT_TEXT",
@"Text field placeholder for 'two factor auth pin' when confirming a pin.");
break;
case Enable2FAMode_Status:
case OWS2FASettingsMode_Status:
OWSFail(@"%@ invalid mode.", self.logTag) break;
}
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.
switch (self.mode) {
case Enable2FAMode_Status: {
case OWS2FASettingsMode_Status: {
OWSTableContents *contents = [OWSTableContents new];
OWSTableSection *section = [OWSTableSection new];
if ([OWS2FAManager.sharedManager is2FAEnabled]) {
@ -222,8 +247,8 @@ NS_ASSUME_NONNULL_BEGIN
self.tableViewController.contents = contents;
break;
}
case Enable2FAMode_SelectPIN:
case Enable2FAMode_ConfirmPIN:
case OWS2FASettingsMode_SelectPIN:
case OWS2FASettingsMode_ConfirmPIN:
return;
}
}
@ -231,10 +256,10 @@ NS_ASSUME_NONNULL_BEGIN
- (BOOL)shouldHaveNextButton
{
switch (self.mode) {
case Enable2FAMode_Status:
case OWS2FASettingsMode_Status:
return NO;
case Enable2FAMode_SelectPIN:
case Enable2FAMode_ConfirmPIN:
case OWS2FASettingsMode_SelectPIN:
case OWS2FASettingsMode_ConfirmPIN:
return [self hasValidPin];
}
}
@ -325,20 +350,21 @@ NS_ASSUME_NONNULL_BEGIN
DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
switch (self.mode) {
case Enable2FAMode_Status:
case OWS2FASettingsMode_Status:
OWSFail(@"%@ status mode should not have a next button.", self.logTag);
return;
case Enable2FAMode_SelectPIN: {
case OWS2FASettingsMode_SelectPIN: {
OWSAssert(self.hasValidPin);
OWS2FASettingsViewController *vc = [OWS2FASettingsViewController new];
vc.mode = Enable2FAMode_ConfirmPIN;
vc.mode = OWS2FASettingsMode_ConfirmPIN;
vc.candidatePin = self.pinTextfield.text;
vc.root2FAViewController = self;
OWSAssert(self.root2FAViewController);
vc.root2FAViewController = self.root2FAViewController;
[self.navigationController pushViewController:vc animated:YES];
break;
}
case Enable2FAMode_ConfirmPIN: {
case OWS2FASettingsMode_ConfirmPIN: {
OWSAssert(self.hasValidPin);
if ([self.pinTextfield.text isEqualToString:self.candidatePin]) {
@ -370,7 +396,7 @@ NS_ASSUME_NONNULL_BEGIN
DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
OWS2FASettingsViewController *vc = [OWS2FASettingsViewController new];
vc.mode = Enable2FAMode_SelectPIN;
vc.mode = OWS2FASettingsMode_SelectPIN;
vc.root2FAViewController = self;
[self.navigationController pushViewController:vc animated:YES];
}
@ -394,7 +420,7 @@ NS_ASSUME_NONNULL_BEGIN
}
failure:^(NSError *error) {
[modalActivityIndicator dismissWithCompletion:^{
[weakSelf updateTableContents];
[weakSelf createContents];
[OWSAlerts
showAlertWithTitle:NSLocalizedString(@"ALERT_ERROR_TITLE", @"")

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

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

Loading…
Cancel
Save