Browse Source

【会员系统】登录逻辑补充

wanjun 4 months ago
parent
commit
9497563553

+ 64 - 0
PDF Office/PDF Master/MemberCenter/View/KMSecureTextField.swift

@@ -0,0 +1,64 @@
+//
+//  KMSecureTextField.swift
+//  PDF Reader Pro
+//
+//  Created by wanjun on 2024/10/25.
+//
+
+import Cocoa
+
+class KMSecureTextField: NSTextField {
+    
+    private var actualText: String = ""
+    
+    private var _isVisible: Bool = false
+    
+    var isVisible: Bool {
+        get {
+            return _isVisible
+        }
+        set {
+            _isVisible = newValue
+            if isVisible {
+                super.stringValue = actualText
+            } else {
+                super.stringValue = String(repeating: "*", count: actualText.count)
+            }
+        }
+    }
+    
+    override var stringValue: String {
+        get {
+            return actualText
+        }
+        set {
+             actualText = newValue
+            if isVisible {
+                super.stringValue = actualText
+            } else {
+                super.stringValue = String(repeating: "*", count: actualText.count)
+            }
+        }
+    }
+    
+    // MARK: Notification
+    
+    override func textDidChange(_ notification: Notification) {
+        if let textField = notification.object as? NSTextField {
+            actualText = textField.stringValue
+            if isVisible {
+                super.stringValue = actualText
+            } else {
+                super.stringValue = String(repeating: "*", count: actualText.count)
+            }
+        }
+        if let textView = notification.object as? NSTextView {
+            actualText = textView.string
+//            if isVisible {
+//                super.stringValue = actualText
+//            } else {
+//                super.stringValue = String(repeating: "*", count: actualText.count)
+//            }
+        }
+    }
+}

+ 21 - 5
PDF Office/PDF Master/MemberCenter/View/KMSignUpView.swift

@@ -27,6 +27,8 @@ class KMSignUpView: KMBaseXibView {
     @IBOutlet weak var sendLabel: NSTextField!
     @IBOutlet weak var passwordView: NSView!
     @IBOutlet weak var passwordTextField: NSTextField!
+    @IBOutlet weak var passwordTextField1: NSSecureTextField!
+    
     @IBOutlet weak var visibleButton: NSButton!
     @IBOutlet weak var passwordErrorLabel: NSTextField!
     @IBOutlet weak var stayCheckButton: NSButton!
@@ -66,13 +68,16 @@ class KMSignUpView: KMBaseXibView {
         emailTextField.placeholderString = NSLocalizedString("Please enter Email", tableName: "MemberCenterLocalizable", comment: "")
         verifficationTextField.placeholderString = NSLocalizedString("Enter Verification code", tableName: "MemberCenterLocalizable", comment: "")
         passwordTextField.placeholderString = NSLocalizedString("Password", tableName: "MemberCenterLocalizable", comment: "")
+        passwordTextField1.placeholderString = NSLocalizedString("Password", tableName: "MemberCenterLocalizable", comment: "")
+        privacyCheckButton.toolTip = NSLocalizedString("Please first agree and check the above agreement.", tableName: "MemberCenterLocalizable", comment: "")
     }
     
     private func initializeUI() -> Void {
         emailTextField.delegate = self
         verifficationTextField.delegate = self
         passwordTextField.delegate = self
-        
+        passwordTextField1.delegate = self
+
         signUpLabel.textColor = NSColor(named: "000000")
         signUpLabel.font = NSFont.SFMediumFontWithSize(20)
         selectBox1.fillColor = NSColor(named: "4982E6") ?? NSColor.blue
@@ -162,7 +167,7 @@ class KMSignUpView: KMBaseXibView {
             passwordButton.setTitleColor(color: NSColor(named: "42464D") ?? NSColor.black, font: NSFont.SFProTextRegularFont(14))
             verifficationView.isHidden = false
             passwordView.isHidden = true
-            passwordTextField.placeholderString = NSLocalizedString("Enter Verification code", tableName: "MemberCenterLocalizable", comment: "")
+            verifficationTextField.placeholderString = NSLocalizedString("Enter Verification code", tableName: "MemberCenterLocalizable", comment: "")
             forgetButton.isHidden = true
         } else if viewModel.signUpState == .password {
             selectBox1.isHidden = true
@@ -172,6 +177,7 @@ class KMSignUpView: KMBaseXibView {
             verifficationView.isHidden = true
             passwordView.isHidden = false
             passwordTextField.placeholderString = NSLocalizedString("Password", tableName: "MemberCenterLocalizable", comment: "")
+            passwordTextField1.placeholderString = NSLocalizedString("Password", tableName: "MemberCenterLocalizable", comment: "")
             forgetButton.isHidden = false
         }
     }
@@ -187,9 +193,15 @@ class KMSignUpView: KMBaseXibView {
     
     private func visibleStateChange() -> Void {
         if viewModel.isVisible {
-            visibleButton.image = NSImage(named: "PasswordVisible")
+            visibleButton.image = NSImage(named: "passwordUnVisible")
+            passwordTextField.isHidden = false
+            passwordTextField1.isHidden = true
+            passwordTextField.stringValue = viewModel.password
         } else {
-            visibleButton.image = NSImage(named: "PasswordUnVisible")
+            visibleButton.image = NSImage(named: "passwordVisible")
+            passwordTextField.isHidden = true
+            passwordTextField1.isHidden = false
+            passwordTextField1.stringValue = viewModel.password
         }
     }
     
@@ -223,7 +235,7 @@ class KMSignUpView: KMBaseXibView {
         }
     }
     
-    func sendBoxRefresh() -> Void {
+    private func sendBoxRefresh() -> Void {
         sendLabel.stringValue = viewModel.sendContent
         if viewModel.sendContent == NSLocalizedString("Send", tableName: "MemberCenterLocalizable", comment: "") {
             if viewModel.email.count > 0 {
@@ -347,6 +359,8 @@ extension KMSignUpView: NSTextFieldDelegate {
             viewModel.verificationCode = textField!.stringValue
         } else if textField == passwordTextField {
             viewModel.password = textField!.stringValue
+        } else if textField == passwordTextField1 {
+            viewModel.password = textField!.stringValue
         }
     }
     
@@ -358,6 +372,8 @@ extension KMSignUpView: NSTextFieldDelegate {
             viewModel.verificationCode = textField!.stringValue
         } else if textField == passwordTextField {
             viewModel.password = textField!.stringValue
+        } else if textField == passwordTextField1 {
+            viewModel.password = textField!.stringValue
         }
     }
 }

+ 25 - 11
PDF Office/PDF Master/MemberCenter/View/KMSignUpView.xib

@@ -18,13 +18,14 @@
                 <outlet property="passwordButton" destination="hI0-Ez-r1t" id="I2i-jA-JZ8"/>
                 <outlet property="passwordErrorLabel" destination="WaO-uv-Tcx" id="3eh-3A-B3w"/>
                 <outlet property="passwordTextField" destination="GgF-lg-2Qh" id="u9W-qC-4eI"/>
+                <outlet property="passwordTextField1" destination="AGE-IA-Gl4" id="82T-7W-e9j"/>
                 <outlet property="passwordView" destination="ttn-3w-NPP" id="Rag-3n-Ujm"/>
                 <outlet property="privacyCheckButton" destination="ykU-at-pNt" id="OPJ-2n-NC3"/>
                 <outlet property="privacyLabel" destination="nTy-dc-ic8" id="oHu-i2-R7L"/>
                 <outlet property="selectBox1" destination="P29-Ro-E8E" id="zVo-7Q-ZMX"/>
                 <outlet property="selectBox2" destination="nVe-Zg-4Ax" id="hQF-vQ-wpn"/>
                 <outlet property="sendBox" destination="YTg-zc-9kj" id="5n6-H0-Z96"/>
-                <outlet property="sendLabel" destination="9CR-yj-hV6" id="xaT-6I-MST"/>
+                <outlet property="sendLabel" destination="9CR-yj-hV6" id="JG3-5D-QXP"/>
                 <outlet property="signUpBox" destination="Zvy-4N-s24" id="QB8-nO-MdS"/>
                 <outlet property="signUpButton" destination="lP8-at-uhr" id="x82-l4-xcU"/>
                 <outlet property="signUpLabel" destination="BPG-eq-njN" id="k4r-WI-LHj"/>
@@ -284,13 +285,13 @@
                                             <rect key="frame" x="0.0" y="0.0" width="277" height="26"/>
                                             <subviews>
                                                 <box boxType="custom" cornerRadius="1" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="JUe-bQ-uSN">
-                                                    <rect key="frame" x="0.0" y="0.0" width="229" height="26"/>
+                                                    <rect key="frame" x="0.0" y="0.0" width="224" height="26"/>
                                                     <view key="contentView" id="LsV-oy-6JL">
-                                                        <rect key="frame" x="1" y="1" width="227" height="24"/>
+                                                        <rect key="frame" x="1" y="1" width="222" height="24"/>
                                                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                                                         <subviews>
                                                             <textField focusRingType="none" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Q4E-Ah-Yxy">
-                                                                <rect key="frame" x="6" y="4" width="215" height="16"/>
+                                                                <rect key="frame" x="6" y="4" width="210" height="16"/>
                                                                 <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" id="7p1-b6-AOB">
                                                                     <font key="font" usesAppearanceFont="YES"/>
                                                                     <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
@@ -308,13 +309,13 @@
                                                     </constraints>
                                                 </box>
                                                 <box boxType="custom" borderWidth="0.0" cornerRadius="1" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="YTg-zc-9kj" customClass="KMBox" customModule="PDF_Reader_Pro" customModuleProvider="target">
-                                                    <rect key="frame" x="229" y="0.0" width="48" height="26"/>
+                                                    <rect key="frame" x="224" y="0.0" width="53" height="26"/>
                                                     <view key="contentView" id="zmY-cn-OGB">
-                                                        <rect key="frame" x="0.0" y="0.0" width="48" height="26"/>
+                                                        <rect key="frame" x="0.0" y="0.0" width="53" height="26"/>
                                                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                                                         <subviews>
                                                             <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="9CR-yj-hV6">
-                                                                <rect key="frame" x="-2" y="5" width="52" height="16"/>
+                                                                <rect key="frame" x="6" y="5" width="41" height="16"/>
                                                                 <textFieldCell key="cell" lineBreakMode="clipping" alignment="center" title="Label" id="fPD-Vb-cyJ">
                                                                     <font key="font" usesAppearanceFont="YES"/>
                                                                     <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
@@ -323,12 +324,11 @@
                                                             </textField>
                                                         </subviews>
                                                         <constraints>
-                                                            <constraint firstItem="9CR-yj-hV6" firstAttribute="leading" secondItem="zmY-cn-OGB" secondAttribute="leading" id="cG0-dq-Jvg"/>
-                                                            <constraint firstAttribute="trailing" secondItem="9CR-yj-hV6" secondAttribute="trailing" id="fre-d6-d3d"/>
+                                                            <constraint firstAttribute="trailing" secondItem="9CR-yj-hV6" secondAttribute="trailing" constant="8" id="EkX-CM-6Nx"/>
+                                                            <constraint firstItem="9CR-yj-hV6" firstAttribute="leading" secondItem="zmY-cn-OGB" secondAttribute="leading" constant="8" id="WVN-gq-fZT"/>
                                                         </constraints>
                                                     </view>
                                                     <constraints>
-                                                        <constraint firstAttribute="width" constant="48" id="2sv-YT-ZUH"/>
                                                         <constraint firstItem="9CR-yj-hV6" firstAttribute="centerY" secondItem="YTg-zc-9kj" secondAttribute="centerY" id="em6-C3-SO0"/>
                                                     </constraints>
                                                 </box>
@@ -346,7 +346,18 @@
                                         <customView hidden="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ttn-3w-NPP">
                                             <rect key="frame" x="0.0" y="0.0" width="277" height="26"/>
                                             <subviews>
-                                                <textField focusRingType="none" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="GgF-lg-2Qh">
+                                                <secureTextField focusRingType="none" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="AGE-IA-Gl4">
+                                                    <rect key="frame" x="8" y="5" width="243" height="16"/>
+                                                    <secureTextFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" drawsBackground="YES" usesSingleLineMode="YES" id="QCj-QO-AzJ">
+                                                        <font key="font" metaFont="system"/>
+                                                        <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
+                                                        <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
+                                                        <allowedInputSourceLocales>
+                                                            <string>NSAllRomanInputSourcesLocaleIdentifier</string>
+                                                        </allowedInputSourceLocales>
+                                                    </secureTextFieldCell>
+                                                </secureTextField>
+                                                <textField hidden="YES" focusRingType="none" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="GgF-lg-2Qh" customClass="KMSecureTextField" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                                     <rect key="frame" x="6" y="5" width="247" height="16"/>
                                                     <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" id="GAi-ha-pFG">
                                                         <font key="font" usesAppearanceFont="YES"/>
@@ -372,8 +383,11 @@
                                             <constraints>
                                                 <constraint firstItem="GgF-lg-2Qh" firstAttribute="centerY" secondItem="ttn-3w-NPP" secondAttribute="centerY" id="3gb-p9-Bqy"/>
                                                 <constraint firstItem="fQP-aK-gzm" firstAttribute="leading" secondItem="GgF-lg-2Qh" secondAttribute="trailing" constant="4" id="J3B-3x-sHF"/>
+                                                <constraint firstItem="AGE-IA-Gl4" firstAttribute="leading" secondItem="ttn-3w-NPP" secondAttribute="leading" constant="8" id="Kbl-30-ImV"/>
                                                 <constraint firstItem="GgF-lg-2Qh" firstAttribute="leading" secondItem="ttn-3w-NPP" secondAttribute="leading" constant="8" id="ZH7-VU-G5L"/>
+                                                <constraint firstItem="AGE-IA-Gl4" firstAttribute="centerY" secondItem="ttn-3w-NPP" secondAttribute="centerY" id="eqH-GG-NYD"/>
                                                 <constraint firstAttribute="trailing" secondItem="fQP-aK-gzm" secondAttribute="trailing" constant="6" id="fdS-R0-PTv"/>
+                                                <constraint firstItem="fQP-aK-gzm" firstAttribute="leading" secondItem="AGE-IA-Gl4" secondAttribute="trailing" constant="4" id="mdD-Vc-jx2"/>
                                                 <constraint firstItem="fQP-aK-gzm" firstAttribute="centerY" secondItem="ttn-3w-NPP" secondAttribute="centerY" id="tww-2G-77N"/>
                                             </constraints>
                                         </customView>