|
@@ -94,11 +94,11 @@ class KMSignUpViewModel: ObservableObject {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- func countDown(type: KMVerificationCodeType, count: Int = 60) -> Void {
|
|
|
+ func countDown(type: KMVerificationCodeType, count: Int = 60, callback: ((Bool?, Any ...)->Void)?) -> Void {
|
|
|
if emailErrorMessage.count > 0 || !isValidEmail() {
|
|
|
return
|
|
|
}
|
|
|
- getVerificationCode(type)
|
|
|
+ getVerificationCode(type, callback: callback)
|
|
|
|
|
|
sendBoxSelect = true
|
|
|
remainingSeconds = count
|
|
@@ -194,7 +194,7 @@ class KMSignUpViewModel: ObservableObject {
|
|
|
@abstract KMSignUpView Sign Up 登录按钮响应事件
|
|
|
@param
|
|
|
*/
|
|
|
- func signUpAction() -> Void {
|
|
|
+ func signUpAction(callback: ((Bool?, Any ...)->Void)?) -> Void {
|
|
|
if KMMemberCenterManager.manager.isConnectionAvailable() == false {
|
|
|
let alert = NSAlert()
|
|
|
alert.alertStyle = .critical
|
|
@@ -202,10 +202,14 @@ class KMSignUpViewModel: ObservableObject {
|
|
|
alert.informativeText = NSLocalizedString("Please make sure your internet connection is available.", comment: "")
|
|
|
alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
|
|
|
alert.runModal()
|
|
|
+
|
|
|
+ callback?(nil)
|
|
|
return
|
|
|
}
|
|
|
if email.count <= 0 || email.count > 100 || !isValidEmail() {
|
|
|
emailErrorMessage = NSLocalizedString("Email format error. Please enter the correct email.", tableName: "MemberCenterLocalizable", comment: "")
|
|
|
+
|
|
|
+ callback?(nil)
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -213,12 +217,16 @@ class KMSignUpViewModel: ObservableObject {
|
|
|
if signUpState == .verificationCode {
|
|
|
if verificationCode.count <= 0 || verificationCode.count > 6 || !isValidVerificationCode() {
|
|
|
passwordErrorMessage = NSLocalizedString("Verification code error.", tableName: "MemberCenterLocalizable", comment: "")
|
|
|
+
|
|
|
+ callback?(nil)
|
|
|
return
|
|
|
}
|
|
|
code = verificationCode
|
|
|
} else if signUpState == .password {
|
|
|
if password.count <= 0 || verificationCode.count > 30 {
|
|
|
passwordErrorMessage = NSLocalizedString("Password error.", tableName: "MemberCenterLocalizable", comment: "")
|
|
|
+
|
|
|
+ callback?(nil)
|
|
|
return
|
|
|
}
|
|
|
code = password
|
|
@@ -232,9 +240,13 @@ class KMSignUpViewModel: ObservableObject {
|
|
|
if (result == .alertFirstButtonReturn) {
|
|
|
privacyState = true
|
|
|
}
|
|
|
+
|
|
|
+ callback?(nil)
|
|
|
return
|
|
|
}
|
|
|
KMMemberCenterManager.manager.emailLogin(email: email, code: code, type: signUpState) { [weak self] success, wrapper in
|
|
|
+ callback?(success)
|
|
|
+
|
|
|
guard let self = self else { return }
|
|
|
let resultDict = wrapper! as KMMemberCenterResult
|
|
|
let msg = resultDict.msg
|
|
@@ -289,7 +301,7 @@ class KMSignUpViewModel: ObservableObject {
|
|
|
if response == .alertFirstButtonReturn {
|
|
|
if(resultDict.code == 317) {
|
|
|
self.signUpState = .verificationCode
|
|
|
- self.countDown(type: .login)
|
|
|
+ self.countDown(type: .login, callback: nil)
|
|
|
} else {
|
|
|
|
|
|
}
|
|
@@ -370,7 +382,7 @@ class KMSignUpViewModel: ObservableObject {
|
|
|
@abstract 获取邮箱验证码
|
|
|
@param
|
|
|
*/
|
|
|
- func getVerificationCode(_ type: KMVerificationCodeType) -> Void {
|
|
|
+ func getVerificationCode(_ type: KMVerificationCodeType, callback: ((Bool?, Any ...)->Void)?) -> Void {
|
|
|
if KMMemberCenterManager.manager.isConnectionAvailable() == false {
|
|
|
let alert = NSAlert()
|
|
|
alert.alertStyle = .critical
|
|
@@ -378,14 +390,20 @@ class KMSignUpViewModel: ObservableObject {
|
|
|
alert.informativeText = NSLocalizedString("Please make sure your internet connection is available.", comment: "")
|
|
|
alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
|
|
|
alert.runModal()
|
|
|
+
|
|
|
+ callback?(nil)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
if !isValidEmail() {
|
|
|
emailErrorMessage = NSLocalizedString("Please enter the correct email format", tableName: "MemberCenterLocalizable", comment: "")
|
|
|
+
|
|
|
+ callback?(nil)
|
|
|
return
|
|
|
}
|
|
|
KMMemberCenterManager.manager.getVerificationCode(action: type, receiver: email) { [weak self] success, wrapper in
|
|
|
+ callback?(success)
|
|
|
+
|
|
|
guard let self = self else { return }
|
|
|
let resultDict = wrapper! as KMMemberCenterResult
|
|
|
let msg = resultDict.msg
|