diff --git a/YuMi/E-P/NewLogin/Controllers/EPLoginTypesViewController.swift b/YuMi/E-P/NewLogin/Controllers/EPLoginTypesViewController.swift index 7ef1a7f..c58d996 100644 --- a/YuMi/E-P/NewLogin/Controllers/EPLoginTypesViewController.swift +++ b/YuMi/E-P/NewLogin/Controllers/EPLoginTypesViewController.swift @@ -7,14 +7,13 @@ import UIKit -class EPLoginTypesViewController: UIViewController { +class EPLoginTypesViewController: BaseViewController { // MARK: - Properties var displayType: EPLoginDisplayType = .id private let loginService = EPLoginService() - private let validator = EPLoginValidator() private let backgroundImageView = UIImageView() private let titleLabel = UILabel() @@ -380,14 +379,14 @@ class EPLoginTypesViewController: UIViewController { let id = firstInputView.text.trimmingCharacters(in: .whitespacesAndNewlines) let password = secondInputView.text - // 表单验证 + // 表单验证(简化,仅检查空值) guard !id.isEmpty else { - showAlert("请输入用户ID") + showErrorToast(YMLocalizedString("LoginPresenter0")) return } guard !password.isEmpty else { - showAlert("请输入密码") + showErrorToast(YMLocalizedString("LoginPresenter1")) return } @@ -397,13 +396,14 @@ class EPLoginTypesViewController: UIViewController { loginService.loginWithID(id: id, password: password) { [weak self] (accountModel: AccountModel) in DispatchQueue.main.async { self?.showLoading(false) - print("[EPLogin] ID登录成功: \(accountModel.uid ?? "")") + print("[EPLogin] ID登录成功: \(accountModel.uid)") + self?.showSuccessToast(YMLocalizedString("XPLoginPhoneViewController1")) EPLoginManager.jumpToHome(from: self!) } } failure: { [weak self] (code: Int, msg: String) in DispatchQueue.main.async { self?.showLoading(false) - self?.showAlert("登录失败: \(msg)") + self?.showErrorToast(msg) } } } @@ -412,14 +412,14 @@ class EPLoginTypesViewController: UIViewController { let email = firstInputView.text.trimmingCharacters(in: .whitespacesAndNewlines) let code = secondInputView.text - // 表单验证 - guard validator.validateEmail(email) else { - showAlert("请输入正确的邮箱地址") + // 表单验证(简化,仅检查空值) + guard !email.isEmpty else { + showErrorToast(YMLocalizedString("LoginPresenter0")) return } - guard validator.validateCode(code) else { - showAlert("请输入6位数字验证码") + guard !code.isEmpty else { + showErrorToast(YMLocalizedString("LoginPresenter1")) return } @@ -428,13 +428,14 @@ class EPLoginTypesViewController: UIViewController { loginService.loginWithEmail(email: email, code: code) { [weak self] (accountModel: AccountModel) in DispatchQueue.main.async { self?.showLoading(false) - print("[EPLogin] 邮箱登录成功: \(accountModel.uid ?? "")") + print("[EPLogin] 邮箱登录成功: \(accountModel.uid)") + self?.showSuccessToast(YMLocalizedString("XPLoginPhoneViewController1")) EPLoginManager.jumpToHome(from: self!) } } failure: { [weak self] (code: Int, msg: String) in DispatchQueue.main.async { self?.showLoading(false) - self?.showAlert("登录失败: \(msg)") + self?.showErrorToast(msg) } } } @@ -443,14 +444,14 @@ class EPLoginTypesViewController: UIViewController { let phone = firstInputView.text.trimmingCharacters(in: .whitespacesAndNewlines) let code = secondInputView.text - // 表单验证 - guard validator.validatePhone(phone) else { - showAlert("请输入正确的手机号") + // 表单验证(简化,仅检查空值) + guard !phone.isEmpty else { + showErrorToast(YMLocalizedString("XPLoginPhoneViewController0")) return } - guard validator.validateCode(code) else { - showAlert("请输入6位数字验证码") + guard !code.isEmpty else { + showErrorToast(YMLocalizedString("LoginPresenter1")) return } @@ -459,13 +460,14 @@ class EPLoginTypesViewController: UIViewController { loginService.loginWithPhone(phone: phone, code: code, areaCode: "+86") { [weak self] (accountModel: AccountModel) in DispatchQueue.main.async { self?.showLoading(false) - print("[EPLogin] 手机登录成功: \(accountModel.uid ?? "")") + print("[EPLogin] 手机登录成功: \(accountModel.uid)") + self?.showSuccessToast(YMLocalizedString("XPLoginPhoneViewController1")) EPLoginManager.jumpToHome(from: self!) } } failure: { [weak self] (code: Int, msg: String) in DispatchQueue.main.async { self?.showLoading(false) - self?.showAlert("登录失败: \(msg)") + self?.showErrorToast(msg) } } } @@ -477,19 +479,19 @@ class EPLoginTypesViewController: UIViewController { let code = secondInputView.text let newPassword = thirdInput.text - // 表单验证 - guard validator.validateEmail(email) else { - showAlert("请输入正确的邮箱地址") + // 表单验证(简化,仅检查空值) + guard !email.isEmpty else { + showErrorToast(YMLocalizedString("LoginPresenter0")) return } - guard validator.validateCode(code) else { - showAlert("请输入6位数字验证码") + guard !code.isEmpty else { + showErrorToast(YMLocalizedString("LoginPresenter1")) return } - guard validator.validatePassword(newPassword) else { - showAlert("密码需6-16位,包含字母和数字") + guard !newPassword.isEmpty else { + showErrorToast(YMLocalizedString("LoginPresenter1")) return } @@ -498,14 +500,13 @@ class EPLoginTypesViewController: UIViewController { loginService.resetEmailPassword(email: email, code: code, newPassword: newPassword) { [weak self] in DispatchQueue.main.async { self?.showLoading(false) - self?.showAlert("密码重置成功", completion: { - self?.navigationController?.popViewController(animated: true) - }) + self?.showSuccessToast(YMLocalizedString("XPForgetPwdViewController1")) + self?.navigationController?.popViewController(animated: true) } } failure: { [weak self] (code: Int, msg: String) in DispatchQueue.main.async { self?.showLoading(false) - self?.showAlert("重置失败: \(msg)") + self?.showErrorToast(msg) } } } @@ -517,19 +518,19 @@ class EPLoginTypesViewController: UIViewController { let code = secondInputView.text let newPassword = thirdInput.text - // 表单验证 - guard validator.validatePhone(phone) else { - showAlert("请输入正确的手机号") + // 表单验证(简化,仅检查空值) + guard !phone.isEmpty else { + showErrorToast(YMLocalizedString("XPLoginPhoneViewController0")) return } - guard validator.validateCode(code) else { - showAlert("请输入6位数字验证码") + guard !code.isEmpty else { + showErrorToast(YMLocalizedString("LoginPresenter1")) return } - guard validator.validatePassword(newPassword) else { - showAlert("密码需6-16位,包含字母和数字") + guard !newPassword.isEmpty else { + showErrorToast(YMLocalizedString("LoginPresenter1")) return } @@ -538,14 +539,13 @@ class EPLoginTypesViewController: UIViewController { loginService.resetPhonePassword(phone: phone, code: code, areaCode: "+86", newPassword: newPassword) { [weak self] in DispatchQueue.main.async { self?.showLoading(false) - self?.showAlert("密码重置成功", completion: { - self?.navigationController?.popViewController(animated: true) - }) + self?.showSuccessToast(YMLocalizedString("XPForgetPwdViewController1")) + self?.navigationController?.popViewController(animated: true) } } failure: { [weak self] (code: Int, msg: String) in DispatchQueue.main.async { self?.showLoading(false) - self?.showAlert("重置失败: \(msg)") + self?.showErrorToast(msg) } } } @@ -555,8 +555,9 @@ class EPLoginTypesViewController: UIViewController { private func sendEmailCode() { let email = firstInputView.text.trimmingCharacters(in: .whitespacesAndNewlines) - guard validator.validateEmail(email) else { - showAlert("请输入正确的邮箱地址") + // 简化验证,仅检查空值 + guard !email.isEmpty else { + secondInputView.stopCountdown() return } @@ -565,11 +566,13 @@ class EPLoginTypesViewController: UIViewController { loginService.sendEmailCode(email: email, type: type) { [weak self] in DispatchQueue.main.async { self?.secondInputView.startCountdown() - self?.showAlert("验证码已发送") + self?.secondInputView.displayKeyboard() + self?.showSuccessToast(YMLocalizedString("XPLoginPhoneViewController2")) } } failure: { [weak self] (code: Int, msg: String) in DispatchQueue.main.async { - self?.showAlert("发送失败: \(msg)") + self?.secondInputView.stopCountdown() + self?.showErrorToast(msg) } } } @@ -577,8 +580,10 @@ class EPLoginTypesViewController: UIViewController { private func sendPhoneCode() { let phone = firstInputView.text.trimmingCharacters(in: .whitespacesAndNewlines) - guard validator.validatePhone(phone) else { - showAlert("请输入正确的手机号") + // 简化验证,仅检查空值 + guard !phone.isEmpty else { + showErrorToast(YMLocalizedString("XPLoginPhoneViewController0")) + secondInputView.stopCountdown() return } @@ -591,11 +596,13 @@ class EPLoginTypesViewController: UIViewController { self.loginService.sendPhoneCode(phone: phone, areaCode: "+86", type: type) { [weak self] in DispatchQueue.main.async { self?.secondInputView.startCountdown() - self?.showAlert("验证码已发送") + self?.secondInputView.displayKeyboard() + self?.showSuccessToast(YMLocalizedString("XPLoginPhoneViewController2")) } } failure: { [weak self] (code: Int, msg: String) in DispatchQueue.main.async { - self?.showAlert("发送失败: \(msg)") + self?.secondInputView.stopCountdown() + self?.showErrorToast(msg) } } } @@ -653,14 +660,6 @@ class EPLoginTypesViewController: UIViewController { actionButton.alpha = isEnabled ? 1.0 : 0.5 } - private func showAlert(_ message: String, completion: (() -> Void)? = nil) { - let alert = UIAlertController(title: nil, message: message, preferredStyle: .alert) - alert.addAction(UIAlertAction(title: "确定", style: .default) { _ in - completion?() - }) - present(alert, animated: true) - } - /// 加载人机验证 Captcha WebView /// - Parameter completion: 验证成功后的回调 private func loadCaptchaWebView(completion: @escaping () -> Void) { diff --git a/YuMi/E-P/NewLogin/Services/EPLoginService.swift b/YuMi/E-P/NewLogin/Services/EPLoginService.swift index e4e0dc4..9ee2218 100644 --- a/YuMi/E-P/NewLogin/Services/EPLoginService.swift +++ b/YuMi/E-P/NewLogin/Services/EPLoginService.swift @@ -15,7 +15,6 @@ import Foundation private let clientSecret = EPLoginConfig.API.clientSecret private let clientId = EPLoginConfig.API.clientId - private let grantType = EPLoginConfig.API.grantType private let version = EPLoginConfig.API.version // MARK: - Private Helper Methods @@ -151,7 +150,7 @@ import Foundation client_secret: clientSecret, version: version, client_id: clientId, - grant_type: grantType) + grant_type: "password") } /// 邮箱 + 验证码登录 @@ -182,7 +181,7 @@ import Foundation client_secret: clientSecret, version: version, client_id: clientId, - grant_type: grantType) + grant_type: "email") } /// 手机号 + 验证码登录 @@ -215,7 +214,7 @@ import Foundation client_secret: clientSecret, version: version, client_id: clientId, - grant_type: grantType, + grant_type: "password", phoneAreaCode: areaCode) } diff --git a/YuMi/E-P/NewLogin/Views/EPLoginInputView.swift b/YuMi/E-P/NewLogin/Views/EPLoginInputView.swift index 67d1256..aae19d0 100644 --- a/YuMi/E-P/NewLogin/Views/EPLoginInputView.swift +++ b/YuMi/E-P/NewLogin/Views/EPLoginInputView.swift @@ -249,6 +249,11 @@ class EPLoginInputView: UIView { inputTextField.text = "" } + /// 弹出键盘(自动聚焦输入框) + func displayKeyboard() { + inputTextField.becomeFirstResponder() + } + // MARK: - Actions @objc private func handleAreaTap() {