Commit f75b3010 authored by David黄金龙's avatar David黄金龙

完善 登录逻辑

parent 1e0b46a9
......@@ -94,13 +94,20 @@ class YHCodeSueecssViewController: YHBaseViewController {
let view = YHSmsCodeInputView(config: YHSmsCodeViewConfig())
view.complete = { [weak self] code in
guard let self = self else { return }
self.viewModel?.login(self.phoneNumber ?? "", code: code, callBackBlock: {[weak self] success in
guard let self = self else { return }
YHLoginManager.shared.userModel = success
if success?.token?.count != 0 {
self.dismiss(animated: true)
}
})
if let phone = self.phoneNumber {
self.viewModel?.login(phone : phone, code: code, callBackBlock: {[weak self] success,error in
guard let self = self else { return }
if success == false {
YHHUD.flash(message: "登录失败")
} else {
YHHUD.flash(message: "登录成功")
self.dismiss(animated: true)
}
})
} else {
printLog("errror : 电话号码为空")
}
}
return view
}()
......@@ -183,7 +190,7 @@ class YHCodeSueecssViewController: YHBaseViewController {
@objc func startClicked() {
viewModel?.getLoginCode(phoneNumber ?? "", callBackBlock: {[weak self] success in
viewModel?.getLoginCode(phoneNumber ?? "", callBackBlock: {[weak self] success,error in
guard let self = self else { return }
self.startTime()
})
......
......@@ -175,7 +175,7 @@ class YHPhoneLoginViewController: YHBaseViewController {
return
}
if privacyView.isAgree {
viewModel?.getLoginCode(phoneNumer, callBackBlock: {[weak self] success in
viewModel?.getLoginCode(phoneNumer, callBackBlock: {[weak self] success,error in
guard let self = self else { return }
let vc = YHCodeSueecssViewController()
vc.phoneNumber = self.phoneMessageView.phoneTextField.text
......
......@@ -16,7 +16,8 @@ class YHLoginManager: NSObject {
private override init() {}
func isLogin() -> Bool {
if userModel?.token?.count != 0 {
let ttt = userModel?.token?.count ?? 0
if ttt != 0 {
return true
}
return false
......
......@@ -45,7 +45,7 @@ class YHLoginPrivacyView: UIView {
let label = UILabel()
label.text = "我已阅读并同意"
label.font = UIFont.PFSC_R(ofSize: 12)
label.textColor = UIColor.contentBkgColor
label.textColor = UIColor.labelTextColor2
label.textAlignment = .left
return label
}()
......@@ -75,7 +75,7 @@ class YHLoginPrivacyView: UIView {
let label = UILabel()
label.text = "和"
label.font = UIFont.PFSC_R(ofSize: 12)
label.textColor = UIColor.contentBkgColor
label.textColor = UIColor.labelTextColor2
label.textAlignment = .left
return label
}()
......
......@@ -19,45 +19,67 @@ class YHLoginViewModel: YHBaseViewModel {
//接口
extension YHLoginViewModel {
//发送验证码
func getLoginCode(_ phone: String, callBackBlock: @escaping (_ success: Bool)->()) {
func getLoginCode(_ phone: String, callBackBlock: @escaping (_ success: Bool,_ error:YHErrorModel?)->()) {
let params: [String : Any] = ["type": "Phone",
"value": phone]
let strUrl = "http://192.168.35.135:18087/" + "user/verify-code"
"value": phone,
"extend":"register"]
let strUrl = "http://test-cuser.galaxy-immi.com/" + "user/verify-code"
let _ = YHNetRequest.postRequest(url: strUrl, params: params) {[weak self] json, code in
guard let self = self else { return }
guard let model = NetBaseModel.deserialize(dict: json) else {
let error : YHErrorModel = YHErrorModel(errorCode:YHErrorCode.dictParseError.rawValue,errorMsg: YHErrorCode.dictParseError.description())
callBackBlock( false,error)
return
}
//1. json字符串 转 对象
if code == 200 {
callBackBlock(true)
if model.code == 200 {
callBackBlock(true,nil)
} else {
let error : YHErrorModel = YHErrorModel(errorCode:Int32(model.code),errorMsg: model.msg)
callBackBlock(false,error)
}
} failBlock: { err in
callBackBlock(false)
callBackBlock(false,err)
}
}
func login(_ phone: String, code: String,callBackBlock: @escaping (_ success: YHUserModel?)->()) {
func login(phone: String, code: String,callBackBlock: @escaping (_ success: Bool,_ error: YHErrorModel?)->()) {
let params: [String : Any] = ["mobile": phone,
"sms_code": code,
"channel": "app",
"client": "super_app"]
let strUrl = "http://192.168.25.12:18083/" + "auth/login"
let strUrl = "http://test.api.diymanager.galaxy-immi.com/" + "auth/login"
let _ = YHNetRequest.postRequest(url: strUrl, params: params) {[weak self] json, code in
//1. json字符串 转 对象
guard let self = self else { return }
guard let model = NetBaseModel.deserialize(dict: json) else {
let error : YHErrorModel = YHErrorModel(errorCode:YHErrorCode.dictParseError.rawValue,errorMsg: YHErrorCode.dictParseError.description())
callBackBlock(nil)
callBackBlock(false,error)
return
}
let dic = model.data?.peel
guard let resultModel = YHUserModel.deserialize(dict: dic as? [AnyHashable : Any]) else {
callBackBlock(nil)
let error : YHErrorModel = YHErrorModel(errorCode:-1,errorMsg: "数据解析不成功")
callBackBlock(false,error)
return
}
self.userModel = resultModel
callBackBlock(resultModel)
if resultModel.token?.count != 0 {
//token 正常
self.userModel = resultModel
YHLoginManager.shared.userModel = resultModel
callBackBlock(true,nil)
} else {
let error : YHErrorModel = YHErrorModel(errorCode:-2,errorMsg: "token 不合法")
callBackBlock(false,error)
}
} failBlock: { err in
callBackBlock(nil)
callBackBlock(false,err)
}
}
}
......@@ -101,13 +101,13 @@ extension YHMyViewController : UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if (indexPath.row >= items.count) { return }
let vc = UINavigationController(rootVC: YHPhoneLoginViewController())
vc.modalPresentationStyle = .custom
self.navigationController?.present(vc, animated: true)
// let vc = YHFamilyMemberFormVC(orderId: 133971)
// self.navigationController?.pushViewController(vc)
return
if YHLoginManager.shared.isLogin() == false {
let vc = UINavigationController(rootVC: YHPhoneLoginViewController())
vc.modalPresentationStyle = .custom
self.navigationController?.present(vc, animated: true)
}
return //for test hjl
let item: PersonalModuleItem = items[indexPath.row];
......@@ -134,8 +134,8 @@ extension YHMyViewController : UITableViewDelegate, UITableViewDataSource {
} else {
let vc = YHLoginViewController()
self.navigationController?.pushViewController(vc)
// let vc = YHLoginViewController()
// self.navigationController?.pushViewController(vc)
}
}
......
......@@ -2,6 +2,11 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSCameraUsageDescription</key>
<string>cameraDesciption</string>
<key>NSPhotoLibraryUsageDescription</key>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment