CCManageCryptoCloudSecurity.m 7.3 KB

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