lhs 5 лет назад
Родитель
Сommit
95c7631afc
7 измененных файлов с 143 добавлено и 29 удалено
  1. 39 0
      docs/docs.go
  2. 39 0
      docs/swagger.json
  3. 26 0
      docs/swagger.yaml
  4. 1 1
      middleware/logger.go
  5. 6 7
      model/session.go
  6. 1 2
      repository/http/loallout_server.go
  7. 31 19
      service/auth.go

+ 39 - 0
docs/docs.go

@@ -146,6 +146,45 @@ var doc = `{
                 }
             }
         },
+        "/Auth/PhoneSignIn": {
+            "post": {
+                "description": "手机验证码登录",
+                "consumes": [
+                    "application/x-www-form-urlencoded"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "Auth"
+                ],
+                "summary": "手机验证码登录",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "手机号",
+                        "name": "phone",
+                        "in": "formData",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "验证码",
+                        "name": "smsCode",
+                        "in": "formData",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/controller.ResponseBase"
+                        }
+                    }
+                }
+            }
+        },
         "/Auth/SignUp": {
             "post": {
                 "description": "用户添加",

+ 39 - 0
docs/swagger.json

@@ -130,6 +130,45 @@
                 }
             }
         },
+        "/Auth/PhoneSignIn": {
+            "post": {
+                "description": "手机验证码登录",
+                "consumes": [
+                    "application/x-www-form-urlencoded"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "Auth"
+                ],
+                "summary": "手机验证码登录",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "手机号",
+                        "name": "phone",
+                        "in": "formData",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "验证码",
+                        "name": "smsCode",
+                        "in": "formData",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/controller.ResponseBase"
+                        }
+                    }
+                }
+            }
+        },
         "/Auth/SignUp": {
             "post": {
                 "description": "用户添加",

+ 26 - 0
docs/swagger.yaml

@@ -144,6 +144,32 @@ paths:
       summary: 手机获取验证码
       tags:
       - Auth
+  /Auth/PhoneSignIn:
+    post:
+      consumes:
+      - application/x-www-form-urlencoded
+      description: 手机验证码登录
+      parameters:
+      - description: 手机号
+        in: formData
+        name: phone
+        required: true
+        type: string
+      - description: 验证码
+        in: formData
+        name: smsCode
+        required: true
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/controller.ResponseBase'
+      summary: 手机验证码登录
+      tags:
+      - Auth
   /Auth/SignUp:
     post:
       consumes:

+ 1 - 1
middleware/logger.go

@@ -34,7 +34,7 @@ func Logger() gin.HandlerFunc {
 				_ = c.Error(err)
 			}
 
-			userid := 0
+			userid := ""
 			src := ""
 
 			endTime := time.Now()

+ 6 - 7
model/session.go

@@ -6,25 +6,24 @@ package model
 
 import (
 	model2 "github.com/ZR233/session/model"
-	"strconv"
 	"time"
 )
 
 type Session struct {
 	Token    string
-	UserId   int
+	UserId   string
 	Channel  string
 	ExpireAt time.Time
 }
 
 func NewSession(s *model2.Session) *Session {
-	userId, err := strconv.Atoi(s.UserId)
-	if err != nil {
-		panic(err)
-	}
+	//userId, err := strconv.Atoi(s.UserId)
+	//if err != nil {
+	//	panic(err)
+	//}
 	s_ := &Session{
 		s.Token,
-		userId,
+		s.UserId,
 		s.Channel,
 		s.ExpireAt,
 	}

+ 1 - 2
repository/http/loallout_server.go

@@ -8,14 +8,13 @@ import (
 	"net/url"
 	"strings"
 	"video_course/errors"
-	"video_course/global"
 )
 
 type LoalloutServer struct {
 }
 
 func (l LoalloutServer) CheckPhone(phone string) (userMd5 string) {
-	api := strings.Join([]string{global.Project.UserServer.Host, "v1/Auth/CheckPhone"}, "/")
+	api := strings.Join([]string{"http://192.168.0.3:19095", "v1/Auth/CheckPhone"}, "/")
 
 	resp, err := http.PostForm(api, url.Values{
 		"phone": {phone},

+ 31 - 19
service/auth.go

@@ -2,15 +2,14 @@ package service
 
 import (
 	"fmt"
-	"strconv"
+	"github.com/mojocn/base64Captcha"
 	"time"
 	"video_course/errors"
 	"video_course/global"
 	"video_course/lib/session"
 	"video_course/model"
+	h "video_course/repository/http"
 	rdb "video_course/repository/redis"
-
-	"github.com/mojocn/base64Captcha"
 )
 
 var store = base64Captcha.DefaultMemStore
@@ -83,16 +82,16 @@ func (a Auth) GenVFCode(codeTypeInt int, phone string, ip string,
 	picId string,
 	picCode string) (err error) {
 	//图形验证码验证
-	if !store.Verify(picId, picCode, true) {
-		return errors.ErrPicVerifyCode
-	}
+	//if !store.Verify(picId, picCode, true) {
+	//	return errors.ErrPicVerifyCode
+	//}
 	//生成短信验证码
-	smsCode := "123456"
+	smsCode := "12345678"
 	//发送短信
 	fmt.Println(smsCode)
 	//存储短信验证码
 	redisdb := rdb.GetRedis()
-	redisdb.Set(global.AppName+":"+"smsCode:"+phone, []byte(smsCode), 3*time.Minute)
+	redisdb.Set(global.ProjectName+":"+global.AppName+":"+"smsCode:"+phone, []byte(smsCode), 3*time.Minute)
 
 	return
 	//dao := a.getUserDao()
@@ -126,18 +125,31 @@ func (a Auth) GenVFCode(codeTypeInt int, phone string, ip string,
 
 func (a Auth) PhoneSignIn(phone string, smsCode string, ip string) (
 	s *model.Session, err error) {
+	//验证短信手机号和验证码
+	redisdb := rdb.GetRedis()
+	tmpCode, err_ := redisdb.Get(global.ProjectName + ":" + global.AppName + ":" + "smsCode:" + phone).Result()
+	if err_ != nil {
+		err = err_
+		return
+	}
+	if tmpCode != smsCode {
+		err = errors.NewServiceErr(errors.CodePermissionDenied, "手机验证码不正确")
+		return
+	}
+
+	//获取usermd5
+	userMd5 := h.LoalloutServer{}.CheckPhone(phone)
+	//创建session
 	sm := session.GetSessionManager()
-	s_, err := sm.CreateSession(strconv.Itoa(userId), src, time.Now().Add(time.Hour*24*5))
-	s = model.NewSession(s_)
-	//sess = NewSession
-	//
-	//gorm.VFCodeDAO{}.CheckVFCode(model.VFCodeCodeTypeLogin, phone, code)
-	//
-	//user := gorm.UserDAO{}.GetUserByPhone(phone)
-	//user.CheckStatus()
-	//
-	//sess = function.Auth{}.WxLoginUser(user, channel, "", ip, phone, user.Phone)
-	//logInfo = fmt.Sprintf("用户[%s]通过手机验证码登录", user.Name)
+
+	sess2, err_ := sm.CreateSession(userMd5, "src", time.Now().Add(time.Hour*24*5))
+	if err_ != nil {
+		err = err_
+		return
+	}
+
+	s = model.NewSession(sess2)
+
 	return
 }