NCNetworkingCheckRemoteUser.swift 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // NCNetworkingCheckRemoteUser.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 15/05/2020.
  6. // Copyright © 2020 Marino Faggiana. All rights reserved.
  7. //
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU General Public License as published by
  11. // the Free Software Foundation, either version 3 of the License, or
  12. // (at your option) any later version.
  13. //
  14. // This program is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. // GNU General Public License for more details.
  18. //
  19. // You should have received a copy of the GNU General Public License
  20. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. //
  22. import Foundation
  23. import NCCommunication
  24. @objc class NCNetworkingCheckRemoteUser: NSObject {
  25. @objc public static let shared: NCNetworkingCheckRemoteUser = {
  26. let instance = NCNetworkingCheckRemoteUser()
  27. return instance
  28. }()
  29. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  30. var checkRemoteUserInProgress = false
  31. @objc func checkRemoteUser(account: String) {
  32. if self.checkRemoteUserInProgress {
  33. return;
  34. } else {
  35. self.checkRemoteUserInProgress = true;
  36. }
  37. let serverVersionMajor = NCManageDatabase.sharedInstance.getCapabilitiesServerInt(account: account, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
  38. guard let tableAccount = NCManageDatabase.sharedInstance.getAccount(predicate: NSPredicate(format: "account == %@", account)) else { return }
  39. if serverVersionMajor >= k_nextcloud_version_17_0 {
  40. guard let token = CCUtility.getPassword(account) else { return }
  41. NCCommunication.shared.getRemoteWipeStatus(serverUrl: tableAccount.url, token: token) { (account, wipe, errorCode, errorDescriptiuon) in
  42. if wipe {
  43. self.appDelegate.deleteAccount(account, wipe: true)
  44. NCContentPresenter.shared.messageNotification(tableAccount.user, description: "_wipe_account_", delay: TimeInterval(k_dismissAfterSecond*2), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorInternalError))
  45. NCCommunication.shared.setRemoteWipeCompletition(serverUrl: tableAccount.url, token: token) { (account, errorCode, errorDescription) in
  46. print("wipe");
  47. }
  48. } else {
  49. if UIApplication.shared.applicationState == .active && NCCommunication.shared.isNetworkReachable() {
  50. let description = String.localizedStringWithFormat(NSLocalizedString("_error_check_remote_user_", comment: ""), tableAccount.user, tableAccount.url)
  51. NCContentPresenter.shared.messageNotification("_error_", description: description, delay: TimeInterval(k_dismissAfterSecond*2), type: NCContentPresenter.messageType.error, errorCode: errorCode)
  52. CCUtility.setPassword(account, password: nil)
  53. }
  54. }
  55. }
  56. } else if CCUtility.getPassword(account) != nil {
  57. if UIApplication.shared.applicationState == .active && NCCommunication.shared.isNetworkReachable() {
  58. let description = String.localizedStringWithFormat(NSLocalizedString("_error_check_remote_user_", comment: ""), tableAccount.user, tableAccount.url)
  59. NCContentPresenter.shared.messageNotification("_error_", description: description, delay: TimeInterval(k_dismissAfterSecond*2), type: NCContentPresenter.messageType.error, errorCode: 403)
  60. CCUtility.setPassword(account, password: nil)
  61. }
  62. }
  63. }
  64. }