NCAppConfigView.swift 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // NCAppConfigView.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 18/09/2019.
  6. // Copyright © 2019 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. @objc protocol NCAppConfigViewDelegate: class {
  25. func loginSuccess(_: NSInteger)
  26. @objc optional func appConfigViewDismiss()
  27. }
  28. class NCAppConfigView: UIViewController {
  29. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  30. @objc var serverUrl: String?
  31. @objc var username: String?
  32. @objc var password: String?
  33. @objc weak var delegate: NCAppConfigViewDelegate?
  34. @IBOutlet weak var logoImage: UIImageView!
  35. override func viewDidLoad() {
  36. super.viewDidLoad()
  37. self.view.backgroundColor = NCBrandColor.sharedInstance.brand
  38. let serverConfig = UserDefaults.standard.dictionary(forKey: NCBrandConfiguration.sharedInstance.configuration_key)
  39. serverUrl = serverConfig?[NCBrandConfiguration.sharedInstance.configuration_serverUrl] as? String
  40. username = serverConfig?[NCBrandConfiguration.sharedInstance.configuration_username] as? String
  41. password = serverConfig?[NCBrandConfiguration.sharedInstance.configuration_password] as? String
  42. }
  43. override func viewDidAppear(_ animated: Bool) {
  44. super.viewDidAppear(animated)
  45. // Stop timer error network
  46. appDelegate.timerErrorNetworking.invalidate()
  47. OCNetworking.sharedManager()?.getAppPassword(serverUrl, username: username, password: password, completion: { (token, message, errorCode) in
  48. if errorCode == 0 {
  49. } else {
  50. self.appDelegate.messageNotification("_error_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  51. }
  52. })
  53. }
  54. override func viewDidDisappear(_ animated: Bool) {
  55. super.viewDidDisappear(animated)
  56. // Start timer error network
  57. appDelegate.startTimerErrorNetworking()
  58. }
  59. }