CCLoginWeb.swift 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. public enum enumLoginType : Int {
  17. case loginAdd = 0, loginAddForced = 1, loginModifyPasswordUser = 2
  18. }
  19. public var loginTypeX : enumLoginType?
  20. override func viewDidLoad() {
  21. super.viewDidLoad()
  22. }
  23. override func didReceiveMemoryWarning() {
  24. super.didReceiveMemoryWarning()
  25. }
  26. func presentModalWithDefaultTheme(_ vc: UIViewController) {
  27. self.viewController = vc
  28. let webVC = SwiftModalWebVC(urlString: k_loginBaseUrl, theme: .loginWeb)
  29. webVC.delegateWeb = self
  30. vc.present(webVC, animated: true, completion: nil)
  31. }
  32. }
  33. extension CCLoginWeb: SwiftModalWebVCDelegate {
  34. func didStartLoading() {
  35. print("Started loading.")
  36. }
  37. func didReceiveServerRedirectForProvisionalNavigation(url: URL) {
  38. let urlString: String = url.absoluteString
  39. if (urlString.contains(k_webLoginAutenticationProtocol) == true) {
  40. let keyValue = url.path.components(separatedBy: "&")
  41. if (keyValue.count == 3) {
  42. let serverUrl : String = String(keyValue[0].replacingOccurrences(of: "/server:", with: "").characters.dropLast())
  43. let username : String = keyValue[1].replacingOccurrences(of: "user:", with: "")
  44. let password : String = keyValue[2].replacingOccurrences(of: "password:", with: "")
  45. let account : String = "\(username) \(serverUrl)"
  46. CCCoreData.deleteAccount(account)
  47. CCCoreData.addAccount(account, url: serverUrl, user: username, password: password)
  48. appDelegate.settingActiveAccount(account, activeUrl: serverUrl, activeUser: username, activePassword: password)
  49. self.delegate?.loginSuccess(loginType: 0)
  50. self.viewController?.dismiss(animated: true, completion: nil)
  51. }
  52. }
  53. }
  54. func didFinishLoading(success: Bool, url: URL) {
  55. print("Finished loading. Success: \(success).")
  56. }
  57. }