CCSettings.m 26 KB

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