CCLogin.m 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. //
  2. // CCLogin.m
  3. // Nextcloud iOS
  4. //
  5. // Created by Marino Faggiana on 09/04/15.
  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 "CCLogin.h"
  24. #import "AppDelegate.h"
  25. #import "CCUtility.h"
  26. #import "NCBridgeSwift.h"
  27. #import "NCNetworkingSync.h"
  28. @interface CCLogin () <CCLoginDelegateWeb>
  29. {
  30. AppDelegate *appDelegate;
  31. UIView *rootView;
  32. }
  33. @end
  34. @implementation CCLogin
  35. - (void)viewDidLoad
  36. {
  37. [super viewDidLoad];
  38. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  39. // Background color
  40. self.view.backgroundColor = [NCBrandColor sharedInstance].customer;
  41. // Image Brand
  42. self.imageBrand.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"loginLogo"] color:[NCBrandColor sharedInstance].customerText];
  43. // Annulla
  44. [self.annulla setTitle:NSLocalizedString(@"_cancel_", nil) forState:UIControlStateNormal];
  45. self.annulla.tintColor = [NCBrandColor sharedInstance].customerText;
  46. // Base URL
  47. _imageBaseUrl.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"loginURL"] color:[NCBrandColor sharedInstance].customerText];
  48. _baseUrl.textColor = [NCBrandColor sharedInstance].customerText;
  49. _baseUrl.tintColor = [NCBrandColor sharedInstance].customerText;
  50. _baseUrl.placeholder = NSLocalizedString(@"_login_url_", nil);
  51. [_baseUrl setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
  52. [self.baseUrl setFont:[UIFont systemFontOfSize:13]];
  53. [self.baseUrl setDelegate:self];
  54. // Loading Base Utl GIF
  55. self.loadingBaseUrl.image = [UIImage animatedImageWithAnimatedGIFURL:[[NSBundle mainBundle] URLForResource: @"loading@2x" withExtension:@"gif"]];
  56. self.loadingBaseUrl.hidden = YES;
  57. // User
  58. _imageUser.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"loginUser"] color:[NCBrandColor sharedInstance].customerText];
  59. _user.textColor = [NCBrandColor sharedInstance].customerText;
  60. _user.tintColor = [NCBrandColor sharedInstance].customerText;
  61. _user.placeholder = NSLocalizedString(@"_username_", nil);
  62. [_user setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
  63. [self.user setFont:[UIFont systemFontOfSize:13]];
  64. [self.user setDelegate:self];
  65. // Password
  66. _imagePassword.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"loginPassword"] color:[NCBrandColor sharedInstance].customerText];
  67. _password.textColor = [NCBrandColor sharedInstance].customerText;
  68. _password.tintColor = [NCBrandColor sharedInstance].customerText;
  69. _password.placeholder = NSLocalizedString(@"_password_", nil);
  70. [_password setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
  71. [self.password setFont:[UIFont systemFontOfSize:13]];
  72. [self.password setDelegate:self];
  73. // Login
  74. [self.login setTitle:NSLocalizedString(@"_login_", nil) forState:UIControlStateNormal];
  75. self.login.backgroundColor = [NCBrandColor sharedInstance].customerText;
  76. self.login.tintColor = [NCBrandColor sharedInstance].customer;
  77. // Type view
  78. [self.loginTypeView setTitle:NSLocalizedString(@"_traditional_login_", nil) forState:UIControlStateNormal];
  79. [self.loginTypeView setTitleColor:[NCBrandColor sharedInstance].customerText forState:UIControlStateNormal];
  80. // Bottom label
  81. self.bottomLabel.text = NSLocalizedString([NCBrandOptions sharedInstance].textLoginProvider, nil);
  82. self.bottomLabel.userInteractionEnabled = YES;
  83. if ([NCBrandOptions sharedInstance].disable_linkLoginProvider) {
  84. self.bottomLabel.hidden = YES;
  85. }
  86. UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tabBottomLabel)];
  87. [self.bottomLabel addGestureRecognizer:tapGesture];
  88. if (self.view.frame.size.width == ([[UIScreen mainScreen] bounds].size.width*([[UIScreen mainScreen] bounds].size.width<[[UIScreen mainScreen] bounds].size.height))+([[UIScreen mainScreen] bounds].size.height*([[UIScreen mainScreen] bounds].size.width>[[UIScreen mainScreen] bounds].size.height))) {
  89. // Portrait
  90. if ([NCBrandOptions sharedInstance].disable_linkLoginProvider == NO)
  91. self.bottomLabel.hidden = NO;
  92. self.loginTypeView.hidden = NO;
  93. } else {
  94. // Landscape
  95. self.bottomLabel.hidden = YES;
  96. self.loginTypeView.hidden = YES;
  97. }
  98. // Brand
  99. if ([NCBrandOptions sharedInstance].disable_request_login_url) {
  100. _baseUrl.text = [NCBrandOptions sharedInstance].loginBaseUrl;
  101. _imageBaseUrl.hidden = YES;
  102. _baseUrl.hidden = YES;
  103. }
  104. if (_loginType == loginAdd) {
  105. // Login Flow ?
  106. _imageUser.hidden = YES;
  107. _user.hidden = YES;
  108. _imagePassword.hidden = YES;
  109. _password.hidden = YES;
  110. }
  111. if (_loginType == loginAddForced) {
  112. _annulla.hidden = YES;
  113. // Login Flow ?
  114. _imageUser.hidden = YES;
  115. _user.hidden = YES;
  116. _imagePassword.hidden = YES;
  117. _password.hidden = YES;
  118. }
  119. if (_loginType == loginModifyPasswordUser) {
  120. _baseUrl.text = appDelegate.activeUrl;
  121. _baseUrl.userInteractionEnabled = NO;
  122. _baseUrl.textColor = [UIColor lightGrayColor];
  123. _user.text = appDelegate.activeUser;
  124. _user.userInteractionEnabled = NO;
  125. _user.textColor = [UIColor lightGrayColor];
  126. }
  127. }
  128. - (void)viewWillAppear:(BOOL)animated
  129. {
  130. [super viewWillAppear:animated];
  131. // verify URL
  132. if (_loginType == loginModifyPasswordUser && [self.baseUrl.text length] > 0)
  133. [self testUrl];
  134. }
  135. // E' apparsa
  136. - (void)viewDidAppear:(BOOL)animated
  137. {
  138. [super viewDidAppear:animated];
  139. }
  140. //
  141. - (void)viewDidDisappear:(BOOL)animated
  142. {
  143. [super viewDidDisappear:animated];
  144. }
  145. - (BOOL)textFieldShouldReturn:(UITextField *)textField
  146. {
  147. [textField resignFirstResponder];
  148. return YES;
  149. }
  150. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
  151. {
  152. [coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
  153. if (self.view.frame.size.width == ([[UIScreen mainScreen] bounds].size.width*([[UIScreen mainScreen] bounds].size.width<[[UIScreen mainScreen] bounds].size.height))+([[UIScreen mainScreen] bounds].size.height*([[UIScreen mainScreen] bounds].size.width>[[UIScreen mainScreen] bounds].size.height))) {
  154. // Portrait
  155. if ([NCBrandOptions sharedInstance].disable_linkLoginProvider == NO)
  156. self.bottomLabel.hidden = NO;
  157. self.loginTypeView.hidden = NO;
  158. } else {
  159. // Landscape
  160. self.bottomLabel.hidden = YES;
  161. self.loginTypeView.hidden = YES;
  162. }
  163. }];
  164. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  165. }
  166. - (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
  167. {
  168. [super dismissViewControllerAnimated:flag completion:completion];
  169. NSArray *callStack = [NSThread callStackSymbols];
  170. NSString *callParent = [callStack objectAtIndex:1];
  171. if ([callParent containsString:@"CCLogin"])
  172. [self.delegate loginClose];
  173. }
  174. #pragma --------------------------------------------------------------------------------------------
  175. #pragma mark == Chech Server URL ==
  176. #pragma --------------------------------------------------------------------------------------------
  177. - (void)testUrl
  178. {
  179. self.login.enabled = NO;
  180. self.loadingBaseUrl.hidden = NO;
  181. // Check whether baseUrl contain protocol. If not add https:// by default.
  182. if(![self.baseUrl.text hasPrefix:@"https"] && ![self.baseUrl.text hasPrefix:@"http"]) {
  183. self.baseUrl.text = [NSString stringWithFormat:@"https://%@",self.baseUrl.text];
  184. }
  185. // Remove trailing slash
  186. if ([self.baseUrl.text hasSuffix:@"/"])
  187. self.baseUrl.text = [self.baseUrl.text substringToIndex:[self.baseUrl.text length] - 1];
  188. // add webDAV for valid test url
  189. NSString *urlTest = [self.baseUrl.text stringByAppendingString:webDAV];
  190. // Remove stored cookies
  191. NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
  192. for (NSHTTPCookie *cookie in [storage cookies])
  193. {
  194. [storage deleteCookie:cookie];
  195. }
  196. // Test Login Flow
  197. if ([self.baseUrl.text length] > 0 && _user.hidden && _password.hidden) {
  198. NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlTest] cachePolicy:0 timeoutInterval:20.0];
  199. [request addValue:[CCUtility getUserAgent] forHTTPHeaderField:@"User-Agent"];
  200. [request addValue:@"true" forHTTPHeaderField:@"OCS-APIRequest"];
  201. NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
  202. NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];
  203. NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler: ^(NSData *data, NSURLResponse *response, NSError *error) {
  204. dispatch_async(dispatch_get_main_queue(), ^{
  205. self.login.enabled = YES;
  206. self.loadingBaseUrl.hidden = YES;
  207. if (error) {
  208. if ([error code] == NSURLErrorServerCertificateUntrusted) {
  209. [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:[error localizedDescription] viewController:self delegate:self];
  210. } else {
  211. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_connection_error_", nil) message:[error localizedDescription] preferredStyle:UIAlertControllerStyleAlert];
  212. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  213. [alertController addAction:okAction];
  214. [self presentViewController:alertController animated:YES completion:nil];
  215. }
  216. } else {
  217. appDelegate.activeLoginWeb = [CCLoginWeb new];
  218. appDelegate.activeLoginWeb.loginType = _loginType;
  219. appDelegate.activeLoginWeb.delegate = self;
  220. appDelegate.activeLoginWeb.urlBase = self.baseUrl.text;
  221. [appDelegate.activeLoginWeb presentModalWithDefaultTheme:self];
  222. }
  223. });
  224. }];
  225. [task resume];
  226. } else {
  227. NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlTest] cachePolicy:0 timeoutInterval:20.0];
  228. [request addValue:[CCUtility getUserAgent] forHTTPHeaderField:@"User-Agent"];
  229. NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
  230. NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];
  231. NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler: ^(NSData *data, NSURLResponse *response, NSError *error) {
  232. dispatch_async(dispatch_get_main_queue(), ^{
  233. self.login.enabled = YES;
  234. self.loadingBaseUrl.hidden = YES;
  235. if (error != nil) {
  236. // self signed certificate
  237. if ([error code] == NSURLErrorServerCertificateUntrusted) {
  238. [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:[error localizedDescription] viewController:self delegate:self];
  239. } else {
  240. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_connection_error_", nil) message:[error localizedDescription] preferredStyle:UIAlertControllerStyleAlert];
  241. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  242. [alertController addAction:okAction];
  243. [self presentViewController:alertController animated:YES completion:nil];
  244. }
  245. }
  246. });
  247. }];
  248. [task resume];
  249. }
  250. }
  251. - (void)trustedCerticateAccepted
  252. {
  253. NSLog(@"[LOG] Certificate trusted");
  254. }
  255. - (void)trustedCerticateDenied
  256. {
  257. if (_loginType == loginModifyPasswordUser)
  258. [self handleAnnulla:self];
  259. }
  260. -(void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler
  261. {
  262. // The pinnning check
  263. if ([[CCCertificate sharedManager] checkTrustedChallenge:challenge]) {
  264. completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]);
  265. } else {
  266. completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil);
  267. }
  268. }
  269. #pragma --------------------------------------------------------------------------------------------
  270. #pragma mark == Login ==
  271. #pragma --------------------------------------------------------------------------------------------
  272. - (void)loginCloudUrl:(NSString *)url user:(NSString *)user password:(NSString *)password
  273. {
  274. NSError *error = [[NCNetworkingSync sharedManager] checkServer:[NSString stringWithFormat:@"%@%@", url, webDAV] user:user userID:user password:password];
  275. dispatch_async(dispatch_get_main_queue(), ^{
  276. self.login.enabled = NO;
  277. self.loadingBaseUrl.hidden = NO;
  278. if (!error) {
  279. // account
  280. NSString *account = [NSString stringWithFormat:@"%@ %@", user, url];
  281. if (_loginType == loginModifyPasswordUser) {
  282. // Change Password
  283. tableAccount *tbAccount = [[NCManageDatabase sharedInstance] setAccountPassword:account password:password];
  284. // Setting appDelegate active account
  285. [appDelegate settingActiveAccount:tbAccount.account activeUrl:tbAccount.url activeUser:tbAccount.user activeUserID:tbAccount.userID activePassword:tbAccount.password];
  286. [self.delegate loginSuccess:_loginType];
  287. [self dismissViewControllerAnimated:YES completion:nil];
  288. } else {
  289. [[NCManageDatabase sharedInstance] deleteAccount:account];
  290. [[NCManageDatabase sharedInstance] addAccount:account url:url user:user password:password loginFlow:false];
  291. // Read User Profile
  292. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:account];
  293. metadataNet.action = actionGetUserProfile;
  294. [appDelegate.netQueue addOperation:[[OCnetworking alloc] initWithDelegate:self metadataNet:metadataNet withUser:user withUserID:user withPassword:password withUrl:url]];
  295. }
  296. } else {
  297. if ([error code] != NSURLErrorServerCertificateUntrusted) {
  298. NSString *description = [error.userInfo objectForKey:@"NSLocalizedDescription"];
  299. NSString *message = [NSString stringWithFormat:@"%@.\n%@", NSLocalizedStringFromTable(@"_not_possible_connect_to_server_", @"Error", nil), description];
  300. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:message preferredStyle:UIAlertControllerStyleAlert];
  301. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  302. [alertController addAction:okAction];
  303. [self presentViewController:alertController animated:YES completion:nil];
  304. }
  305. }
  306. self.login.enabled = YES;
  307. self.loadingBaseUrl.hidden = YES;
  308. });
  309. }
  310. #pragma --------------------------------------------------------------------------------------------
  311. #pragma mark ==== User Profile ====
  312. #pragma --------------------------------------------------------------------------------------------
  313. - (void)getUserProfileFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  314. {
  315. [[NCManageDatabase sharedInstance] deleteAccount:metadataNet.account];
  316. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:message preferredStyle:UIAlertControllerStyleAlert];
  317. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  318. [alertController addAction:okAction];
  319. [self presentViewController:alertController animated:YES completion:nil];
  320. }
  321. - (void)getUserProfileSuccess:(CCMetadataNet *)metadataNet userProfile:(OCUserProfile *)userProfile
  322. {
  323. // Verify if the account already exists
  324. if (userProfile.id.length > 0 && self.baseUrl.text.length > 0 && self.user.text.length > 0) {
  325. tableAccount *accountAlreadyExists = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"url = %@ AND user = %@ AND userID != %@", self.baseUrl.text, userProfile.id, self.user.text]];
  326. if (accountAlreadyExists) {
  327. [[NCManageDatabase sharedInstance] deleteAccount:metadataNet.account];
  328. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:[NSString stringWithFormat:NSLocalizedString(@"_account_already_exists_", nil), userProfile.id] preferredStyle:UIAlertControllerStyleAlert];
  329. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  330. [alertController addAction:okAction];
  331. [self presentViewController:alertController animated:YES completion:nil];
  332. return;
  333. }
  334. }
  335. // Verify if account is a valid account
  336. tableAccount *account = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account = %@", metadataNet.account]];
  337. if (account) {
  338. // Update User (+ userProfile.id)
  339. (void)[[NCManageDatabase sharedInstance] setAccountsUserProfile:userProfile];
  340. // Set this account as default
  341. tableAccount *account = [[NCManageDatabase sharedInstance] setAccountActive:metadataNet.account];
  342. if (account) {
  343. // Setting appDelegate active account
  344. [appDelegate settingActiveAccount:account.account activeUrl:account.url activeUser:account.user activeUserID:account.userID activePassword:account.password];
  345. [self.delegate loginSuccess:_loginType];
  346. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  347. [self dismissViewControllerAnimated:YES completion:nil];
  348. });
  349. }
  350. }
  351. }
  352. #pragma --------------------------------------------------------------------------------------------
  353. #pragma mark == TextField ==
  354. #pragma --------------------------------------------------------------------------------------------
  355. -(void)textFieldDidBeginEditing:(UITextField *)textField
  356. {
  357. if (textField == self.password) {
  358. self.toggleVisiblePassword.hidden = NO;
  359. self.password.defaultTextAttributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0f], NSForegroundColorAttributeName:[NCBrandColor sharedInstance].customerText};
  360. }
  361. }
  362. -(void)textFieldDidEndEditing:(UITextField *)textField
  363. {
  364. if (textField == self.password) {
  365. self.toggleVisiblePassword.hidden = YES;
  366. self.password.defaultTextAttributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0f], NSForegroundColorAttributeName:[NCBrandColor sharedInstance].customerText};
  367. }
  368. }
  369. #pragma --------------------------------------------------------------------------------------------
  370. #pragma mark === CCLoginDelegateWeb ===
  371. #pragma --------------------------------------------------------------------------------------------
  372. - (void)loginSuccess:(NSInteger)loginType
  373. {
  374. [self.delegate loginSuccess:_loginType];
  375. }
  376. - (void)loginWebClose
  377. {
  378. appDelegate.activeLoginWeb = nil;
  379. [self dismissViewControllerAnimated:YES completion:nil];
  380. }
  381. #pragma --------------------------------------------------------------------------------------------
  382. #pragma mark == Action ==
  383. #pragma --------------------------------------------------------------------------------------------
  384. - (void)tabBottomLabel
  385. {
  386. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NCBrandOptions sharedInstance].linkLoginProvider]];
  387. }
  388. - (IBAction)handlebaseUrlchange:(id)sender
  389. {
  390. if ([self.baseUrl.text length] > 0 && !_user.hidden && !_password.hidden)
  391. [self performSelector:@selector(testUrl) withObject:nil];
  392. }
  393. - (IBAction)handleButtonLogin:(id)sender
  394. {
  395. if ([self.baseUrl.text length] > 0 && _user.hidden && _password.hidden) {
  396. [self testUrl];
  397. return;
  398. }
  399. if ([self.baseUrl.text length] > 0 && [self.user.text length] && [self.password.text length]) {
  400. // remove last char if /
  401. if ([[self.baseUrl.text substringFromIndex:[self.baseUrl.text length] - 1] isEqualToString:@"/"])
  402. self.baseUrl.text = [self.baseUrl.text substringToIndex:[self.baseUrl.text length] - 1];
  403. NSString *url = self.baseUrl.text;
  404. NSString *user = self.user.text;
  405. NSString *password = self.password.text;
  406. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
  407. [self loginCloudUrl:url user:user password:password];
  408. });
  409. }
  410. }
  411. - (IBAction)handleAnnulla:(id)sender
  412. {
  413. [self dismissViewControllerAnimated:YES completion:nil];
  414. }
  415. - (IBAction)handleToggleVisiblePassword:(id)sender
  416. {
  417. NSString *currentPassword = self.password.text;
  418. self.password.secureTextEntry = ! self.password.secureTextEntry;
  419. self.password.text = @"";
  420. self.password.text = currentPassword;
  421. self.password.defaultTextAttributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0f], NSForegroundColorAttributeName: [NCBrandColor sharedInstance].customerText};
  422. }
  423. - (IBAction)handleLoginTypeView:(id)sender
  424. {
  425. if (_user.hidden && _password.hidden) {
  426. _imageUser.hidden = NO;
  427. _user.hidden = NO;
  428. _imagePassword.hidden = NO;
  429. _password.hidden = NO;
  430. [self.loginTypeView setTitle:NSLocalizedString(@"_web_login_", nil) forState:UIControlStateNormal];
  431. } else {
  432. _imageUser.hidden = YES;
  433. _user.hidden = YES;
  434. _imagePassword.hidden = YES;
  435. _password.hidden = YES;
  436. [self.loginTypeView setTitle:NSLocalizedString(@"_traditional_login_", nil) forState:UIControlStateNormal];
  437. }
  438. }
  439. @end