CCManageAccount.m 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. //
  2. // CCManageAccount.m
  3. // Nextcloud iOS
  4. //
  5. // Created by Marino Faggiana on 12/03/15.
  6. // Copyright (c) 2017 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 <JDStatusBarNotification/JDStatusBarNotification.h>
  24. #import "CCManageAccount.h"
  25. #import "AppDelegate.h"
  26. #import "CCLogin.h"
  27. #import "NCAutoUpload.h"
  28. #import "NCBridgeSwift.h"
  29. #define actionSheetCancellaAccount 1
  30. @interface CCManageAccount () <CCLoginDelegate, CCLoginDelegateWeb>
  31. {
  32. AppDelegate *appDelegate;
  33. }
  34. @end
  35. @implementation CCManageAccount
  36. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  37. {
  38. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  39. if (self) {
  40. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  41. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
  42. }
  43. return self;
  44. }
  45. - (void)initializeForm
  46. {
  47. XLFormDescriptor *form = [XLFormDescriptor formDescriptor];
  48. XLFormSectionDescriptor *section;
  49. XLFormRowDescriptor *row;
  50. NSArray *listAccount = [[NCManageDatabase sharedInstance] getAccounts];
  51. tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountActive];
  52. tableCapabilities *tableCapabilities = [[NCManageDatabase sharedInstance] getCapabilitesWithAccount:tableAccount.account];
  53. // Section : ACCOUNTS -------------------------------------------
  54. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_accounts_", nil)];
  55. [form addFormSection:section];
  56. form.rowNavigationOptions = XLFormRowNavigationOptionNone;
  57. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"pickerAccount" rowType:XLFormRowDescriptorTypePicker];
  58. row.height = 100;
  59. if (listAccount.count > 0) {
  60. row.selectorOptions = listAccount;
  61. row.value = tableAccount.account;
  62. } else {
  63. row.selectorOptions = [[NSArray alloc] initWithObjects:@"", nil];
  64. }
  65. // Avatar
  66. NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@-%@.png", [CCUtility getDirectoryUserData], [CCUtility getStringUser:appDelegate.activeUser activeUrl:appDelegate.activeUrl], appDelegate.activeUser];
  67. UIImage *avatar = [UIImage imageWithContentsOfFile:fileNamePath];
  68. if (avatar) {
  69. avatar = [CCGraphics scaleImage:avatar toSize:CGSizeMake(40, 40) isAspectRation:YES];
  70. CCAvatar *avatarImageView = [[CCAvatar alloc] initWithImage:avatar borderColor:[UIColor lightGrayColor] borderWidth:0.5];
  71. CGSize imageSize = avatarImageView.bounds.size;
  72. UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
  73. CGContextRef context = UIGraphicsGetCurrentContext();
  74. [avatarImageView.layer renderInContext:context];
  75. avatar = UIGraphicsGetImageFromCurrentImageContext();
  76. UIGraphicsEndImageContext();
  77. } else {
  78. avatar = [UIImage imageNamed:@"avatarBN"];
  79. }
  80. [row.cellConfig setObject:avatar forKey:@"imageView.image"];
  81. [section addFormRow:row];
  82. // Section : MANAGE ACCOUNT -------------------------------------------
  83. if ([NCBrandOptions sharedInstance].disable_manage_account == NO) {
  84. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_manage_account_", nil)];
  85. [form addFormSection:section];
  86. // Modify Account
  87. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"changePassword" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_change_password_", nil)];
  88. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  89. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"rename"] multiplier:2 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
  90. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  91. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
  92. row.action.formSelector = @selector(changePassword:);
  93. if (listAccount.count == 0) row.disabled = @YES;
  94. [section addFormRow:row];
  95. // Brand
  96. if ([NCBrandOptions sharedInstance].disable_multiaccount == NO) {
  97. // New Account nextcloud
  98. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"addAccount" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_add_account_", nil)];
  99. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  100. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"add"] multiplier:2 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
  101. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  102. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
  103. row.action.formSelector = @selector(addAccount:);
  104. [section addFormRow:row];
  105. }
  106. // delete Account
  107. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"delAccount" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_delete_account_", nil)];
  108. [row.cellConfig setObject:[UIColor redColor] forKey:@"textLabel.textColor"];
  109. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  110. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"trash"] width:50 height:50 color:[UIColor redColor]] forKey:@"imageView.image"];
  111. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  112. row.action.formSelector = @selector(deleteAccount:);
  113. if (listAccount.count == 0) row.disabled = @YES;
  114. [section addFormRow:row];
  115. }
  116. // Section : USER INFORMATION -------------------------------------------
  117. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_personal_information_", nil)];
  118. [form addFormSection:section];
  119. // Full Name
  120. if ([tableAccount.displayName length] > 0) {
  121. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"userfullname" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_full_name_", nil)];
  122. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  123. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  124. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"user"] width:50 height:50 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
  125. row.value = tableAccount.displayName;
  126. [section addFormRow:row];
  127. }
  128. // Address
  129. if ([tableAccount.address length] > 0) {
  130. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"useraddress" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_address_", nil)];
  131. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  132. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  133. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"address"] width:50 height:50 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
  134. row.value = tableAccount.address;
  135. [section addFormRow:row];
  136. }
  137. // City + zip
  138. if ([tableAccount.city length] > 0) {
  139. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"usercity" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_city_", nil)];
  140. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  141. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  142. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"city"] width:50 height:50 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
  143. row.value = tableAccount.city;
  144. if ([tableAccount.zip length] > 0) {
  145. row.value = [NSString stringWithFormat:@"%@ %@", row.value, tableAccount.zip];
  146. }
  147. [section addFormRow:row];
  148. }
  149. // Country
  150. if ([tableAccount.country length] > 0) {
  151. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"usercountry" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_country_", nil)];
  152. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  153. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  154. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"country"] width:50 height:50 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
  155. row.value = [[NSLocale systemLocale] displayNameForKey:NSLocaleCountryCode value:tableAccount.country];
  156. //NSArray *countryCodes = [NSLocale ISOCountryCodes];
  157. [section addFormRow:row];
  158. }
  159. // Phone
  160. if ([tableAccount.phone length] > 0) {
  161. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"userphone" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_phone_", nil)];
  162. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  163. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  164. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"phone"] width:50 height:50 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
  165. row.value = tableAccount.phone;
  166. [section addFormRow:row];
  167. }
  168. // Email
  169. if ([tableAccount.email length] > 0) {
  170. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"useremail" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_email_", nil)];
  171. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  172. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  173. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"email"] width:50 height:50 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
  174. row.value = tableAccount.email;
  175. [section addFormRow:row];
  176. }
  177. // Web
  178. if ([tableAccount.webpage length] > 0) {
  179. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"userweb" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_web_", nil)];
  180. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  181. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  182. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"web"] width:50 height:50 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
  183. row.value = tableAccount.webpage;
  184. [section addFormRow:row];
  185. }
  186. // Twitter
  187. if ([tableAccount.twitter length] > 0) {
  188. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"usertwitter" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_twitter_", nil)];
  189. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  190. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  191. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"twitter"] width:50 height:50 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
  192. row.value = tableAccount.twitter;
  193. [section addFormRow:row];
  194. }
  195. // Section : THIRT PART -------------------------------------------
  196. if (tableCapabilities.isHandwerkcloudEnabled) {
  197. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_user_job_", nil)];
  198. [form addFormSection:section];
  199. // Business Type
  200. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"userbusinesstype" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_businesstype_", nil)];
  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:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"businesstype"] width:50 height:50 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
  204. row.value = tableAccount.businessType;
  205. [section addFormRow:row];
  206. // Business Size
  207. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"userbusinesssize" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_businesssize_", nil)];
  208. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  209. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  210. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"users"] width:50 height:50 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
  211. row.value = tableAccount.businessSize;
  212. [section addFormRow:row];
  213. // Role
  214. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"userrole" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_role_", nil)];
  215. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  216. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  217. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"role"] width:50 height:50 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
  218. if ([tableAccount.role isEqualToString:@"owner"]) row.value = NSLocalizedString(@"_user_owner_", nil);
  219. else if ([tableAccount.role isEqualToString:@"employee"]) row.value = NSLocalizedString(@"_user_employee_", nil);
  220. else if ([tableAccount.role isEqualToString:@"contractor"]) row.value = NSLocalizedString(@"_user_contractor_", nil);
  221. else row.value = @"";
  222. [section addFormRow:row];
  223. // Company
  224. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"usercompany" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_user_company_", nil)];
  225. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  226. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  227. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"company"] width:50 height:50 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
  228. row.value = tableAccount.company;
  229. [section addFormRow:row];
  230. if (tableAccount.hcIsTrial) {
  231. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_trial_", nil)];
  232. [form addFormSection:section];
  233. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"trial" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_trial_expired_day_", nil)];
  234. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  235. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  236. [row.cellConfig setObject:[UIColor redColor] forKey:@"textLabel.textColor"];
  237. [row.cellConfig setObject:[UIColor redColor] forKey:@"detailTextLabel.textColor"];
  238. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"timer"] width:50 height:50 color:[UIColor redColor]] forKey:@"imageView.image"];
  239. NSInteger numberOfDays = tableAccount.hcTrialRemainingSec / (24*3600);
  240. row.value = [@(numberOfDays) stringValue];
  241. [section addFormRow:row];
  242. }
  243. section = [XLFormSectionDescriptor formSection];
  244. [form addFormSection:section];
  245. // Edit profile
  246. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"editUserProfile" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_user_editprofile_", nil)];
  247. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  248. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"editUserProfile"] width:50 height:50 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
  249. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  250. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
  251. #if defined(HC)
  252. row.action.viewControllerClass = [HCEditProfile class];
  253. #endif
  254. if (listAccount.count == 0) row.disabled = @YES;
  255. [section addFormRow:row];
  256. }
  257. self.form = form;
  258. // Open Login
  259. if (listAccount.count == 0) {
  260. [appDelegate openLoginView:self delegate:self loginType:k_login_Add_Forced selector:k_intro_login];
  261. }
  262. }
  263. // Apparirà
  264. - (void)viewWillAppear:(BOOL)animated
  265. {
  266. [super viewWillAppear:animated];
  267. self.navigationItem.title = NSLocalizedString(@"_credentials_", nil);
  268. self.tableView.backgroundColor = [NCBrandColor sharedInstance].backgroundView;
  269. self.tableView.showsVerticalScrollIndicator = NO;
  270. // Color
  271. [appDelegate aspectNavigationControllerBar:self.navigationController.navigationBar online:[appDelegate.reachability isReachable] hidden:NO];
  272. [appDelegate aspectTabBar:self.tabBarController.tabBar hidden:NO];
  273. [self initializeForm];
  274. }
  275. - (void)changeTheming
  276. {
  277. [appDelegate changeTheming:self];
  278. }
  279. #pragma --------------------------------------------------------------------------------------------
  280. #pragma mark === Delegate ===
  281. #pragma --------------------------------------------------------------------------------------------
  282. -(void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  283. {
  284. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  285. if ([rowDescriptor.tag isEqualToString:@"pickerAccount"] && oldValue && newValue) {
  286. if (![newValue isEqualToString:oldValue] && ![newValue isEqualToString:@""] && ![newValue isEqualToString:appDelegate.activeAccount]) {
  287. [self ChangeDefaultAccount:newValue];
  288. }
  289. if ([newValue isEqualToString:@""]) {
  290. NSArray *listAccount = [[NCManageDatabase sharedInstance] getAccounts];
  291. if ([listAccount count] > 0) {
  292. [self ChangeDefaultAccount:listAccount[0]];
  293. }
  294. }
  295. }
  296. }
  297. #pragma --------------------------------------------------------------------------------------------
  298. #pragma mark === Delegate Login ===
  299. #pragma --------------------------------------------------------------------------------------------
  300. - (void)loginSuccess:(NSInteger)loginType
  301. {
  302. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil userInfo:nil];
  303. }
  304. #pragma --------------------------------------------------------------------------------------------
  305. #pragma mark === Add Account ===
  306. #pragma --------------------------------------------------------------------------------------------
  307. - (void)addAccount:(XLFormRowDescriptor *)sender
  308. {
  309. [self deselectFormRow:sender];
  310. [appDelegate openLoginView:self delegate:self loginType:k_login_Add selector:k_intro_login];
  311. }
  312. #pragma --------------------------------------------------------------------------------------------
  313. #pragma mark === Modify Account ===
  314. #pragma --------------------------------------------------------------------------------------------
  315. - (void)changePassword:(XLFormRowDescriptor *)sender
  316. {
  317. [self deselectFormRow:sender];
  318. [appDelegate openLoginView:self delegate:self loginType:k_login_Modify_Password selector:k_intro_login];
  319. }
  320. #pragma --------------------------------------------------------------------------------------------
  321. #pragma mark === Delete Account ===
  322. #pragma --------------------------------------------------------------------------------------------
  323. - (void)deleteAccount:(XLFormRowDescriptor *)sender
  324. {
  325. [self deselectFormRow:sender];
  326. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_want_delete_",nil) message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  327. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  328. XLFormPickerCell *pickerAccount = (XLFormPickerCell *)[[self.form formRowWithTag:@"pickerAccount"] cellForFormController:self];
  329. tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", pickerAccount.rowDescriptor.value]];
  330. NSString *account = tableAccount.account;
  331. if (account) {
  332. [appDelegate unsubscribingNextcloudServerPushNotification:account url:tableAccount.url withSubscribing:false];
  333. [[NCManageDatabase sharedInstance] clearTable:[tableAccount class] account:account];
  334. [[NCManageDatabase sharedInstance] clearTable:[tableActivity class] account:account];
  335. [[NCManageDatabase sharedInstance] clearTable:[tableActivitySubjectRich class] account:account];
  336. [[NCManageDatabase sharedInstance] clearTable:[tableCapabilities class] account:account];
  337. [[NCManageDatabase sharedInstance] clearTable:[tableDirectory class] account:account];
  338. [[NCManageDatabase sharedInstance] clearTable:[tableE2eEncryption class] account:account];
  339. [[NCManageDatabase sharedInstance] clearTable:[tableExternalSites class] account:account];
  340. [[NCManageDatabase sharedInstance] clearTable:[tableLocalFile class] account:account];
  341. [[NCManageDatabase sharedInstance] clearTable:[tableMetadata class] account:account];
  342. [[NCManageDatabase sharedInstance] clearTable:[tableMedia class] account:account];
  343. [[NCManageDatabase sharedInstance] clearTable:[tablePhotoLibrary class] account:account];
  344. [[NCManageDatabase sharedInstance] clearTable:[tableShare class] account:account];
  345. // Clear active user
  346. [appDelegate settingActiveAccount:nil activeUrl:nil activeUser:nil activeUserID:nil activePassword:nil];
  347. // Clear keychain
  348. [CCUtility clearAllKeysEndToEnd:account];
  349. [CCUtility clearAllKeysPushNotification:account];
  350. [CCUtility setPassword:account password:nil];
  351. [CCUtility setCertificateError:account error:NO];
  352. }
  353. NSArray *listAccount = [[NCManageDatabase sharedInstance] getAccounts];
  354. if ([listAccount count] > 0) {
  355. [self ChangeDefaultAccount:listAccount[0]];
  356. } else {
  357. [self initializeForm];
  358. }
  359. }]];
  360. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { }]];
  361. alertController.popoverPresentationController.sourceView = self.view;
  362. NSIndexPath *indexPath = [self.form indexPathOfFormRow:sender];
  363. alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
  364. [self presentViewController:alertController animated:YES completion:nil];
  365. }
  366. #pragma --------------------------------------------------------------------------------------------
  367. #pragma mark === Change Default Account ===
  368. #pragma --------------------------------------------------------------------------------------------
  369. - (void)ChangeDefaultAccount:(NSString *)account
  370. {
  371. tableAccount *tableAccount = [[NCManageDatabase sharedInstance] setAccountActive:account];
  372. if (tableAccount) {
  373. [appDelegate settingActiveAccount:tableAccount.account activeUrl:tableAccount.url activeUser:tableAccount.user activeUserID:tableAccount.userID activePassword:[CCUtility getPassword:tableAccount.account]];
  374. // Init home
  375. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil userInfo:nil];
  376. }
  377. [self initializeForm];
  378. }
  379. @end