NCSettings.m 23 KB

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