CCManageAccount.m 28 KB

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