CCSettings.m 27 KB

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