Browse Source

验证码判断增加判断手机号

fuwencai 4 năm trước cách đây
mục cha
commit
0035abab3c

+ 3 - 2
src/github.com/baiy/Cadmin-server-go/system/index/index.go

@@ -114,8 +114,9 @@ func Login(context *admin.Context) (interface{}, error) {
 		phoneCode := util.ObjToString(session.Values["code"])
 		log.Println("phoneCode", phoneCode)
 		log.Println("param.PhoneCode", param.PhoneCode)
-		// phone := util.ObjToString(session.Values["phone"])
-		if phoneCode != param.PhoneCode {
+		phone := util.ObjToString(session.Values["phone"])
+
+		if phoneCode != param.PhoneCode || phone != u.Phone {
 			return nil, errors.New("手机验证码错误")
 		}
 	}

+ 9 - 5
src/github.com/baiy/Cadmin-server-go/system/user/user.go

@@ -83,9 +83,13 @@ func Save(context *admin.Context) (interface{}, error) {
 		password = string(admin.Passworder.Hash([]byte(param.Password)))
 	}
 	if param.LoginType == "2" { //点击发送手机验证码
-		_, err := thisModel.GetByPhone(param.Phone)
-		if err == nil {
-			return nil, errors.New("手机号已绑定其他账号")
+		phoneExist, _ := thisModel.GetByPhone(param.Phone)
+		if phoneExist.Id > 0 {
+			if phoneExist.Id != param.Id {
+				return nil, errors.New("手机号已绑定其他账号")
+			} else {
+				return nil, errors.New("手机号与原手机号一致")
+			}
 		}
 		if SendPhoneIdentCode(context, param.Phone) {
 			return map[string]interface{}{"status": 3}, nil
@@ -102,8 +106,8 @@ func Save(context *admin.Context) (interface{}, error) {
 			return nil, errors.New("手机验证码不能为空")
 		}
 		phoneCode := util.ObjToString(session.Values["code"])
-		// phone := util.ObjToString(session.Values["phone"])
-		if phoneCode != param.PhoneCode {
+		phone := util.ObjToString(session.Values["phone"])
+		if phone != param.Phone || phoneCode != param.PhoneCode {
 			return nil, errors.New("手机验证码错误")
 		}
 	}