NCNetworkingCheckRemoteUser.swift 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 UIKit
  23. import NextcloudKit
  24. class NCNetworkingCheckRemoteUser {
  25. func checkRemoteUser(account: String, error: NKError) {
  26. guard let tableAccount = NCManageDatabase.shared.getAccount(predicate: NSPredicate(format: "account == %@", account)) else {
  27. return
  28. }
  29. // remove all process ----
  30. NCNetworking.shared.cancelAllTransfer(account: account) { }
  31. NCOperationQueue.shared.cancelAllQueue()
  32. NCNetworking.shared.cancelAllTask()
  33. // -----------------------
  34. if NCGlobal.shared.capabilityServerVersionMajor >= NCGlobal.shared.nextcloudVersion17 {
  35. let token = CCUtility.getPassword(account)!
  36. if token.isEmpty {
  37. return
  38. }
  39. NextcloudKit.shared.getRemoteWipeStatus(serverUrl: tableAccount.urlBase, token: token) { account, wipe, data, error in
  40. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  41. if wipe {
  42. appDelegate.deleteAccount(account, wipe: true)
  43. let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_wipe_account_")
  44. NCContentPresenter.shared.messageNotification(tableAccount.user, error: error, delay: NCGlobal.shared.dismissAfterSecondLong, type: NCContentPresenter.messageType.error, priority: .max)
  45. NextcloudKit.shared.setRemoteWipeCompletition(serverUrl: tableAccount.urlBase, token: token) { _, _ in print("wipe") }
  46. } else {
  47. if UIApplication.shared.applicationState == .active && NextcloudKit.shared.isNetworkReachable() && !CCUtility.getPassword(account).isEmpty {
  48. let description = String.localizedStringWithFormat(NSLocalizedString("_error_check_remote_user_", comment: ""), tableAccount.user, tableAccount.urlBase)
  49. let error = NKError(errorCode: error.errorCode, errorDescription: description)
  50. NCContentPresenter.shared.showError(error: error, priority: .max)
  51. CCUtility.setPassword(account, password: nil)
  52. NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Password removed.")
  53. }
  54. }
  55. }
  56. } else if CCUtility.getPassword(account) != "" {
  57. if UIApplication.shared.applicationState == .active && NextcloudKit.shared.isNetworkReachable() {
  58. let description = String.localizedStringWithFormat(NSLocalizedString("_error_check_remote_user_", comment: ""), tableAccount.user, tableAccount.urlBase)
  59. let error = NKError(errorCode: error.errorCode, errorDescription: description)
  60. NCContentPresenter.shared.showError(error: error, priority: .max)
  61. CCUtility.setPassword(account, password: nil)
  62. }
  63. }
  64. }
  65. }