CCManageCryptoCloudSecurity.m 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 mail
  41. form = [XLFormDescriptor formDescriptor];
  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. - (void)viewDidLoad
  78. {
  79. [super viewDidLoad];
  80. self.navigationItem.title = NSLocalizedString(@"_title_form_security_init_", nil);
  81. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
  82. }
  83. -(void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  84. {
  85. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  86. }
  87. #pragma --------------------------------------------------------------------------------------------
  88. #pragma mark - ==== Done ====
  89. #pragma --------------------------------------------------------------------------------------------
  90. - (void)donePressed
  91. {
  92. XLFormRowDescriptor *rowMail = [self.form formRowWithTag:@"mail"];
  93. XLFormRowDescriptor *rowHint = [self.form formRowWithTag:@"hint"];
  94. if ([CCUtility isValidEmail:rowMail.value])
  95. [CCUtility setEmail:(NSString *)rowMail.value];
  96. else
  97. [CCUtility setEmail:@""];
  98. if ([rowHint.value length] >0)
  99. [CCUtility setHint:(NSString *)rowHint.value];
  100. else
  101. [CCUtility setHint:@""];
  102. [self.delegate closeCryptoCloudSecurity];
  103. [self dismissViewControllerAnimated:YES completion:nil];
  104. }
  105. #pragma --------------------------------------------------------------------------------------------
  106. #pragma mark === Mail ===
  107. #pragma --------------------------------------------------------------------------------------------
  108. - (void) mailComposeController:(MFMailComposeViewController *)vc didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
  109. {
  110. switch (result) {
  111. case MFMailComposeResultCancelled:
  112. [app messageNotification:@"_info_" description:@"_mail_deleted_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  113. break;
  114. case MFMailComposeResultSaved:
  115. [app messageNotification:@"_info_" description:@"_mail_saved_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  116. break;
  117. case MFMailComposeResultSent:
  118. [app messageNotification:@"_info_" description:@"_mail_sent_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  119. break;
  120. case MFMailComposeResultFailed: {
  121. NSString *msg = [NSString stringWithFormat:NSLocalizedString(@"_mail_failure_", nil), [error localizedDescription]];
  122. [app messageNotification:@"_error_" description:msg visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  123. }
  124. break;
  125. default:
  126. break;
  127. }
  128. // Close the Mail Interface
  129. [self dismissViewControllerAnimated:YES completion:NULL];
  130. // Close
  131. [self donePressed];
  132. }
  133. - (void)sendMailEncryptPass:(XLFormRowDescriptor *)sender
  134. {
  135. [self deselectFormRow:sender];
  136. XLFormRowDescriptor *row = [self.form formRowWithTag:@"mail"];
  137. [CCUtility sendMailEncryptPass:row.value validateEmail:YES form:self];
  138. }
  139. @end