CCLoginWeb.swift 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // CCLoginWeb.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 07/04/17.
  6. // Copyright © 2017 TWS. All rights reserved.
  7. //
  8. import UIKit
  9. public protocol CCLoginDelegate: class {
  10. func loginSuccess(loginType: Int)
  11. }
  12. class CCLoginWeb: UIViewController {
  13. var viewController : UIViewController?
  14. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  15. public weak var delegate: CCLoginDelegate?
  16. override func viewDidLoad() {
  17. super.viewDidLoad()
  18. }
  19. override func didReceiveMemoryWarning() {
  20. super.didReceiveMemoryWarning()
  21. }
  22. func presentModalWithDefaultTheme(_ vc: UIViewController) {
  23. self.viewController = vc
  24. let webVC = SwiftModalWebVC(urlString: k_loginBaseUrl, theme: .loginWeb)
  25. webVC.delegateWeb = self
  26. vc.present(webVC, animated: true, completion: nil)
  27. }
  28. }
  29. extension CCLoginWeb: SwiftModalWebVCDelegate {
  30. func didStartLoading() {
  31. print("Started loading.")
  32. }
  33. func didReceiveServerRedirectForProvisionalNavigation(url: URL) {
  34. let urlString: String = url.absoluteString
  35. if (urlString.contains(k_webLoginAutenticationProtocol) == true) {
  36. let keyValue = url.path.components(separatedBy: "&")
  37. if (keyValue.count == 3) {
  38. let serverUrl : String = String(keyValue[0].replacingOccurrences(of: "/server:", with: "").characters.dropLast())
  39. let username : String = keyValue[1].replacingOccurrences(of: "user:", with: "")
  40. let password : String = keyValue[2].replacingOccurrences(of: "password:", with: "")
  41. let account : String = "\(username) \(serverUrl)"
  42. CCCoreData.addAccount(account, url: serverUrl, user: username, password: password)
  43. appDelegate.settingActiveAccount(account, activeUrl: serverUrl, activeUser: username, activePassword: password)
  44. self.delegate?.loginSuccess(loginType: 0)
  45. self.viewController?.dismiss(animated: true, completion: nil)
  46. }
  47. }
  48. }
  49. func didFinishLoading(success: Bool, url: URL) {
  50. print("Finished loading. Success: \(success).")
  51. }
  52. }