CCManageAccount.m 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. //
  2. // CCManageAccount.m
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 12/03/15.
  6. // Copyright (c) 2015 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  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 "CCManageAccount.h"
  24. #import "NSNotificationCenter+MainThread.h"
  25. #import "NCBridgeSwift.h"
  26. #import "CCUtility.h"
  27. #define actionSheetCancellaAccount 1
  28. @interface CCManageAccount ()
  29. {
  30. AppDelegate *appDelegate;
  31. }
  32. @end
  33. @implementation CCManageAccount
  34. - (void)initializeForm
  35. {
  36. XLFormDescriptor *form = [XLFormDescriptor formDescriptor];
  37. XLFormSectionDescriptor *section;
  38. XLFormRowDescriptor *row;
  39. NSArray *accounts = [[NCManageDatabase shared] getAllAccount];
  40. tableAccount *activeAccount = [[NCManageDatabase shared] getActiveAccount];
  41. // Section : ACCOUNTS -------------------------------------------
  42. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_accounts_", nil) sectionOptions:XLFormSectionOptionCanDelete];
  43. [form addFormSection:section];
  44. for (tableAccount *account in accounts) {
  45. NSString *title = [NSString stringWithFormat:@"%@ %@", account.user, [NSURL URLWithString:account.urlBase].host];
  46. row = [XLFormRowDescriptor formRowDescriptorWithTag:account.account rowType:XLFormRowDescriptorTypeBooleanCheck title:title];
  47. // Avatar
  48. NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@-%@-original.png", [CCUtility getDirectoryUserData], [CCUtility getUserUrlBase:account.user urlBase:account.urlBase], account.user];
  49. UIImage *avatar = [UIImage imageWithContentsOfFile:fileNamePath];
  50. if (avatar) {
  51. avatar = [NCUtility.shared createAvatarWithImage:avatar size:40];
  52. } else {
  53. avatar = [[UIImage imageNamed:@"avatar"] imageWithColor:NCBrandColor.shared.gray size:40];
  54. }
  55. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.secondarySystemGroupedBackground;
  56. [row.cellConfig setObject:[UIFont systemFontOfSize:13.0] forKey:@"textLabel.font"];
  57. [row.cellConfig setObject:avatar forKey:@"imageView.image"];
  58. if (account.active) {
  59. row.value = @"YES";
  60. }
  61. [section addFormRow:row];
  62. }
  63. // Section : ALIAS --------------------------------------------------
  64. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_alias_", nil)];
  65. section.footerTitle = NSLocalizedString(@"_alias_footer_", nil);
  66. [form addFormSection:section];
  67. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"alias" rowType:XLFormRowDescriptorTypeText];
  68. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.secondarySystemGroupedBackground;
  69. [row.cellConfig setObject:[[UIImage imageNamed:@"form-textbox"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
  70. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textField.font"];
  71. [row.cellConfig setObject:NCBrandColor.shared.label forKey:@"textField.textColor"];
  72. row.value = activeAccount.alias;
  73. [section addFormRow:row];
  74. // Section : REQUEST ACCOUNT -------------------------------------------
  75. if (NCBrandOptions.shared.disable_request_account == NO) {
  76. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_account_request_", nil)];
  77. [form addFormSection:section];
  78. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"accountRequest" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_settings_account_request_", nil)];
  79. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.secondarySystemGroupedBackground;
  80. [row.cellConfig setObject:[[UIImage imageNamed:@"users"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
  81. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  82. [row.cellConfig setObject:NCBrandColor.shared.label forKey:@"textLabel.textColor"];
  83. if ([CCUtility getAccountRequest]) row.value = @1;
  84. else row.value = @0;
  85. [section addFormRow:row];
  86. }
  87. // Section : MANAGE ACCOUNT -------------------------------------------
  88. if ([NCBrandOptions shared].disable_manage_account == NO) {
  89. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_manage_account_", nil)];
  90. [form addFormSection:section];
  91. // Brand
  92. if ([NCBrandOptions shared].disable_multiaccount == NO) {
  93. // New Account nextcloud
  94. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"addAccount" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_add_account_", nil)];
  95. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.secondarySystemGroupedBackground;
  96. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  97. [row.cellConfig setObject:[[UIImage imageNamed:@"plus"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
  98. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  99. [row.cellConfig setObject:NCBrandColor.shared.label forKey:@"textLabel.textColor"];
  100. row.action.formSelector = @selector(addAccount:);
  101. [section addFormRow:row];
  102. }
  103. // Set user status
  104. if (@available(iOS 13.0, *)) {
  105. BOOL userStatus = [[NCManageDatabase shared] getCapabilitiesServerBoolWithAccount:activeAccount.account elements:NCElementsJSON.shared.capabilitiesUserStatusEnabled exists:false];
  106. if (userStatus) {
  107. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"setUserStatus" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_set_user_status_", nil)];
  108. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.secondarySystemGroupedBackground;
  109. [row.cellConfig setObject:NCBrandColor.shared.label forKey:@"textLabel.textColor"];
  110. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  111. [row.cellConfig setObject:[[UIImage imageNamed:@"userStatusAway"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
  112. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  113. row.action.formSelector = @selector(setUserStatus:);
  114. if (accounts.count == 0) row.disabled = @YES;
  115. [section addFormRow:row];
  116. }
  117. }
  118. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"certificateDetails" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_certificate_details_", nil)];
  119. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.secondarySystemGroupedBackground;
  120. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  121. [row.cellConfig setObject:[[UIImage imageNamed:@"lock-question"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
  122. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  123. [row.cellConfig setObject:NCBrandColor.shared.label forKey:@"textLabel.textColor"];
  124. row.action.formSelector = @selector(certificateDetails:);
  125. [section addFormRow:row];
  126. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"certificatePNDetails" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_certificate_pn_details_", nil)];
  127. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.secondarySystemGroupedBackground;
  128. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  129. [row.cellConfig setObject:[[UIImage imageNamed:@"lock-question"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
  130. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  131. [row.cellConfig setObject:NCBrandColor.shared.label forKey:@"textLabel.textColor"];
  132. row.action.formSelector = @selector(certificatePNDetails:);
  133. [section addFormRow:row];
  134. }
  135. // Section : USER INFORMATION -------------------------------------------
  136. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_personal_information_", nil)];
  137. [form addFormSection:section];
  138. // Full Name
  139. if ([activeAccount.displayName length] > 0) {
  140. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"userfullname" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_full_name_", nil)];
  141. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.secondarySystemGroupedBackground;
  142. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  143. [row.cellConfig setObject:NCBrandColor.shared.label forKey:@"textLabel.textColor"];
  144. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"detailTextLabel.font"];
  145. [row.cellConfig setObject:[[UIImage imageNamed:@"user"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
  146. row.value = activeAccount.displayName;
  147. [section addFormRow:row];
  148. }
  149. // Address
  150. if ([activeAccount.address length] > 0) {
  151. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"useraddress" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_address_", nil)];
  152. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.secondarySystemGroupedBackground;
  153. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  154. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"detailTextLabel.font"];
  155. [row.cellConfig setObject:NCBrandColor.shared.label forKey:@"textLabel.textColor"];
  156. [row.cellConfig setObject:[[UIImage imageNamed:@"address"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
  157. row.value = activeAccount.address;
  158. [section addFormRow:row];
  159. }
  160. // City + zip
  161. if ([activeAccount.city length] > 0) {
  162. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"usercity" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_city_", nil)];
  163. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.secondarySystemGroupedBackground;
  164. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  165. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"detailTextLabel.font"];
  166. [row.cellConfig setObject:NCBrandColor.shared.label forKey:@"textLabel.textColor"];
  167. [row.cellConfig setObject:[[UIImage imageNamed:@"city"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
  168. row.value = activeAccount.city;
  169. if ([activeAccount.zip length] > 0) {
  170. row.value = [NSString stringWithFormat:@"%@ %@", row.value, activeAccount.zip];
  171. }
  172. [section addFormRow:row];
  173. }
  174. // Country
  175. if ([activeAccount.country length] > 0) {
  176. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"usercountry" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_country_", nil)];
  177. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.secondarySystemGroupedBackground;
  178. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  179. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"detailTextLabel.font"];
  180. [row.cellConfig setObject:NCBrandColor.shared.label forKey:@"textLabel.textColor"];
  181. [row.cellConfig setObject:[[UIImage imageNamed:@"country"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
  182. row.value = [[NSLocale systemLocale] displayNameForKey:NSLocaleCountryCode value:activeAccount.country];
  183. //NSArray *countryCodes = [NSLocale ISOCountryCodes];
  184. [section addFormRow:row];
  185. }
  186. // Phone
  187. if ([activeAccount.phone length] > 0) {
  188. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"userphone" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_phone_", nil)];
  189. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.secondarySystemGroupedBackground;
  190. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  191. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"detailTextLabel.font"];
  192. [row.cellConfig setObject:NCBrandColor.shared.label forKey:@"textLabel.textColor"];
  193. [row.cellConfig setObject:[[UIImage imageNamed:@"phone"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
  194. row.value = activeAccount.phone;
  195. [section addFormRow:row];
  196. }
  197. // Email
  198. if ([activeAccount.email length] > 0) {
  199. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"useremail" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_email_", nil)];
  200. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.secondarySystemGroupedBackground;
  201. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  202. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"detailTextLabel.font"];
  203. [row.cellConfig setObject:NCBrandColor.shared.label forKey:@"textLabel.textColor"];
  204. [row.cellConfig setObject:[[UIImage imageNamed:@"email"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
  205. row.value = activeAccount.email;
  206. [section addFormRow:row];
  207. }
  208. // Web
  209. if ([activeAccount.webpage length] > 0) {
  210. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"userweb" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_web_", nil)];
  211. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.secondarySystemGroupedBackground;
  212. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  213. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"detailTextLabel.font"];
  214. [row.cellConfig setObject:NCBrandColor.shared.label forKey:@"textLabel.textColor"];
  215. [row.cellConfig setObject:[[UIImage imageNamed:@"network"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
  216. row.value = activeAccount.webpage;
  217. [section addFormRow:row];
  218. }
  219. // Twitter
  220. if ([activeAccount.twitter length] > 0) {
  221. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"usertwitter" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_twitter_", nil)];
  222. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.secondarySystemGroupedBackground;
  223. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  224. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"detailTextLabel.font"];
  225. [row.cellConfig setObject:NCBrandColor.shared.label forKey:@"textLabel.textColor"];
  226. [row.cellConfig setObject:[[UIImage imageNamed:@"twitter"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
  227. row.value = activeAccount.twitter;
  228. [section addFormRow:row];
  229. }
  230. // Section : THIRT PART -------------------------------------------
  231. BOOL isHandwerkcloudEnabled = [[NCManageDatabase shared] getCapabilitiesServerBoolWithAccount:activeAccount.account elements:NCElementsJSON.shared.capabilitiesHWCEnabled exists:false];
  232. if (isHandwerkcloudEnabled) {
  233. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_user_job_", nil)];
  234. [form addFormSection:section];
  235. // Business Type
  236. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"userbusinesstype" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_businesstype_", nil)];
  237. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.secondarySystemGroupedBackground;
  238. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  239. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"detailTextLabel.font"];
  240. [row.cellConfig setObject:NCBrandColor.shared.label forKey:@"textLabel.textColor"];
  241. [row.cellConfig setObject:[[UIImage imageNamed:@"businesstype"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
  242. row.value = activeAccount.businessType;
  243. [section addFormRow:row];
  244. // Business Size
  245. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"userbusinesssize" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_businesssize_", nil)];
  246. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.secondarySystemGroupedBackground;
  247. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  248. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"detailTextLabel.font"];
  249. [row.cellConfig setObject:NCBrandColor.shared.label forKey:@"textLabel.textColor"];
  250. [row.cellConfig setObject:[[UIImage imageNamed:@"users"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
  251. row.value = activeAccount.businessSize;
  252. [section addFormRow:row];
  253. // Role
  254. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"userrole" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_role_", nil)];
  255. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.secondarySystemGroupedBackground;
  256. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  257. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"detailTextLabel.font"];
  258. [row.cellConfig setObject:NCBrandColor.shared.label forKey:@"textLabel.textColor"];
  259. [row.cellConfig setObject:[[UIImage imageNamed:@"role"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
  260. if ([activeAccount.role isEqualToString:@"owner"]) row.value = NSLocalizedString(@"_user_owner_", nil);
  261. else if ([activeAccount.role isEqualToString:@"employee"]) row.value = NSLocalizedString(@"_user_employee_", nil);
  262. else if ([activeAccount.role isEqualToString:@"contractor"]) row.value = NSLocalizedString(@"_user_contractor_", nil);
  263. else row.value = @"";
  264. [section addFormRow:row];
  265. // Company
  266. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"usercompany" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_company_", nil)];
  267. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.secondarySystemGroupedBackground;
  268. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  269. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"detailTextLabel.font"];
  270. [row.cellConfig setObject:NCBrandColor.shared.label forKey:@"textLabel.textColor"];
  271. [row.cellConfig setObject:[[UIImage imageNamed:@"company"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
  272. row.value = activeAccount.company;
  273. [section addFormRow:row];
  274. if (activeAccount.hcIsTrial) {
  275. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_trial_", nil)];
  276. [form addFormSection:section];
  277. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"trial" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_trial_expired_day_", nil)];
  278. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.secondarySystemGroupedBackground;
  279. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  280. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"detailTextLabel.font"];
  281. [row.cellConfig setObject:[UIColor redColor] forKey:@"textLabel.textColor"];
  282. [row.cellConfig setObject:[UIColor redColor] forKey:@"detailTextLabel.textColor"];
  283. [row.cellConfig setObject:[[UIImage imageNamed:@"timer"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
  284. NSInteger numberOfDays = activeAccount.hcTrialRemainingSec / (24*3600);
  285. row.value = [@(numberOfDays) stringValue];
  286. [section addFormRow:row];
  287. }
  288. section = [XLFormSectionDescriptor formSection];
  289. [form addFormSection:section];
  290. // Edit profile
  291. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"editUserProfile" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_user_editprofile_", nil)];
  292. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.secondarySystemGroupedBackground;
  293. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  294. [row.cellConfig setObject:[[UIImage imageNamed:@"editUserProfile"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
  295. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  296. [row.cellConfig setObject:NCBrandColor.shared.label forKey:@"textLabel.textColor"];
  297. #if defined(HC)
  298. row.action.viewControllerClass = [HCEditProfile class];
  299. #endif
  300. if (accounts.count == 0) row.disabled = @YES;
  301. [section addFormRow:row];
  302. }
  303. self.tableView.showsVerticalScrollIndicator = NO;
  304. self.form = form;
  305. // Open Login
  306. if (accounts.count == 0) {
  307. [appDelegate openLoginWithViewController:self selector:NCGlobal.shared.introLogin openLoginWeb:false];
  308. }
  309. }
  310. // MARK: - View Life Cycle
  311. - (void)viewDidLoad
  312. {
  313. [super viewDidLoad];
  314. self.title = NSLocalizedString(@"_credentials_", nil);
  315. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  316. self.view.backgroundColor = NCBrandColor.shared.systemGroupedBackground;
  317. self.tableView.backgroundColor = NCBrandColor.shared.systemGroupedBackground;
  318. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(initialize) name:NCGlobal.shared.notificationCenterInitialize object:nil];
  319. [self initializeForm];
  320. }
  321. - (void)viewWillAppear:(BOOL)animated
  322. {
  323. [super viewWillAppear:animated];
  324. appDelegate.activeViewController = self;
  325. }
  326. #pragma mark - NotificationCenter
  327. - (void)initialize
  328. {
  329. [self initializeForm];
  330. }
  331. #pragma mark -
  332. -(void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  333. {
  334. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  335. if ([rowDescriptor.tag isEqualToString:@"accountRequest"]) {
  336. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  337. [CCUtility setAccountRequest:true];
  338. } else {
  339. [CCUtility setAccountRequest:false];
  340. }
  341. }
  342. else if ([rowDescriptor.tag isEqualToString:@"alias"]) {
  343. if ([newValue isEqual:[NSNull null]]) {
  344. [[NCManageDatabase shared] setAccountAlias:@""];
  345. } else {
  346. [[NCManageDatabase shared] setAccountAlias:newValue];
  347. }
  348. }
  349. else {
  350. NSArray *accounts = [[NCManageDatabase shared] getAllAccount];
  351. tableAccount *activeAccount = [[NCManageDatabase shared] getActiveAccount];
  352. for (tableAccount *account in accounts) {
  353. if ([rowDescriptor.tag isEqualToString:account.account]) {
  354. if (![account.account isEqualToString:activeAccount.account]) {
  355. [appDelegate changeAccount:account.account];
  356. }
  357. }
  358. }
  359. [self initializeForm];
  360. }
  361. }
  362. -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  363. [super tableView:tableView commitEditingStyle:editingStyle forRowAtIndexPath:indexPath];
  364. if (editingStyle == UITableViewCellEditingStyleDelete) {
  365. [self initializeForm];
  366. NSArray *accounts = [[NCManageDatabase shared] getAllAccount];
  367. tableAccount *tableAccountForDelete = accounts[indexPath.row];
  368. tableAccount *tableActiveAccount = [[NCManageDatabase shared] getActiveAccount];
  369. NSString *accountForDelete = tableAccountForDelete.account;
  370. NSString *activeAccount = tableActiveAccount.account;
  371. NSString *title = [NSString stringWithFormat:NSLocalizedString(@"_want_delete_account_",nil), accountForDelete];
  372. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  373. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  374. if (accountForDelete) {
  375. [appDelegate deleteAccount:accountForDelete wipe:false];
  376. }
  377. NSArray *listAccount = [[NCManageDatabase shared] getAccounts];
  378. if ([listAccount count] > 0) {
  379. if ([accountForDelete isEqualToString:activeAccount]) {
  380. [appDelegate changeAccount:listAccount[0]];
  381. }
  382. }
  383. [self initializeForm];
  384. }]];
  385. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { }]];
  386. alertController.popoverPresentationController.sourceView = self.view;
  387. alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
  388. [self presentViewController:alertController animated:YES completion:nil];
  389. }
  390. }
  391. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  392. if (indexPath.section == 0) {
  393. return 60;
  394. } else {
  395. return NCGlobal.shared.heightCellSettings;
  396. }
  397. }
  398. #pragma mark -
  399. - (void)addAccount:(XLFormRowDescriptor *)sender
  400. {
  401. [self deselectFormRow:sender];
  402. [appDelegate openLoginWithViewController:self selector:NCGlobal.shared.introLogin openLoginWeb:false];
  403. }
  404. #pragma mark -
  405. - (void)setUserStatus:(XLFormRowDescriptor *)sender
  406. {
  407. [self deselectFormRow:sender];
  408. if (@available(iOS 13.0, *)) {
  409. UINavigationController *navigationController = [[UIStoryboard storyboardWithName:@"NCUserStatus" bundle:nil] instantiateInitialViewController];
  410. [self presentViewController:navigationController animated:YES completion:nil];
  411. }
  412. }
  413. #pragma mark -
  414. - (void)certificateDetails:(XLFormRowDescriptor *)sender
  415. {
  416. [self deselectFormRow:sender];
  417. UINavigationController *navigationController = [[UIStoryboard storyboardWithName:@"NCViewCertificateDetails" bundle:nil] instantiateInitialViewController];
  418. NCViewCertificateDetails *viewController = (NCViewCertificateDetails *)navigationController.topViewController;
  419. NSURL *url = [NSURL URLWithString:appDelegate.urlBase];
  420. viewController.host = [url host];
  421. [self presentViewController:navigationController animated:YES completion:nil];
  422. }
  423. - (void)certificatePNDetails:(XLFormRowDescriptor *)sender
  424. {
  425. [self deselectFormRow:sender];
  426. UINavigationController *navigationController = [[UIStoryboard storyboardWithName:@"NCViewCertificateDetails" bundle:nil] instantiateInitialViewController];
  427. NCViewCertificateDetails *viewController = (NCViewCertificateDetails *)navigationController.topViewController;
  428. NSURL *url = [NSURL URLWithString: NCBrandOptions.shared.pushNotificationServerProxy];
  429. viewController.host = [url host];
  430. [self presentViewController:navigationController animated:YES completion:nil];
  431. }
  432. @end