CCSettings.m 32 KB

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