KMSignUpView.swift 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. //
  2. // KMSignUpView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by wanjun on 2024/10/23.
  6. //
  7. import Cocoa
  8. import Combine
  9. class KMSignUpView: KMBaseXibView {
  10. @IBOutlet weak var signUpLabel: NSTextField!
  11. @IBOutlet weak var loginModeBox: NSBox!
  12. @IBOutlet weak var verificationCodeButton: NSButton!
  13. @IBOutlet weak var selectBox1: NSBox!
  14. @IBOutlet weak var passwordButton: NSButton!
  15. @IBOutlet weak var selectBox2: NSBox!
  16. @IBOutlet weak var emailBox: NSBox!
  17. @IBOutlet weak var emailTextField: NSTextField!
  18. @IBOutlet weak var emailErrorLabel: NSTextField!
  19. @IBOutlet weak var passwordBox: NSBox!
  20. @IBOutlet weak var verifficationView: NSView!
  21. @IBOutlet weak var verifficationBox: NSBox!
  22. @IBOutlet weak var verifficationTextField: NSTextField!
  23. @IBOutlet weak var sendBox: KMBox!
  24. @IBOutlet weak var sendLabel: NSTextField!
  25. @IBOutlet weak var passwordView: NSView!
  26. @IBOutlet weak var passwordTextField: NSTextField!
  27. @IBOutlet weak var passwordTextField1: NSSecureTextField!
  28. @IBOutlet weak var visibleButton: NSButton!
  29. @IBOutlet weak var passwordErrorLabel: NSTextField!
  30. @IBOutlet weak var stayCheckButton: NSButton!
  31. @IBOutlet weak var stayLabel: NSTextField!
  32. @IBOutlet weak var forgetButton: NSButton!
  33. @IBOutlet weak var signUpBox: NSBox!
  34. @IBOutlet weak var signUpButton: NSButton!
  35. @IBOutlet weak var privacyCheckButton: NSButton!
  36. @IBOutlet weak var privacyLabel: NSTextField!
  37. private var viewModel = KMSignUpViewModel()
  38. private var cancellables = Set<AnyCancellable>()
  39. private var popOver_: NSPopover?
  40. convenience init(model: KMSignUpViewModel, superView: NSView) {
  41. self.init(frame: superView.bounds)
  42. viewModel = model
  43. viewModel.screenType = .signUp
  44. bindViewModel()
  45. languageLocalized()
  46. initializeUI()
  47. if model.sendCode {
  48. self.viewModel.countDown(type: .login, callback: nil)
  49. model.sendCode = false
  50. }
  51. }
  52. public override init(frame frameRect: NSRect) {
  53. super.init(frame: frameRect)
  54. }
  55. public required init?(coder decoder: NSCoder) {
  56. fatalError("init(coder:) has not been implemented")
  57. }
  58. public func resetTextFileData() {
  59. if(self.superview != nil) {
  60. emailTextField.stringValue = ""
  61. passwordTextField.stringValue = ""
  62. passwordTextField1.stringValue = ""
  63. verifficationTextField.stringValue = ""
  64. emailErrorLabel.isHidden = true
  65. passwordErrorLabel.isHidden = true
  66. sendLabel.stringValue = NSLocalizedString("Send", tableName: "MemberCenterLocalizable", comment: "")
  67. viewModel.sendContent = NSLocalizedString("Send", tableName: "MemberCenterLocalizable", comment: "")
  68. viewModel.email = ""
  69. sendBoxRefresh()
  70. }
  71. }
  72. override func updateUI() {
  73. super.updateUI()
  74. NotificationCenter.default.addObserver(self, selector: #selector(loginSuccessNotification), name: NSNotification.Name(rawValue: "MemberCenterLoginSuccess"), object: nil)
  75. bindViewModel()
  76. languageLocalized()
  77. initializeUI()
  78. }
  79. // MARK: Private Method
  80. private func languageLocalized() -> Void {
  81. signUpLabel.stringValue = NSLocalizedString("Sign in(titile)", tableName: "MemberCenterLocalizable", comment: "")
  82. verificationCodeButton.title = NSLocalizedString("Verification Code", tableName: "MemberCenterLocalizable", comment: "")
  83. passwordButton.title = NSLocalizedString("Password", tableName: "MemberCenterLocalizable", comment: "")
  84. stayLabel.stringValue = NSLocalizedString("Stay signed in", tableName: "MemberCenterLocalizable", comment: "")
  85. forgetButton.title = NSLocalizedString("Forgot password?", tableName: "MemberCenterLocalizable", comment: "")
  86. signUpButton.title = NSLocalizedString("Sign in(button)", tableName: "MemberCenterLocalizable", comment: "")
  87. emailErrorLabel.stringValue = String(format: "*%@", NSLocalizedString("Email format error. Please enter the correct email.", tableName: "MemberCenterLocalizable", comment: ""))
  88. passwordErrorLabel.stringValue = String(format: "*%@", NSLocalizedString("Verification code error.", tableName: "MemberCenterLocalizable", comment: ""))
  89. emailTextField.placeholderString = NSLocalizedString("Please enter email address", tableName: "MemberCenterLocalizable", comment: "")
  90. verifficationTextField.placeholderString = NSLocalizedString("Please enter code", tableName: "MemberCenterLocalizable", comment: "")
  91. passwordTextField.placeholderString = NSLocalizedString("Please enter password", tableName: "MemberCenterLocalizable", comment: "")
  92. passwordTextField1.placeholderString = NSLocalizedString("Please enter password", tableName: "MemberCenterLocalizable", comment: "")
  93. privacyCheckButton.toolTip = NSLocalizedString("Please agree and check the agreement first.", tableName: "MemberCenterLocalizable", comment: "")
  94. emailTextField.stringValue = viewModel.email
  95. verifficationTextField.stringValue = viewModel.verificationCode
  96. passwordTextField.stringValue = viewModel.password
  97. passwordTextField1.stringValue = viewModel.password
  98. }
  99. private func initializeUI() -> Void {
  100. emailBox.fillColor = NSColor(named: "texefiedfillcolor") ?? NSColor.white
  101. passwordBox.fillColor = NSColor(named: "texefiedfillcolor") ?? NSColor.white
  102. emailTextField.delegate = self
  103. verifficationTextField.delegate = self
  104. passwordTextField.delegate = self
  105. passwordTextField1.delegate = self
  106. emailErrorLabel.isHidden = !viewModel.emailError()
  107. passwordErrorLabel.isHidden = !viewModel.passwordError()
  108. signUpLabel.textColor = NSColor(named: "000000")
  109. signUpLabel.font = NSFont.SFMediumFontWithSize(20)
  110. selectBox1.fillColor = NSColor(named: "4982E6") ?? NSColor.blue
  111. emailErrorLabel.textColor = NSColor(named: "FA1E5D")
  112. emailErrorLabel.font = NSFont.SFProTextRegularFont(9)
  113. passwordBox.borderColor = NSColor(named: "DADBDE") ?? NSColor.gray
  114. verifficationBox.borderColor = NSColor(named: "FA1E5D") ?? NSColor.gray
  115. if viewModel.isValidEmail() {
  116. sendBox.fillColor = NSColor(named: "273C62") ?? NSColor.blue
  117. } else {
  118. sendBox.fillColor = NSColor(named: "273C62_0.4") ?? NSColor.blue
  119. }
  120. sendBox.borderColor = NSColor(named: "273C62") ?? NSColor.blue
  121. sendLabel.textColor = NSColor(named: "FFFFFF") ?? NSColor.white
  122. sendLabel.font = NSFont.SFProTextRegularFont(13)
  123. passwordErrorLabel.textColor = NSColor(named: "FA1E5D")
  124. passwordErrorLabel.font = NSFont.SFProTextRegularFont(9)
  125. stayCheckButton.image = NSImage(named: "CheckBoxNor")
  126. stayLabel.textColor = NSColor(named: "0E1114") ?? NSColor.black
  127. stayLabel.font = NSFont.SFProTextRegularFont(12)
  128. forgetButton.setTitleColor(color: NSColor(named: "4982E6") ?? NSColor.blue, font: NSFont.SFProTextRegularFont(12))
  129. signUpBox.fillColor = NSColor(named: "273C62") ?? NSColor.blue
  130. signUpButton.setTitleColor(color: NSColor(named: "FFFFFF") ?? NSColor.white, font: NSFont.SFProTextRegularFont(16))
  131. privacyCheckButton.image = NSImage(named: "CheckBoxNor")
  132. privacyLabel.isEditable = false
  133. privacyLabel.isSelectable = true
  134. privacyLabel.allowsEditingTextAttributes = true
  135. privacyLabel.textColor = NSColor.black
  136. privacyLabel.font = NSFont.SFProTextRegularFont(16.0)
  137. let tipsString = NSLocalizedString("I have read and agreed to the %@ and %@. An account will be automatically created after signing in with an unregistered email address.", tableName: "MemberCenterLocalizable", comment: "")
  138. let specialOffer = NSLocalizedString("Terms of Service", tableName: "MemberCenterLocalizable", comment: "")
  139. let contactsUs = NSLocalizedString("Privacy Policy", tableName: "MemberCenterLocalizable", comment: "")
  140. let fullString = String(format: tipsString, specialOffer, contactsUs)
  141. let attributedString = NSMutableAttributedString(string: fullString)
  142. // 定义链接的范围
  143. let specialOfferRange = (fullString as NSString).range(of: specialOffer)
  144. let contactsUsRange = (fullString as NSString).range(of: contactsUs)
  145. let linkColor = NSColor(named: "4982E6") ?? NSColor.blue
  146. let font = NSFont.SFProTextRegularFont(11.0) // 与普通文本相同的字体
  147. attributedString.addAttributes([
  148. .foregroundColor: NSColor(named: "0E1114") ?? NSColor.black as Any,
  149. .font: font
  150. ], range: (fullString as NSString).range(of: fullString))
  151. attributedString.addAttributes([
  152. .foregroundColor: linkColor,
  153. .link: NSLocalizedString("https://www.pdfreaderpro.com/terms_of_service", comment: ""),
  154. .font: font
  155. ], range: specialOfferRange)
  156. attributedString.addAttributes([
  157. .foregroundColor: linkColor,
  158. .link: NSLocalizedString("https://www.pdfreaderpro.com/privacy-policy", comment: ""),
  159. .font: font
  160. ], range: contactsUsRange)
  161. privacyLabel.attributedStringValue = attributedString
  162. signUpStateChange()
  163. visibleStateChange()
  164. textfieldInputState(isEmail: true)
  165. textfieldInputState(isEmail: false)
  166. sendBoxRefresh()
  167. sendBox.moveCallback = { [weak self](mouseEntered: Bool, mouseBox: KMBox) -> Void in
  168. guard let self = self else { return }
  169. if self.viewModel.email.count <= 0 { return }
  170. if self.viewModel.sendBoxSelect { return }
  171. if !self.viewModel.isValidEmail() { return }
  172. if mouseEntered {
  173. self.sendBox.fillColor = NSColor(named: "000000_0.1") ?? NSColor.blue
  174. } else {
  175. self.sendBox.fillColor = NSColor(named: "273C62") ?? NSColor.blue
  176. }
  177. }
  178. sendBox.downCallback = { [weak self](downEntered: Bool, mouseBox: KMBox, event) -> Void in
  179. guard let self = self else { return }
  180. if self.viewModel.email.count <= 0 { return }
  181. if self.viewModel.sendBoxSelect { return }
  182. if downEntered {
  183. self.sendBox.fillColor = NSColor(named: "273C62_0.4") ?? NSColor.blue
  184. self.viewModel.countDown(type: .login, callback: nil)
  185. }
  186. }
  187. }
  188. private func signUpStateChange() -> Void {
  189. if viewModel.signUpState == .verificationCode {
  190. selectBox1.isHidden = false
  191. selectBox2.isHidden = true
  192. verificationCodeButton.setTitleColor(color: NSColor(named: "4982E6") ?? NSColor.systemBlue, font: NSFont.SFProTextRegularFont(14))
  193. passwordButton.setTitleColor(color: NSColor(named: "42464D") ?? NSColor.black, font: NSFont.SFProTextRegularFont(14))
  194. verifficationView.isHidden = false
  195. passwordView.isHidden = true
  196. verifficationTextField.placeholderString = NSLocalizedString("Please enter code", tableName: "MemberCenterLocalizable", comment: "")
  197. forgetButton.isHidden = true
  198. } else if viewModel.signUpState == .password {
  199. selectBox1.isHidden = true
  200. selectBox2.isHidden = false
  201. verificationCodeButton.setTitleColor(color: NSColor(named: "42464D") ?? NSColor.black, font: NSFont.SFProTextRegularFont(14))
  202. passwordButton.setTitleColor(color: NSColor(named: "4982E6") ?? NSColor.black, font: NSFont.SFProTextRegularFont(14))
  203. verifficationView.isHidden = true
  204. passwordView.isHidden = false
  205. passwordTextField.placeholderString = NSLocalizedString("Please enter password", tableName: "MemberCenterLocalizable", comment: "")
  206. passwordTextField1.placeholderString = NSLocalizedString("Please enter password", tableName: "MemberCenterLocalizable", comment: "")
  207. forgetButton.isHidden = false
  208. }
  209. }
  210. private func checkStateChange(button: NSButton!, state: Bool) -> Void {
  211. button.state = state ? .on : .off
  212. if button.state == .on {
  213. button.image = NSImage(named: "CheckBoxSel")
  214. } else {
  215. button.image = NSImage(named: "CheckBoxNor")
  216. }
  217. }
  218. private func visibleStateChange() -> Void {
  219. if viewModel.isVisible {
  220. visibleButton.image = NSImage(named: "passwordVisible")
  221. passwordTextField.isHidden = false
  222. passwordTextField1.isHidden = true
  223. passwordTextField.stringValue = viewModel.password
  224. } else {
  225. visibleButton.image = NSImage(named: "passwordUnVisible")
  226. passwordTextField.isHidden = true
  227. passwordTextField1.isHidden = false
  228. passwordTextField1.stringValue = viewModel.password
  229. }
  230. }
  231. private func textfieldInputState(isEmail: Bool) -> Void {
  232. if isEmail {
  233. if viewModel.emailError() {
  234. emailBox.borderColor = NSColor(named: "FA1E5D") ?? NSColor.red
  235. } else {
  236. emailBox.borderColor = NSColor(named: "DADBDE") ?? NSColor.gray
  237. }
  238. emailErrorLabel.isHidden = !viewModel.emailError()
  239. } else {
  240. if viewModel.passwordError() {
  241. if viewModel.signUpState == .verificationCode {
  242. passwordBox.borderWidth = 0
  243. verifficationBox.borderWidth = 1
  244. passwordBox.borderColor = NSColor(named: "DADBDE") ?? NSColor.gray
  245. verifficationBox.borderColor = NSColor(named: "FA1E5D") ?? NSColor.red
  246. } else if viewModel.signUpState == .password {
  247. passwordBox.borderWidth = 1
  248. verifficationBox.borderWidth = 0
  249. verifficationBox.borderColor = NSColor(named: "DADBDE") ?? NSColor.gray
  250. passwordBox.borderColor = NSColor(named: "FA1E5D") ?? NSColor.red
  251. }
  252. } else {
  253. if viewModel.signUpState == .verificationCode {
  254. passwordBox.borderWidth = 1
  255. verifficationBox.borderWidth = 0
  256. } else if viewModel.signUpState == .password {
  257. passwordBox.borderWidth = 1
  258. verifficationBox.borderWidth = 0
  259. }
  260. }
  261. passwordErrorLabel.isHidden = !viewModel.passwordError()
  262. }
  263. }
  264. private func sendBoxRefresh() -> Void {
  265. sendLabel.stringValue = viewModel.sendContent
  266. if viewModel.sendContent == NSLocalizedString("Send", tableName: "MemberCenterLocalizable", comment: "") ||
  267. viewModel.sendContent == NSLocalizedString("Resend", tableName: "MemberCenterLocalizable", comment: "") {
  268. if viewModel.email.count > 0 {
  269. if viewModel.isValidEmail() {
  270. sendBox.fillColor = NSColor(named: "273C62") ?? NSColor.blue
  271. } else {
  272. sendBox.fillColor = NSColor(named: "273C62_0.4") ?? NSColor.blue
  273. }
  274. } else {
  275. sendBox.fillColor = NSColor(named: "273C62_0.4") ?? NSColor.blue
  276. }
  277. sendLabel.textColor = NSColor(named: "FFFFFF") ?? NSColor.white
  278. } else {
  279. sendBox.fillColor = NSColor(named: "DADBDE") ?? NSColor.gray
  280. sendLabel.stringValue = String(format: "%@s", viewModel.sendContent)
  281. sendLabel.textColor = NSColor(named: "0E1114") ?? NSColor.black
  282. }
  283. }
  284. private func _showPop() {
  285. guard let _ = self.window else {
  286. return
  287. }
  288. if (self.popOver_ != nil) {
  289. return
  290. }
  291. let popViewController = KMToolbarItemPopViewController()
  292. self.popOver_ = NSPopover()
  293. self.popOver_?.contentViewController = popViewController
  294. self.popOver_?.animates = false
  295. self.popOver_?.behavior = .semitransient
  296. self.popOver_?.contentSize = popViewController.view.frame.size
  297. self.popOver_?.delegate = self
  298. // 0.8
  299. var color = NSColor(hex: "#273C62").withAlphaComponent(1)
  300. if KMAppearance.isDarkMode() {
  301. color = NSColor(hex: "#4E7FDB").withAlphaComponent(1)
  302. }
  303. popViewController.view.wantsLayer = true
  304. popViewController.view.layer?.backgroundColor = color.cgColor
  305. self.popOver_?.setBackgroundColor(color)
  306. popViewController.toolbarHelpTipLabel.textColor = .white
  307. popViewController.toolbarHelpTipLabel.font = .SFProTextRegularFont(13)
  308. popViewController.contentInset = .init(top: 12, left: 8, bottom: 12, right: 8)
  309. popViewController.updateWithHelpTip(helpTip: NSLocalizedString("Please agree and check the agreement first.", tableName: "MemberCenterLocalizable", comment: ""))
  310. self.popOver_?.show(relativeTo: NSMakeRect(0, 0, 0, 12), of: privacyCheckButton, preferredEdge: .maxY)
  311. }
  312. // MARK: Bind Method
  313. func bindViewModel() -> Void {
  314. viewModel.$isVisible
  315. .receive(on: RunLoop.main)
  316. .sink { [weak self] newValue in
  317. self?.visibleStateChange()
  318. }
  319. .store(in: &cancellables)
  320. viewModel.$stayState
  321. .receive(on: RunLoop.main)
  322. .sink { [weak self] newValue in
  323. self?.checkStateChange(button: self?.stayCheckButton, state: newValue)
  324. }
  325. .store(in: &cancellables)
  326. viewModel.$privacyState
  327. .receive(on: RunLoop.main)
  328. .sink { [weak self] newValue in
  329. self?.checkStateChange(button: self?.privacyCheckButton, state: newValue)
  330. self?.popOver_?.close()
  331. }
  332. .store(in: &cancellables)
  333. viewModel.$signUpState
  334. .receive(on: RunLoop.main)
  335. .sink { [weak self] newValue in
  336. self?.signUpStateChange()
  337. }
  338. .store(in: &cancellables)
  339. viewModel.$emailErrorMessage
  340. .receive(on: RunLoop.main)
  341. .sink { [weak self] newValue in
  342. self?.emailErrorLabel.stringValue = newValue
  343. self?.emailErrorLabel.isHidden = false
  344. self?.textfieldInputState(isEmail: true)
  345. }
  346. .store(in: &cancellables)
  347. viewModel.$passwordErrorMessage
  348. .receive(on: RunLoop.main)
  349. .sink { [weak self] newValue in
  350. self?.passwordErrorLabel.stringValue = newValue
  351. if self?.viewModel.passwordErrorMessage == "" {
  352. self?.passwordErrorLabel.isHidden = true
  353. } else {
  354. self?.passwordErrorLabel.isHidden = false
  355. }
  356. }
  357. .store(in: &cancellables)
  358. viewModel.$sendContent
  359. .receive(on: RunLoop.main)
  360. .sink { [weak self] newValue in
  361. self?.sendBoxRefresh()
  362. }
  363. .store(in: &cancellables)
  364. viewModel.$email
  365. .receive(on: RunLoop.main)
  366. .sink { [weak self] newValue in
  367. self?.sendBoxRefresh()
  368. }
  369. .store(in: &cancellables)
  370. viewModel.$verificationCode
  371. .receive(on: RunLoop.main)
  372. .sink { [weak self] newValue in
  373. if newValue.count <= 6 && newValue.count >= 0 {
  374. self?.viewModel.passwordErrorMessage = ""
  375. } else {
  376. self?.viewModel.passwordErrorMessage = NSLocalizedString("Verification code error.", tableName: "MemberCenterLocalizable", comment: "")
  377. }
  378. }
  379. .store(in: &cancellables)
  380. viewModel.$password
  381. .receive(on: RunLoop.main)
  382. .sink { [weak self] newValue in
  383. if newValue.count <= 30 && newValue.count >= 0 {
  384. self?.viewModel.passwordErrorMessage = ""
  385. } else {
  386. self?.viewModel.passwordErrorMessage = NSLocalizedString("Password cannot exceed 30 characters.", tableName: "MemberCenterLocalizable", comment: "")
  387. }
  388. }
  389. .store(in: &cancellables)
  390. viewModel.$privacyPopShow
  391. .receive(on: RunLoop.main)
  392. .sink { [weak self] newValue in
  393. if newValue {
  394. KMMainThreadExecute {
  395. self?._showPop()
  396. }
  397. }
  398. }
  399. .store(in: &cancellables)
  400. }
  401. // MARK: Action Method
  402. @IBAction func verificationCodeAction(_ sender: NSButton) {
  403. viewModel.signUpStateChange(state: .verificationCode)
  404. }
  405. @IBAction func passwordAction(_ sender: NSButton) {
  406. viewModel.signUpStateChange(state: .password)
  407. }
  408. @IBAction func visibleAction(_ sender: NSButton) {
  409. viewModel.isVisible.toggle()
  410. }
  411. @IBAction func stayCheckAction(_ sender: NSButton) {
  412. viewModel.stayState.toggle()
  413. viewModel.stayStateAction()
  414. }
  415. @IBAction func signUpAction(_ sender: NSButton) {
  416. self.window?.makeFirstResponder(nil)
  417. viewModel.emailErrorMessage = ""
  418. viewModel.passwordErrorMessage = ""
  419. window?.showWaitingView()
  420. viewModel.signUpAction { [weak self] result, _ in
  421. self?.window?.hideWaitingView()
  422. }
  423. }
  424. @IBAction func forgetAction(_ sender: NSButton) {
  425. guard let parentView = self.superview else { return }
  426. if parentView is NSBox {
  427. let model = KMSignUpViewModel()
  428. model.email = viewModel.email
  429. let forgotView = KMForgotPasswordView(model: model, superView: parentView)
  430. NSAnimationContext.runAnimationGroup { context in
  431. context.duration = 0.3
  432. self.animator().alphaValue = 0
  433. } completionHandler: {
  434. self.removeFromSuperview()
  435. forgotView.alphaValue = 0
  436. (parentView as! NSBox).contentView = forgotView
  437. NSAnimationContext.runAnimationGroup({ context in
  438. context.duration = 0.3
  439. forgotView.animator().alphaValue = 1
  440. }, completionHandler: nil)
  441. }
  442. } else {
  443. let model = KMSignUpViewModel()
  444. model.email = viewModel.email
  445. let forgotView = KMForgotPasswordView(model: model, superView: parentView)
  446. NSAnimationContext.runAnimationGroup { context in
  447. context.duration = 0.3
  448. self.animator().alphaValue = 0
  449. } completionHandler: {
  450. self.removeFromSuperview()
  451. forgotView.alphaValue = 0
  452. parentView.addSubview(forgotView)
  453. NSAnimationContext.runAnimationGroup({ context in
  454. context.duration = 0.3
  455. forgotView.animator().alphaValue = 1
  456. }, completionHandler: nil)
  457. }
  458. }
  459. }
  460. @IBAction func privacyCheckAction(_ sender: NSButton) {
  461. viewModel.privacyState.toggle()
  462. }
  463. }
  464. extension KMSignUpView: NSTextFieldDelegate {
  465. func controlTextDidEndEditing(_ obj: Notification) {
  466. let textField = obj.object as? NSTextField
  467. if textField == emailTextField {
  468. viewModel.email = textField!.stringValue
  469. } else if textField == verifficationTextField {
  470. viewModel.verificationCode = textField!.stringValue
  471. } else if textField == passwordTextField {
  472. viewModel.password = textField!.stringValue
  473. } else if textField == passwordTextField1 {
  474. viewModel.password = textField!.stringValue
  475. }
  476. }
  477. func controlTextDidChange(_ obj: Notification) {
  478. let textField = obj.object as? NSTextField
  479. if textField == emailTextField {
  480. viewModel.emailErrorMessage = ""
  481. viewModel.email = textField!.stringValue
  482. emailBox.borderColor = NSColor(named: "DADBDE") ?? NSColor.gray
  483. } else if textField == verifficationTextField {
  484. viewModel.passwordErrorMessage = ""
  485. viewModel.verificationCode = textField!.stringValue
  486. verifficationBox.borderColor = NSColor(named: "DADBDE") ?? NSColor.gray
  487. } else if textField == passwordTextField {
  488. viewModel.passwordErrorMessage = ""
  489. viewModel.password = textField!.stringValue
  490. passwordBox.borderColor = NSColor(named: "DADBDE") ?? NSColor.gray
  491. } else if textField == passwordTextField1 {
  492. viewModel.passwordErrorMessage = ""
  493. viewModel.password = textField!.stringValue
  494. passwordBox.borderColor = NSColor(named: "DADBDE") ?? NSColor.gray
  495. }
  496. }
  497. @objc func loginSuccessNotification() -> Void {
  498. resetTextFileData()
  499. }
  500. }
  501. extension KMSignUpView: NSPopoverDelegate {
  502. func popoverDidClose(_ notification: Notification) {
  503. if let data = self.popOver_?.isEqual(to: notification.object), data {
  504. self.popOver_ = nil
  505. }
  506. }
  507. }