CCSettings.m 28 KB

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