CCSettings.m 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. //
  2. // CCSettings.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 24/11/14.
  6. // Copyright (c) 2017 TWS. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  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 "CCSettings.h"
  24. #import "AppDelegate.h"
  25. #import "CCMain.h"
  26. #import "OCCapabilities.h"
  27. #import "CCSynchronize.h"
  28. #import "CCAdvanced.h"
  29. #import "CCManageCryptoCloud.h"
  30. #import "CCManageAccount.h"
  31. #import "NCBridgeSwift.h"
  32. #define alertViewEsci 1
  33. #define alertViewAzzeraCache 2
  34. @implementation CCSettings
  35. - (id)initWithCoder:(NSCoder *)aDecoder
  36. {
  37. self = [super initWithCoder:aDecoder];
  38. if (self) {
  39. [self initializeForm];
  40. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
  41. app.activeSettings = self;
  42. }
  43. return self;
  44. }
  45. - (void)initializeForm
  46. {
  47. XLFormDescriptor *form;
  48. XLFormSectionDescriptor *section;
  49. XLFormRowDescriptor *row;
  50. form = [XLFormDescriptor formDescriptorWithTitle:NSLocalizedString(@"_settings_", nil)];
  51. form.rowNavigationOptions = XLFormRowNavigationOptionNone;
  52. // Section AUTOMATIC UPLOAD OF CAMERA IMAGES ----------------------------
  53. section = [XLFormSectionDescriptor formSection];
  54. [form addFormSection:section];
  55. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"cameraupload" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_uploading_from_camera_", nil)];
  56. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  57. [row.cellConfig setObject:[UIImage imageNamed:@"settingsCameraUpload"] forKey:@"imageView.image"];
  58. row.action.formSegueIdentifier = @"CCManageCameraUploadSegue";
  59. [section addFormRow:row];
  60. // Section FOLDERS FAVORITES OFFLINE ------------------------------------
  61. section = [XLFormSectionDescriptor formSection];
  62. [form addFormSection:section];
  63. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"favoriteoffline" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_favorite_offline_", nil)];
  64. [row.cellConfig setObject:[UIImage imageNamed:@"settingsFavoriteOffline"] forKey:@"imageView.image"];
  65. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  66. [section addFormRow:row];
  67. // Section : PASSWORD --------------------------------------------------------------
  68. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_passcode_", nil)];
  69. [form addFormSection:section];
  70. // Passcode
  71. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"bloccopasscode" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_lock_not_active_", nil)];
  72. [row.cellConfig setObject:[UIImage imageNamed:@"settingsPasscodeNO"] forKey:@"imageView.image"];
  73. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  74. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
  75. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  76. //[row.cellConfig setObject:@(UITableViewCellAccessoryDisclosureIndicator) forKey:@"accessoryType"];
  77. row.action.formSelector = @selector(bloccoPassword);
  78. [section addFormRow:row];
  79. // Passcode simply
  80. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"simplypasscode" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_lock_protection_simply_", nil)];
  81. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  82. [section addFormRow:row];
  83. // Passcode only directory
  84. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"onlylockdir" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_lock_protection_folder_", nil)];
  85. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  86. [section addFormRow:row];
  87. // Section CRYPTO CLOUD SYSTEM ------------------------------------------
  88. // Brand
  89. if ([NCBrandOptions sharedInstance].disable_cryptocloudsystem == NO) {
  90. section = [XLFormSectionDescriptor formSection];
  91. [form addFormSection:section];
  92. // Crypto Cloud
  93. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"cryptocloud" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_crypto_cloud_system_", nil)];
  94. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  95. [row.cellConfig setObject:[UIImage imageNamed:@"settingsCryptoCloud"] forKey:@"imageView.image"];
  96. row.action.viewControllerClass = [CCManageCryptoCloud class];
  97. [section addFormRow:row];
  98. }
  99. // Section Advanced -------------------------------------------------
  100. section = [XLFormSectionDescriptor formSection];
  101. [form addFormSection:section];
  102. // Advanced
  103. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"advanced" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_advanced_", nil)];
  104. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  105. [row.cellConfig setObject:[UIImage imageNamed:@"settingsAdvanced"] forKey:@"imageView.image"];
  106. row.action.viewControllerClass = [CCAdvanced class];
  107. [section addFormRow:row];
  108. // Section : INFORMATION ------------------------------------------------
  109. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_information_", nil)];
  110. [form addFormSection:section];
  111. // Acknowledgements
  112. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"buttonLeftAligned" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_acknowledgements_", nil)];
  113. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  114. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  115. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
  116. [row.cellConfig setObject:[UIImage imageNamed:@"settingsAcknowledgements"] forKey:@"imageView.image"];
  117. row.action.formBlock = ^(XLFormRowDescriptor * sender){
  118. [self performSegueWithIdentifier:@"AcknowledgementsSegue" sender:sender];
  119. [self deselectFormRow:sender];
  120. };
  121. [section addFormRow:row];
  122. // Contact us mail
  123. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sendmail" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_contact_by_email_", nil)];
  124. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
  125. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  126. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  127. [row.cellConfig setObject:[UIImage imageNamed:@"settingsMail"] forKey:@"imageView.image"];
  128. row.action.formSelector = @selector(sendMail:);
  129. [section addFormRow:row];
  130. self.form = form;
  131. }
  132. // Apparirà
  133. - (void)viewWillAppear:(BOOL)animated
  134. {
  135. [super viewWillAppear:animated];
  136. self.tableView.backgroundColor = [NCBrandColor sharedInstance].tableBackground;
  137. // Color
  138. [app aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
  139. [app aspectTabBar:self.tabBarController.tabBar hidden:NO];
  140. [self reloadForm];
  141. }
  142. - (void)changeTheming
  143. {
  144. if (self.isViewLoaded && self.view.window)
  145. [app changeTheming:self];
  146. }
  147. #pragma --------------------------------------------------------------------------------------------
  148. #pragma mark === Chiamate dal Form ===
  149. #pragma --------------------------------------------------------------------------------------------
  150. - (void)reloadForm
  151. {
  152. self.form.delegate = nil;
  153. // ----------------------
  154. XLFormRowDescriptor *rowBloccoPasscode = [self.form formRowWithTag:@"bloccopasscode"];
  155. XLFormRowDescriptor *rowSimplyPasscode = [self.form formRowWithTag:@"simplypasscode"];
  156. XLFormRowDescriptor *rowOnlyLockDir = [self.form formRowWithTag:@"onlylockdir"];
  157. XLFormRowDescriptor *rowFavoriteOffline = [self.form formRowWithTag:@"favoriteoffline"];
  158. // ------------------------------------------------------------------
  159. if ([[CCUtility getBlockCode] length]) {
  160. rowBloccoPasscode.title = NSLocalizedString(@"_lock_active_", nil);
  161. [rowBloccoPasscode.cellConfig setObject:[UIImage imageNamed:@"settingsPasscodeYES"] forKey:@"imageView.image"];
  162. } else {
  163. rowBloccoPasscode.title = NSLocalizedString(@"_lock_not_active_", nil);
  164. [rowBloccoPasscode.cellConfig setObject:[UIImage imageNamed:@"settingsPasscodeNO"] forKey:@"imageView.image"];
  165. }
  166. if ([CCUtility getSimplyBlockCode]) [rowSimplyPasscode setValue:@1]; else [rowSimplyPasscode setValue:@0];
  167. if ([CCUtility getOnlyLockDir]) [rowOnlyLockDir setValue:@1]; else [rowOnlyLockDir setValue:@0];
  168. if ([CCUtility getFavoriteOffline]) [rowFavoriteOffline setValue:@1]; else [rowFavoriteOffline setValue:@0];
  169. // -----------------------------------------------------------------
  170. [self.tableView reloadData];
  171. self.form.delegate = self;
  172. }
  173. - (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  174. {
  175. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  176. if ([rowDescriptor.tag isEqualToString:@"onlylockdir"]) {
  177. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  178. [CCUtility setOnlyLockDir:true];
  179. } else {
  180. [CCUtility setOnlyLockDir:false];
  181. }
  182. }
  183. if ([rowDescriptor.tag isEqualToString:@"simplypasscode"]) {
  184. if ([[CCUtility getBlockCode] length] == 0)
  185. [CCUtility setSimplyBlockCode:[[rowDescriptor.value valueData] boolValue]];
  186. else
  187. [self changeSimplyPassword];
  188. }
  189. if ([rowDescriptor.tag isEqualToString:@"favoriteoffline"]) {
  190. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  191. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:NSLocalizedString(@"_continue_", nil) preferredStyle:UIAlertControllerStyleActionSheet];
  192. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  193. [CCUtility setFavoriteOffline:true];
  194. [self synchronizeFavorites];
  195. }]];
  196. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  197. [self reloadForm];
  198. }]];
  199. //if iPhone
  200. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  201. [self presentViewController:alertController animated:YES completion:nil];
  202. }
  203. //if iPad
  204. else {
  205. // Change Rect to position Popover
  206. UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:alertController];
  207. [popup presentPopoverFromRect:[self.tableView rectForRowAtIndexPath:[self.form indexPathOfFormRow:rowDescriptor]] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  208. }
  209. } else {
  210. [CCUtility setFavoriteOffline:false];
  211. }
  212. }
  213. }
  214. - (void)checkEncryptPass:(XLFormRowDescriptor *)sender
  215. {
  216. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  217. viewController.delegate = self;
  218. viewController.fromType = CCBKPasscodeFromCheckCryptoKey;
  219. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  220. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  221. viewController.passcodeInputView.maximumLength = 64;
  222. viewController.title = NSLocalizedString(@"_check_key_aes_256_", nil);
  223. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  224. viewController.navigationItem.leftBarButtonItem.tintColor = [NCBrandColor sharedInstance].cryptocloud;
  225. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  226. [self presentViewController:navigationController animated:YES completion:nil];
  227. }
  228. - (void)changeSimplyPassword
  229. {
  230. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  231. viewController.delegate = self;
  232. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  233. viewController.fromType = CCBKPasscodeFromSimply;
  234. viewController.title = NSLocalizedString(@"_change_simply_passcode_", nil);
  235. viewController.inputViewTitlePassword = YES;
  236. if ([CCUtility getSimplyBlockCode]) {
  237. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  238. viewController.passcodeInputView.maximumLength = 6;
  239. } else {
  240. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  241. viewController.passcodeInputView.maximumLength = 64;
  242. }
  243. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
  244. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  245. viewController.touchIDManager = touchIDManager;
  246. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  247. viewController.navigationItem.leftBarButtonItem.tintColor = [NCBrandColor sharedInstance].cryptocloud;
  248. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  249. [self presentViewController:navigationController animated:YES completion:nil];
  250. }
  251. - (void)bloccoPassword
  252. {
  253. // ATTIVAZIONE LOCK PASSWORD
  254. if ([[CCUtility getBlockCode] length] == 0) {
  255. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  256. viewController.delegate = self;
  257. viewController.type = BKPasscodeViewControllerNewPasscodeType;
  258. viewController.fromType = CCBKPasscodeFromSettingsPasscode;
  259. viewController.inputViewTitlePassword = YES;
  260. if ([CCUtility getSimplyBlockCode]) {
  261. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  262. viewController.passcodeInputView.maximumLength = 6;
  263. } else {
  264. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  265. viewController.passcodeInputView.maximumLength = 64;
  266. }
  267. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
  268. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  269. viewController.touchIDManager = touchIDManager;
  270. viewController.title = NSLocalizedString(@"_passcode_activate_", nil);
  271. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  272. viewController.navigationItem.leftBarButtonItem.tintColor = [NCBrandColor sharedInstance].cryptocloud;
  273. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  274. [self presentViewController:navigationController animated:YES completion:nil];
  275. } else {
  276. // OFF LOCK PASSWORD
  277. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  278. viewController.delegate = self;
  279. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  280. viewController.fromType = CCBKPasscodeFromSettingsPasscode;
  281. viewController.inputViewTitlePassword = YES;
  282. if ([CCUtility getSimplyBlockCode]) {
  283. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  284. viewController.passcodeInputView.maximumLength = 6;
  285. } else {
  286. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  287. viewController.passcodeInputView.maximumLength = 64;
  288. }
  289. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
  290. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  291. viewController.touchIDManager = touchIDManager;
  292. viewController.title = NSLocalizedString(@"_disabling_passcode_", nil);
  293. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  294. viewController.navigationItem.leftBarButtonItem.tintColor = [NCBrandColor sharedInstance].cryptocloud;
  295. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  296. [self presentViewController:navigationController animated:YES completion:nil];
  297. }
  298. }
  299. - (void)synchronizeFavorites
  300. {
  301. NSArray *recordsTableMetadata = [CCCoreData getTableMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (favorite == 1)", app.activeAccount] context:nil];
  302. for (TableMetadata *tableMetadata in recordsTableMetadata) {
  303. if ([tableMetadata.directory boolValue]) {
  304. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:tableMetadata.directoryID activeAccount:app.activeAccount];
  305. serverUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:tableMetadata.fileNamePrint];
  306. NSArray *TableDirectories = [CCCoreData getDirectoryIDsFromBeginsWithServerUrl:serverUrl activeAccount:app.activeAccount];
  307. for (TableDirectory *tableDirecory in TableDirectories)
  308. [CCCoreData clearDateReadAccount:app.activeAccount serverUrl:nil directoryID:tableDirecory.directoryID];
  309. }
  310. }
  311. [[CCSynchronize sharedSynchronize] readListingFavorites];
  312. }
  313. #pragma --------------------------------------------------------------------------------------------
  314. #pragma mark === Table View ===
  315. #pragma --------------------------------------------------------------------------------------------
  316. - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
  317. {
  318. NSString *sectionName;
  319. switch (section)
  320. {
  321. case 1: {
  322. sectionName = NSLocalizedString(@"_favorite_offline_footer_", nil);
  323. }
  324. break;
  325. case 5: {
  326. tableCapabilities *capabilities = [[NCManageDatabase sharedInstance] getCapabilitesForAccount:app.activeAccount];
  327. NSString *versionServer = capabilities.versionString;
  328. NSString *versionApp = [NSString stringWithFormat:@"%@.%@", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]];
  329. NSString *versionNextcloud = [NSString stringWithFormat:[NCBrandOptions sharedInstance].textCopyrightNextcloudServer, versionServer];
  330. NSString *versionNextcloudiOS = [NSString stringWithFormat:[NCBrandOptions sharedInstance].textCopyrightNextcloudiOS, versionApp];
  331. sectionName = [NSString stringWithFormat:@"%@\n%@", versionNextcloudiOS, versionNextcloud];
  332. }
  333. break;
  334. }
  335. return sectionName;
  336. }
  337. #pragma --------------------------------------------------------------------------------------------
  338. #pragma mark === Mail ===
  339. #pragma --------------------------------------------------------------------------------------------
  340. - (void) mailComposeController:(MFMailComposeViewController *)vc didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
  341. {
  342. switch (result)
  343. {
  344. case MFMailComposeResultCancelled:
  345. [app messageNotification:@"_info_" description:@"_mail_deleted_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode:error.code];
  346. break;
  347. case MFMailComposeResultSaved:
  348. [app messageNotification:@"_info_" description:@"_mail_saved_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode:error.code];
  349. break;
  350. case MFMailComposeResultSent:
  351. [app messageNotification:@"_info_" description:@"_mail_sent_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode:error.code];
  352. break;
  353. case MFMailComposeResultFailed: {
  354. NSString *msg = [NSString stringWithFormat:NSLocalizedString(@"_mail_failure_", nil), [error localizedDescription]];
  355. [app messageNotification:@"_error_" description:msg visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  356. }
  357. break;
  358. default:
  359. break;
  360. }
  361. // Close the Mail Interface
  362. [self dismissViewControllerAnimated:YES completion:NULL];
  363. }
  364. - (void)sendMail:(XLFormRowDescriptor *)sender
  365. {
  366. // Email Subject
  367. NSString *emailTitle = NSLocalizedString(@"_information_req_", nil);
  368. // Email Content
  369. NSString *messageBody;
  370. // Email Recipents
  371. NSArray *toRecipents;
  372. messageBody = [NSString stringWithFormat:@"\n\n\n%@ Version %@ (%@)", [NCBrandOptions sharedInstance].brand, [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]];
  373. toRecipents = [NSArray arrayWithObject:[NCBrandOptions sharedInstance].mailMe];
  374. MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
  375. mc.mailComposeDelegate = self;
  376. [mc setSubject:emailTitle];
  377. [mc setMessageBody:messageBody isHTML:NO];
  378. [mc setToRecipients:toRecipents];
  379. // Present mail view controller on screen
  380. [self presentViewController:mc animated:YES completion:NULL];
  381. }
  382. - (void)sendMailEncryptPass
  383. {
  384. [CCUtility sendMailEncryptPass:[CCUtility getEmail] validateEmail:NO form:self nameImage:@"backgroundDetail"];
  385. }
  386. #pragma --------------------------------------------------------------------------------------------
  387. #pragma mark === BKPasscodeViewController ===
  388. #pragma --------------------------------------------------------------------------------------------
  389. - (void)passcodeViewController:(CCBKPasscode *)aViewController didFinishWithPasscode:(NSString *)aPasscode
  390. {
  391. [aViewController dismissViewControllerAnimated:YES completion:nil];
  392. switch (aViewController.type) {
  393. case BKPasscodeViewControllerNewPasscodeType: {
  394. // enable passcode
  395. [CCUtility setBlockCode:aPasscode];
  396. }
  397. break;
  398. case BKPasscodeViewControllerCheckPasscodeType: {
  399. // disable passcode
  400. if (aViewController.fromType == CCBKPasscodeFromSettingsPasscode) {
  401. [CCUtility setBlockCode:@""];
  402. [CCCoreData setAllDirectoryUnLockForAccount:app.activeAccount];
  403. [app.activeMain.tableView reloadData];
  404. }
  405. // email Key EAS-256
  406. if (aViewController.fromType == CCBKPasscodeFromCheckCryptoKey)
  407. [self sendMailEncryptPass];
  408. // change simply
  409. if (aViewController.fromType == CCBKPasscodeFromSimply) {
  410. // disable passcode
  411. [CCUtility setBlockCode:@""];
  412. [CCCoreData setAllDirectoryUnLockForAccount:app.activeAccount];
  413. [app.activeMain.tableView reloadData];
  414. [CCUtility setSimplyBlockCode:![CCUtility getSimplyBlockCode]];
  415. // Call new passcode
  416. [self bloccoPassword];
  417. }
  418. }
  419. break;
  420. default:
  421. break;
  422. }
  423. [self reloadForm];
  424. }
  425. - (void)passcodeViewController:(CCBKPasscode *)aViewController authenticatePasscode:(NSString *)aPasscode resultHandler:(void (^)(BOOL))aResultHandler
  426. {
  427. if (aViewController.fromType == CCBKPasscodeFromCheckCryptoKey) {
  428. NSString *key = [CCUtility getKeyChainPasscodeForUUID:[CCUtility getUUID]];
  429. if ([aPasscode isEqualToString:key]) {
  430. self.lockUntilDate = nil;
  431. self.failedAttempts = 0;
  432. aResultHandler(YES);
  433. } else aResultHandler(NO);
  434. }
  435. if (aViewController.fromType == CCBKPasscodeFromSettingsPasscode || aViewController.fromType == CCBKPasscodeFromSimply) {
  436. if ([aPasscode isEqualToString:[CCUtility getBlockCode]]) {
  437. self.lockUntilDate = nil;
  438. self.failedAttempts = 0;
  439. aResultHandler(YES);
  440. } else aResultHandler(NO);
  441. }
  442. }
  443. - (void)passcodeViewControllerDidFailAttempt:(CCBKPasscode *)aViewController
  444. {
  445. self.failedAttempts++;
  446. if (self.failedAttempts > 5) {
  447. NSTimeInterval timeInterval = 60;
  448. if (self.failedAttempts > 6) {
  449. NSUInteger multiplier = self.failedAttempts - 6;
  450. timeInterval = (5 * 60) * multiplier;
  451. if (timeInterval > 3600 * 24) {
  452. timeInterval = 3600 * 24;
  453. }
  454. }
  455. self.lockUntilDate = [NSDate dateWithTimeIntervalSinceNow:timeInterval];
  456. }
  457. }
  458. - (NSUInteger)passcodeViewControllerNumberOfFailedAttempts:(CCBKPasscode *)aViewController
  459. {
  460. return self.failedAttempts;
  461. }
  462. - (NSDate *)passcodeViewControllerLockUntilDate:(CCBKPasscode *)aViewController
  463. {
  464. return self.lockUntilDate;
  465. }
  466. - (void)passcodeViewCloseButtonPressed:(id)sender
  467. {
  468. [self dismissViewControllerAnimated:YES completion:nil];
  469. }
  470. @end