CCManageCryptoCloudSecurity.m 7.3 KB

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