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