NCNetworkingCheckRemoteUser.swift 3.4 KB

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