NCSettings.m 23 KB

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