NCLogin.swift 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //
  2. // NCLogin.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 24/02/21.
  6. // Copyright © 2021 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 Foundation
  24. import NCCommunication
  25. class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
  26. @IBOutlet weak var imageBrand: UIImageView!
  27. @IBOutlet weak var baseUrl: UITextField!
  28. @IBOutlet weak var user: UITextField!
  29. @IBOutlet weak var password: UITextField!
  30. @IBOutlet weak var imageBaseUrl: UIImageView!
  31. @IBOutlet weak var imageUser: UIImageView!
  32. @IBOutlet weak var imagePassword: UIImageView!
  33. @IBOutlet weak var activity: UIActivityIndicatorView!
  34. @IBOutlet weak var login: UIButton!
  35. @IBOutlet weak var toggleVisiblePassword: UIButton!
  36. @IBOutlet weak var loginTypeView: UIButton!
  37. @IBOutlet weak var qrCode: UIButton!
  38. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  39. // MARK: - Life Cycle
  40. // MARK: - QRCode
  41. func dismissQRCode(_ value: String?, metadataType: String?) {
  42. guard var value = value else { return }
  43. let protocolLogin = NCBrandOptions.shared.webLoginAutenticationProtocol + "login/"
  44. if value.hasPrefix("protocolLogin") && value.contains("user:") && value.contains("password:") && value.contains("server:") {
  45. value = value.replacingOccurrences(of: protocolLogin, with: "")
  46. let valueArray = value.components(separatedBy: "&")
  47. if valueArray.count == 3 {
  48. user.text = valueArray[0].replacingOccurrences(of: "user:", with: "")
  49. password.text = valueArray[1].replacingOccurrences(of: "password:", with: "")
  50. baseUrl.text = valueArray[2].replacingOccurrences(of: "server:", with: "")
  51. // Check whether baseUrl contain protocol. If not add https:// by default.
  52. if (baseUrl.text?.hasPrefix("https") ?? false) == false && (baseUrl.text?.hasPrefix("http") ?? false) == false {
  53. self.baseUrl.text = "https://" + (self.baseUrl.text ?? "")
  54. }
  55. login.isEnabled = false
  56. activity.startAnimating()
  57. let webDAV = NCUtilityFileSystem.shared.getWebDAV(account: appDelegate.account)
  58. let serverUrl = (baseUrl.text ?? "") + "/" + webDAV
  59. NCCommunication.shared.checkServer(serverUrl: serverUrl) { (errorCode, errorDescription) in
  60. self.activity.stopAnimating()
  61. self.login.isEnabled = true
  62. // [self afterLoginWithUrl:url user:user token:token errorCode:errorCode message:errorDescription];
  63. }
  64. }
  65. }
  66. }
  67. }