NCSettings.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. //
  2. // NCSettings.m
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 24/11/14.
  6. // Copyright (c) 2014 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. #import "NCSettings.h"
  24. #import "CCAdvanced.h"
  25. #import "CCManageAccount.h"
  26. #import "CCManageAutoUpload.h"
  27. #import "NCBridgeSwift.h"
  28. #import "NSNotificationCenter+MainThread.h"
  29. #import <LocalAuthentication/LocalAuthentication.h>
  30. #import <TOPasscodeViewController/TOPasscodeViewController.h>
  31. #define alertViewEsci 1
  32. #define alertViewAzzeraCache 2
  33. @interface NCSettings () <TOPasscodeSettingsViewControllerDelegate, TOPasscodeViewControllerDelegate>
  34. {
  35. AppDelegate *appDelegate;
  36. TOPasscodeViewController *passcodeViewController;
  37. TOPasscodeSettingsViewController *passcodeSettingsViewController;
  38. NSString *versionServer;
  39. NSString *themingName;
  40. NSString *themingSlogan;
  41. }
  42. @end
  43. @implementation NCSettings
  44. - (void)initializeForm
  45. {
  46. XLFormDescriptor *form = [XLFormDescriptor formDescriptor];
  47. XLFormSectionDescriptor *section;
  48. XLFormRowDescriptor *row;
  49. form.rowNavigationOptions = XLFormRowNavigationOptionNone;
  50. // Section AUTO UPLOAD OF CAMERA IMAGES ----------------------------
  51. section = [XLFormSectionDescriptor formSection];
  52. [form addFormSection:section];
  53. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUpload" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_settings_autoupload_", nil)];
  54. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  55. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  56. [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
  57. [row.cellConfig setObject:[[UIImage imageNamed:@"autoUpload"] imageWithColor:UIColor.systemGrayColor size:25] forKey:@"imageView.image"];
  58. row.action.viewControllerClass = [CCManageAutoUpload class];
  59. [section addFormRow:row];
  60. // Section : PRIVACY --------------------------------------------------------------
  61. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_privacy_", nil)];
  62. [form addFormSection:section];
  63. // Lock active YES/NO
  64. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"bloccopasscode" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_lock_not_active_", nil)];
  65. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  66. [row.cellConfig setObject:[[UIImage imageNamed:@"lock_open"] imageWithColor:UIColor.systemGrayColor size:25] forKey:@"imageView.image"];
  67. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  68. [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
  69. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  70. //[row.cellConfig setObject:@(UITableViewCellAccessoryDisclosureIndicator) forKey:@"accessoryType"];
  71. row.action.formSelector = @selector(passcode:);
  72. [section addFormRow:row];
  73. // Enable Touch ID
  74. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"enableTouchDaceID" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_enable_touch_face_id_", nil)];
  75. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  76. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  77. [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
  78. [section addFormRow:row];
  79. // Lock no screen
  80. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"notPasscodeAtStart" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_lock_protection_no_screen_", nil)];
  81. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  82. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  83. [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
  84. [section addFormRow:row];
  85. // Privacy screen
  86. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"privacyScreen" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_privacy_screen_", nil)];
  87. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  88. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  89. [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
  90. [section addFormRow:row];
  91. // Reset app wrong attemps
  92. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"resetAppAttemps" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_reset_wrong_passcode_", nil)];
  93. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  94. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  95. [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
  96. [section addFormRow:row];
  97. // Section : CALDAV CARDAV --------------------------------------------------------------
  98. if (!NCBrandOptions.shared.disable_mobileconfig) {
  99. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_calendar_contacts_", nil)];
  100. [form addFormSection:section];
  101. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"caldavcardav" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_mobile_config_", nil)];
  102. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  103. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  104. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  105. [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
  106. [row.cellConfig setObject:[[UIImage imageNamed:@"caldavcardav"] imageWithColor:UIColor.systemGrayColor size:25] forKey:@"imageView.image"];
  107. row.action.formSelector = @selector(CalDAVCardDAV:);
  108. [section addFormRow:row];
  109. }
  110. // Section : E2EEncryption --------------------------------------------------------------
  111. BOOL isE2EEEnabled = [[NCGlobal shared] capabilityE2EEEnabled];
  112. NSString *versionE2EE = [[NCGlobal shared] capabilityE2EEApiVersion];
  113. if (isE2EEEnabled == YES && [NCGlobal.shared.e2eeVersions containsObject:versionE2EE]) {
  114. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_e2e_settings_title_", nil)];
  115. [form addFormSection:section];
  116. // EndToEnd Encryption
  117. NSString *title = [NSString stringWithFormat:@"%@",NSLocalizedString(@"_e2e_settings_", nil)];
  118. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"e2eEncryption" rowType:XLFormRowDescriptorTypeButton title:title];
  119. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  120. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  121. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  122. [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
  123. [row.cellConfig setObject:[[UIImage imageNamed:@"lock"] imageWithColor:UIColor.systemGrayColor size:25] forKey:@"imageView.image"];
  124. row.action.formSelector = @selector(manageE2EE:);
  125. [section addFormRow:row];
  126. }
  127. // Section Advanced -------------------------------------------------
  128. section = [XLFormSectionDescriptor formSection];
  129. [form addFormSection:section];
  130. // Advanced
  131. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"advanced" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_advanced_", nil)];
  132. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  133. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  134. [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
  135. [row.cellConfig setObject:[[UIImage imageNamed:@"gear"] imageWithColor:UIColor.systemGrayColor size:25] forKey:@"imageView.image"];
  136. row.action.viewControllerClass = [CCAdvanced class];
  137. [section addFormRow:row];
  138. // Section : INFORMATION ------------------------------------------------
  139. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_information_", nil)];
  140. [form addFormSection:section];
  141. // Acknowledgements
  142. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"buttonLeftAligned" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_acknowledgements_", nil)];
  143. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  144. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  145. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  146. [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
  147. [row.cellConfig setObject:[[UIImage imageNamed:@"acknowledgements"] imageWithColor:UIColor.systemGrayColor size:25] forKey:@"imageView.image"];
  148. row.action.formBlock = ^(XLFormRowDescriptor * sender){
  149. [self performSegueWithIdentifier:@"AcknowledgementsSegue" sender:sender];
  150. [self deselectFormRow:sender];
  151. };
  152. [section addFormRow:row];
  153. if (!NCBrandOptions.shared.disable_crash_service) {
  154. // Privacy and Legal Policy
  155. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"privacy" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_privacy_legal_", nil)];
  156. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  157. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  158. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  159. [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
  160. [row.cellConfig setObject:[[UIImage imageNamed:@"shield.checkerboard"] imageWithColor:UIColor.systemGrayColor size:25] forKey:@"imageView.image"];
  161. row.action.formSelector = @selector(privacy:);
  162. [section addFormRow:row];
  163. // Source code
  164. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sourcecode" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_source_code_", nil)];
  165. row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
  166. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  167. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  168. [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
  169. [row.cellConfig setObject:[[UIImage imageNamed:@"gitHub"] imageWithColor:UIColor.systemGrayColor size:25] forKey:@"imageView.image"];
  170. row.action.formSelector = @selector(sourceCode:);
  171. [section addFormRow:row];
  172. }
  173. self.tableView.showsVerticalScrollIndicator = NO;
  174. self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 35, 0);
  175. self.form = form;
  176. }
  177. // MARK: - View Life Cycle
  178. - (void)viewDidLoad
  179. {
  180. [super viewDidLoad];
  181. self.title = NSLocalizedString(@"_settings_", nil);
  182. self.view.backgroundColor = UIColor.systemGroupedBackgroundColor;
  183. self.tableView.backgroundColor = UIColor.systemGroupedBackgroundColor;
  184. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  185. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground) name:NCGlobal.shared.notificationCenterApplicationDidEnterBackground object:nil];
  186. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeUser) name:NCGlobal.shared.notificationCenterChangeUser object:nil];
  187. [self initializeForm];
  188. [self reloadForm];
  189. }
  190. - (void)viewWillAppear:(BOOL)animated
  191. {
  192. [super viewWillAppear:animated];
  193. appDelegate.activeViewController = self;
  194. versionServer = [[NCGlobal shared] capabilityServerVersion];
  195. themingName = [[NCGlobal shared] capabilityThemingName];
  196. themingSlogan = [[NCGlobal shared] capabilityThemingSlogan];
  197. }
  198. #pragma mark - NotificationCenter
  199. - (void)changeUser
  200. {
  201. [self initializeForm];
  202. [self reloadForm];
  203. }
  204. - (void)applicationDidEnterBackground
  205. {
  206. if (passcodeViewController.view.window != nil) {
  207. [passcodeViewController dismissViewControllerAnimated:true completion:nil];
  208. }
  209. if (passcodeSettingsViewController.view.window != nil) {
  210. [passcodeSettingsViewController dismissViewControllerAnimated:true completion:nil];
  211. }
  212. [[self navigationController] popToRootViewControllerAnimated:false];
  213. }
  214. #pragma mark -
  215. - (void)reloadForm
  216. {
  217. self.form.delegate = nil;
  218. // ------------------------------------------------------------------
  219. XLFormRowDescriptor *rowBloccoPasscode = [self.form formRowWithTag:@"bloccopasscode"];
  220. XLFormRowDescriptor *rowNotPasscodeAtStart = [self.form formRowWithTag:@"notPasscodeAtStart"];
  221. XLFormRowDescriptor *rowEnableTouchDaceID = [self.form formRowWithTag:@"enableTouchDaceID"];
  222. XLFormRowDescriptor *rowResetAppAttemps = [self.form formRowWithTag:@"resetAppAttemps"];
  223. XLFormRowDescriptor *rowPrivacyScreen = [self.form formRowWithTag:@"privacyScreen"];
  224. // ------------------------------------------------------------------
  225. if ([[NCKeychain alloc] init].passcode) {
  226. rowBloccoPasscode.title = NSLocalizedString(@"_lock_active_", nil);
  227. [rowBloccoPasscode.cellConfig setObject:[[UIImage imageNamed:@"lock"] imageWithColor:UIColor.systemGrayColor size:25] forKey:@"imageView.image"];
  228. } else {
  229. rowBloccoPasscode.title = NSLocalizedString(@"_lock_not_active_", nil);
  230. [rowBloccoPasscode.cellConfig setObject:[[UIImage imageNamed:@"lock_open"] imageWithColor:UIColor.systemGrayColor size:25] forKey:@"imageView.image"];
  231. }
  232. if ([[NCKeychain alloc] init].resetAppCounterFail) [rowResetAppAttemps setValue:@1]; else [rowResetAppAttemps setValue:@0];
  233. if ([[NCKeychain alloc] init].touchFaceID) [rowEnableTouchDaceID setValue:@1]; else [rowEnableTouchDaceID setValue:@0];
  234. if ([[NCKeychain alloc] init].requestPasscodeAtStart) [rowNotPasscodeAtStart setValue:@0]; else [rowNotPasscodeAtStart setValue:@1];
  235. if ([[NCKeychain alloc] init].privacyScreenEnabled) [rowPrivacyScreen setValue:@1]; else [rowPrivacyScreen setValue:@0];
  236. // -----------------------------------------------------------------
  237. [self.tableView reloadData];
  238. self.form.delegate = self;
  239. }
  240. - (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  241. {
  242. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  243. if ([rowDescriptor.tag isEqualToString:@"notPasscodeAtStart"]) {
  244. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  245. [[NCKeychain alloc] init].requestPasscodeAtStart = false;
  246. } else {
  247. [[NCKeychain alloc] init].requestPasscodeAtStart = true;
  248. }
  249. }
  250. if ([rowDescriptor.tag isEqualToString:@"enableTouchDaceID"]) {
  251. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  252. [[NCKeychain alloc] init].touchFaceID = true;
  253. } else {
  254. [[NCKeychain alloc] init].touchFaceID = false;
  255. }
  256. }
  257. if ([rowDescriptor.tag isEqualToString:@"privacyScreen"]) {
  258. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  259. [[NCKeychain alloc] init].privacyScreenEnabled = true;
  260. } else {
  261. [[NCKeychain alloc] init].privacyScreenEnabled = false;
  262. }
  263. }
  264. if ([rowDescriptor.tag isEqualToString:@"resetAppAttemps"]) {
  265. NSInteger value = [[rowDescriptor.value valueData] intValue];
  266. [[NCKeychain alloc] init].resetAppCounterFail = value;
  267. }
  268. }
  269. #pragma mark -
  270. - (void)manageE2EE:(XLFormRowDescriptor *)sender
  271. {
  272. [self deselectFormRow:sender];
  273. UIViewController *vc = [[NCManageE2EEInterface alloc] makeShipDetailsUIWithAccount:appDelegate.account];
  274. [self.navigationController pushViewController:vc animated:YES];
  275. }
  276. - (void)privacy:(XLFormRowDescriptor *)sender
  277. {
  278. [self deselectFormRow:sender];
  279. NCBrowserWeb* browserWebVC = [[UIStoryboard storyboardWithName:@"NCBrowserWeb" bundle:nil] instantiateInitialViewController];
  280. browserWebVC.urlBase = NCBrandOptions.shared.privacy;
  281. browserWebVC.isHiddenButtonExit = false;
  282. browserWebVC.titleBrowser = NSLocalizedString(@"_privacy_", nil);
  283. [self presentViewController:browserWebVC animated:YES completion:nil];
  284. }
  285. - (void)sourceCode:(XLFormRowDescriptor *)sender
  286. {
  287. [self deselectFormRow:sender];
  288. NCBrowserWeb* browserWebVC = [[UIStoryboard storyboardWithName:@"NCBrowserWeb" bundle:nil] instantiateInitialViewController];
  289. browserWebVC.urlBase = NCBrandOptions.shared.sourceCode;
  290. browserWebVC.isHiddenButtonExit = false;
  291. browserWebVC.titleBrowser = NSLocalizedString(@"_source_code_", nil);
  292. [self presentViewController:browserWebVC animated:YES completion:nil];
  293. }
  294. - (void)CalDAVCardDAV:(XLFormRowDescriptor *)sender
  295. {
  296. [self deselectFormRow:sender];
  297. NSString *url = [appDelegate.urlBase stringByAppendingString:NCBrandOptions.shared.mobileconfig];
  298. NCConfigServer *configServer = [NCConfigServer new];
  299. [configServer startServiceWithUrl:[NSURL URLWithString: url]];
  300. }
  301. #pragma mark - Passcode
  302. - (void)didPerformBiometricValidationRequestInPasscodeViewController:(TOPasscodeViewController *)passcodeViewController
  303. {
  304. [[LAContext new] evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:[[NCBrandOptions shared] brand] reply:^(BOOL success, NSError * _Nullable error) {
  305. if (success) {
  306. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  307. [[NCKeychain alloc] init].passcode = nil;
  308. [passcodeViewController dismissViewControllerAnimated:YES completion:nil];
  309. [self reloadForm];
  310. });
  311. }
  312. }];
  313. }
  314. - (void)passcodeSettingsViewController:(TOPasscodeSettingsViewController *)passcodeSettingsViewController didChangeToNewPasscode:(NSString *)passcode ofType:(TOPasscodeType)type
  315. {
  316. [[NCKeychain alloc] init].passcode = passcode;
  317. [passcodeSettingsViewController dismissViewControllerAnimated:YES completion:nil];
  318. [self reloadForm];
  319. }
  320. - (void)didTapCancelInPasscodeViewController:(TOPasscodeViewController *)passcodeViewController
  321. {
  322. [passcodeViewController dismissViewControllerAnimated:YES completion:nil];
  323. }
  324. - (BOOL)passcodeViewController:(TOPasscodeViewController *)passcodeViewController isCorrectCode:(NSString *)code
  325. {
  326. if ([code isEqualToString:[[NCKeychain alloc] init].passcode]) {
  327. [[NCKeychain alloc] init].passcode = nil;
  328. [self reloadForm];
  329. return YES;
  330. }
  331. return NO;
  332. }
  333. - (void)passcode:(XLFormRowDescriptor *)sender
  334. {
  335. LAContext *laContext = [LAContext new];
  336. NSError *error;
  337. [self deselectFormRow:sender];
  338. if ([[NCKeychain alloc] init].passcode) {
  339. passcodeViewController = [[TOPasscodeViewController alloc] initPasscodeType:TOPasscodeTypeSixDigits allowCancel:true];
  340. passcodeViewController.delegate = self;
  341. passcodeViewController.keypadButtonShowLettering = false;
  342. if ([[NCKeychain alloc] init].touchFaceID && [laContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
  343. if (error == NULL) {
  344. if (laContext.biometryType == LABiometryTypeFaceID) {
  345. passcodeViewController.biometryType = TOPasscodeBiometryTypeFaceID;
  346. passcodeViewController.allowBiometricValidation = true;
  347. passcodeViewController.automaticallyPromptForBiometricValidation = true;
  348. } else if (laContext.biometryType == LABiometryTypeTouchID) {
  349. passcodeViewController.biometryType = TOPasscodeBiometryTypeTouchID;
  350. passcodeViewController.allowBiometricValidation = true;
  351. passcodeViewController.automaticallyPromptForBiometricValidation = true;
  352. } else {
  353. NSLog(@"No Biometric support");
  354. }
  355. }
  356. }
  357. [self presentViewController:passcodeViewController animated:YES completion:nil];
  358. } else {
  359. passcodeSettingsViewController = [[TOPasscodeSettingsViewController alloc] init];
  360. passcodeSettingsViewController.hideOptionsButton = YES;
  361. passcodeSettingsViewController.requireCurrentPasscode = NO;
  362. passcodeSettingsViewController.passcodeType = TOPasscodeTypeSixDigits;
  363. passcodeSettingsViewController.delegate = self;
  364. [self presentViewController:passcodeSettingsViewController animated:YES completion:nil];
  365. }
  366. }
  367. #pragma mark -
  368. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  369. return NCGlobal.shared.heightCellSettings;
  370. }
  371. - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
  372. {
  373. NSString *sectionName;
  374. NSInteger numSections = [tableView numberOfSections] - 1;
  375. if (section == 1) {
  376. NSString *reset = [NSString stringWithFormat:NSLocalizedString(@"_reset_wrong_passcode_desc_", nil), NCBrandOptions.shared.resetAppPasscodeAttempts];
  377. NSString *lock = NSLocalizedString(@"_lock_protection_no_screen_footer_", nil);
  378. sectionName = [NSString stringWithFormat:@"%@\n%@", reset, lock];
  379. } else if (section == 2 && !NCBrandOptions.shared.disable_mobileconfig) {
  380. sectionName = NSLocalizedString(@"_calendar_contacts_footer_", nil);
  381. } else if (section == numSections) {
  382. NSString *versionNextcloud = [NSString stringWithFormat:[NCBrandOptions shared].textCopyrightNextcloudServer, versionServer];
  383. NSString *versionNextcloudiOS = [NSString stringWithFormat:[NCBrandOptions shared].textCopyrightNextcloudiOS, [[[NCUtility alloc] init] getVersionAppWithBuild:true]];
  384. NSString *nameSlogan = [NSString stringWithFormat:@"%@ - %@", themingName, themingSlogan];
  385. sectionName = [NSString stringWithFormat:@"\n%@\n\n%@\n%@", versionNextcloudiOS, versionNextcloud, nameSlogan];
  386. }
  387. return sectionName;
  388. }
  389. @end