Browse Source

【会员系统】token过期相关问题

dinglingui 6 days ago
parent
commit
316c51a862

+ 4 - 4
PDF Office/PDF Master/MemberCenter/View/KMEnterVerificationCodeView.swift

@@ -181,12 +181,12 @@ class KMEnterVerificationCodeView: KMBaseXibView {
         viewModel.$passwordErrorMessage
             .receive(on: RunLoop.main)
             .sink { [weak self] newValue in
-                self?.verifficationErrorLabel.stringValue = newValue
-                if self?.viewModel.passwordErrorMessage.isEmpty == false {
-                    self?.verifficationErrorLabel.isHidden = true
+                self?.verifficationErrorLabel.stringValue = self?.viewModel.passwordErrorMessage ?? ""
+                if self?.verifficationErrorLabel.stringValue.isEmpty == false {
+                    self?.verifficationErrorLabel.isHidden = false
                     self?.verifficationBox.borderColor = NSColor(named: "FA1E5D") ?? NSColor.red
                 } else {
-                    self?.verifficationErrorLabel.isHidden = false
+                    self?.verifficationErrorLabel.isHidden = true
                     self?.verifficationBox.borderColor = NSColor(named: "DADBDE") ?? NSColor.red
                 }
             }

+ 25 - 0
PDF Office/PDF Master/MemberCenter/ViewController/KMUserInfoViewController.swift

@@ -105,6 +105,31 @@ class KMUserInfoViewController: NSViewController {
     deinit {
         KMPrint("KMUserInfoViewController deinit.")
     }
+    
+   @objc class func refreshTokenUserInfo(callback: ((Bool)->Void)?) -> Void {
+        if KMMemberCenterManager.manager.isConnectionAvailable() == false {
+            let alert = NSAlert()
+            alert.alertStyle = .critical
+            alert.messageText = NSLocalizedString("Error Information", comment: "")
+            alert.informativeText = NSLocalizedString("Please make sure your internet connection is available.", comment: "")
+            alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
+            alert.runModal()
+            
+            callback?(false)
+            return
+        }
+        
+        KMUserInfoVCModel().refreshUserInfo(networkAlert: false) { success, msg in
+            callback?(success)
+            if success {
+                KMMemberInfo.shared.isLogin = true
+                NotificationCenter.default.post(name: NSNotification.Name(rawValue: "MemberCenterLoginSuccess"), object: nil)
+            } else {
+                KMMemberInfo.shared.isLogin = false
+            }
+        }
+
+    }
 
     override func viewDidLoad() {
         super.viewDidLoad()

+ 1 - 1
PDF Office/PDF Master/MemberCenter/ViewModel/KMSignUpViewModel.swift

@@ -390,7 +390,7 @@ class KMSignUpViewModel: ObservableObject {
             return
         }
         if verificationCode.count <= 0 || verificationCode.count > 6 || !isValidVerificationCode() {
-            emailErrorMessage = NSLocalizedString("Verification code error.", tableName: "MemberCenterLocalizable", comment: "")
+            passwordErrorMessage = NSLocalizedString("Verification code error.", tableName: "MemberCenterLocalizable", comment: "")
             complete(false, "")
             return
         }

+ 9 - 0
PDF Office/PDF Master/MemberCenter/ViewModel/KMUserInfoVCModel.swift

@@ -36,6 +36,8 @@ class KMUserInfoVCModel: ObservableObject {
             guard let result = result else { return }
             let resultDict = result as KMMemberCenterResult
             let msg = resultDict.msg
+            let code = resultDict.code
+
             if success {
                 let userInfo = resultDict.userInfo
                 guard let userInfo = resultDict.userInfo else { return }
@@ -43,6 +45,13 @@ class KMUserInfoVCModel: ObservableObject {
                 complete(true, "")
             } else {
                 complete(false, "")
+                if(code == 304) {
+                    KMMemberInfo.shared.clearMemberInfoCache()
+                    KMMemberInfo.shared.isLogin = false
+                    KMMemberInfo.shared.access_token = ""
+                    NotificationCenter.default.post(name: NSNotification.Name(rawValue: "MemberCenterLogoutSuccess"), object: nil)
+
+                }
             }
         }
     }