|
|
|
@ -14,7 +14,6 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
NSString *const NSNotificationName_2FAStateDidChange = @"NSNotificationName_2FAStateDidChange";
|
|
|
|
|
|
|
|
|
|
NSString *const kOWS2FAManager_Collection = @"kOWS2FAManager_Collection";
|
|
|
|
|
NSString *const kOWS2FAManager_IsEnabledKey = @"kOWS2FAManager_IsEnabledKey";
|
|
|
|
|
NSString *const kOWS2FAManager_LastSuccessfulReminderDateKey = @"kOWS2FAManager_LastSuccessfulReminderDateKey";
|
|
|
|
|
NSString *const kOWS2FAManager_PinCode = @"kOWS2FAManager_PinCode";
|
|
|
|
|
NSString *const kOWS2FAManager_RepetitionInterval = @"kOWS2FAManager_RepetitionInterval";
|
|
|
|
@ -71,16 +70,19 @@ const NSUInteger kDaySecs = kHourSecs * 24;
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (nullable NSString *)pinCode
|
|
|
|
|
{
|
|
|
|
|
return [self.dbConnection objectForKey:kOWS2FAManager_PinCode inCollection:kOWS2FAManager_Collection];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL)is2FAEnabled
|
|
|
|
|
{
|
|
|
|
|
return [self.dbConnection boolForKey:kOWS2FAManager_IsEnabledKey
|
|
|
|
|
inCollection:kOWS2FAManager_Collection
|
|
|
|
|
defaultValue:NO];
|
|
|
|
|
return self.pinCode != nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setIs2FAEnabled:(BOOL)value
|
|
|
|
|
- (void)set2FANotEnabled
|
|
|
|
|
{
|
|
|
|
|
[self.dbConnection setBool:value forKey:kOWS2FAManager_IsEnabledKey inCollection:kOWS2FAManager_Collection];
|
|
|
|
|
[self.dbConnection removeObjectForKey:kOWS2FAManager_PinCode inCollection:kOWS2FAManager_Collection];
|
|
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationNameAsync:NSNotificationName_2FAStateDidChange
|
|
|
|
|
object:nil
|
|
|
|
@ -89,8 +91,13 @@ const NSUInteger kDaySecs = kHourSecs * 24;
|
|
|
|
|
|
|
|
|
|
- (void)mark2FAAsEnabledWithPin:(NSString *)pin
|
|
|
|
|
{
|
|
|
|
|
[self setIs2FAEnabled:YES];
|
|
|
|
|
[self storePinCode:pin];
|
|
|
|
|
OWSAssert(pin.length > 0);
|
|
|
|
|
|
|
|
|
|
[self.dbConnection setObject:pin forKey:kOWS2FAManager_PinCode inCollection:kOWS2FAManager_Collection];
|
|
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationNameAsync:NSNotificationName_2FAStateDidChange
|
|
|
|
|
object:nil
|
|
|
|
|
userInfo:nil];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)requestEnable2FAWithPin:(NSString *)pin
|
|
|
|
@ -107,6 +114,7 @@ const NSUInteger kDaySecs = kHourSecs * 24;
|
|
|
|
|
OWSAssertIsOnMainThread();
|
|
|
|
|
|
|
|
|
|
[self mark2FAAsEnabledWithPin:pin];
|
|
|
|
|
|
|
|
|
|
if (success) {
|
|
|
|
|
success();
|
|
|
|
|
}
|
|
|
|
@ -127,7 +135,7 @@ const NSUInteger kDaySecs = kHourSecs * 24;
|
|
|
|
|
success:^(NSURLSessionDataTask *task, id responseObject) {
|
|
|
|
|
OWSAssertIsOnMainThread();
|
|
|
|
|
|
|
|
|
|
[self setIs2FAEnabled:NO];
|
|
|
|
|
[self set2FANotEnabled];
|
|
|
|
|
|
|
|
|
|
if (success) {
|
|
|
|
|
success();
|
|
|
|
@ -145,16 +153,6 @@ const NSUInteger kDaySecs = kHourSecs * 24;
|
|
|
|
|
|
|
|
|
|
#pragma mark - Reminders
|
|
|
|
|
|
|
|
|
|
- (void)storePinCode:(nullable NSString *)pinCode
|
|
|
|
|
{
|
|
|
|
|
[self.dbConnection setObject:pinCode forKey:kOWS2FAManager_PinCode inCollection:kOWS2FAManager_Collection];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (nullable NSString *)pinCode
|
|
|
|
|
{
|
|
|
|
|
return [self.dbConnection objectForKey:kOWS2FAManager_PinCode inCollection:kOWS2FAManager_Collection];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (nullable NSDate *)lastSuccessfulReminderDate
|
|
|
|
|
{
|
|
|
|
|
return [self.dbConnection dateForKey:kOWS2FAManager_LastSuccessfulReminderDateKey
|
|
|
|
|