CCManageCryptoCloudSecurity.m 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. //
  2. // CCManageCryptoCloudSecurity.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 31/03/16.
  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 "CCManageCryptoCloudSecurity.h"
  24. #import "AppDelegate.h"
  25. @interface CCManageCryptoCloudSecurity()
  26. {
  27. NSTimer* myTimer;
  28. NSMutableDictionary *field;
  29. }
  30. @end
  31. @implementation CCManageCryptoCloudSecurity
  32. - (id)initWithDelegate:(id <CCManageCryptoCloudSecurityDelegate>)delegate
  33. {
  34. self = [super init];
  35. if (self){
  36. self.delegate = delegate;
  37. XLFormDescriptor * form ;
  38. XLFormSectionDescriptor *section;
  39. XLFormRowDescriptor *row;
  40. form = [XLFormDescriptor formDescriptorWithTitle:NSLocalizedString(@"_title_form_security_init_", nil)];
  41. // form mail
  42. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_security_init_required_mail_", nil)];
  43. [form addFormSection:section];
  44. form.assignFirstResponderOnShow = YES;
  45. form.rowNavigationOptions = XLFormRowNavigationOptionNone;
  46. // mail
  47. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"mail" rowType:XLFormRowDescriptorTypeEmail title:NSLocalizedString(@"_email_", nil)];
  48. [row.cellConfig setObject:COLOR_TEXT_ANTHRACITE forKey:@"textField.textColor"];
  49. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  50. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  51. [section addFormRow:row];
  52. section = [XLFormSectionDescriptor formSection];
  53. [form addFormSection:section];
  54. // Send aes-256 password via mail
  55. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sendmailencryptpass" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_encryptpass_by_email_", nil)];
  56. [row.cellConfig setObject:@(NSTextAlignmentCenter) forKey:@"textLabel.textAlignment"];
  57. [row.cellConfig setObject:COLOR_CRYPTOCLOUD forKey:@"textLabel.textColor"];
  58. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  59. [row.cellConfig setObject:[UIImage imageNamed:image_settingsKeyMail] forKey:@"imageView.image"];
  60. row.action.formSelector = @selector(sendMailEncryptPass:);
  61. //row.disabled = @1;
  62. [section addFormRow:row];
  63. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_security_init_required_hint_", nil)];
  64. [form addFormSection:section];
  65. // hint
  66. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"hint" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_hint_", nil)];
  67. [row.cellConfig setObject:COLOR_TEXT_ANTHRACITE forKey:@"textField.textColor"];
  68. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  69. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  70. row.value = [CCUtility getHint];
  71. [section addFormRow:row];
  72. self.form = form;
  73. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(donePressed)];
  74. }
  75. return self;
  76. }
  77. // Apparirà
  78. - (void)viewWillAppear:(BOOL)animated
  79. {
  80. [super viewWillAppear:animated];
  81. self.tableView.backgroundColor = COLOR_TABLE_BACKGROUND;
  82. // Color
  83. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
  84. [CCAspect aspectTabBar:self.tabBarController.tabBar hidden:NO];
  85. }
  86. -(void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  87. {
  88. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  89. }
  90. #pragma --------------------------------------------------------------------------------------------
  91. #pragma mark - ==== Done ====
  92. #pragma --------------------------------------------------------------------------------------------
  93. - (void)donePressed
  94. {
  95. XLFormRowDescriptor *rowMail = [self.form formRowWithTag:@"mail"];
  96. XLFormRowDescriptor *rowHint = [self.form formRowWithTag:@"hint"];
  97. if ([CCUtility isValidEmail:rowMail.value])
  98. [CCUtility setEmail:(NSString *)rowMail.value];
  99. else
  100. [CCUtility setEmail:@""];
  101. if ([rowHint.value length] >0)
  102. [CCUtility setHint:(NSString *)rowHint.value];
  103. else
  104. [CCUtility setHint:@""];
  105. [self.delegate closeCryptoCloudSecurity];
  106. [self dismissViewControllerAnimated:YES completion:nil];
  107. }
  108. #pragma --------------------------------------------------------------------------------------------
  109. #pragma mark === Mail ===
  110. #pragma --------------------------------------------------------------------------------------------
  111. - (void) mailComposeController:(MFMailComposeViewController *)vc didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
  112. {
  113. switch (result) {
  114. case MFMailComposeResultCancelled:
  115. [app messageNotification:@"_info_" description:@"_mail_deleted_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  116. break;
  117. case MFMailComposeResultSaved:
  118. [app messageNotification:@"_info_" description:@"_mail_saved_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  119. break;
  120. case MFMailComposeResultSent:
  121. [app messageNotification:@"_info_" description:@"_mail_sent_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  122. break;
  123. case MFMailComposeResultFailed: {
  124. NSString *msg = [NSString stringWithFormat:NSLocalizedString(@"_mail_failure_", nil), [error localizedDescription]];
  125. [app messageNotification:@"_error_" description:msg visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  126. }
  127. break;
  128. default:
  129. break;
  130. }
  131. // Close the Mail Interface
  132. [self dismissViewControllerAnimated:YES completion:NULL];
  133. // Close
  134. [self donePressed];
  135. }
  136. - (void)sendMailEncryptPass:(XLFormRowDescriptor *)sender
  137. {
  138. [self deselectFormRow:sender];
  139. XLFormRowDescriptor *row = [self.form formRowWithTag:@"mail"];
  140. [CCUtility sendMailEncryptPass:row.value validateEmail:YES form:self];
  141. }
  142. @end