spring 3 年之前
父节点
当前提交
7573f1ea48
共有 3 个文件被更改,包括 27 次插入35 次删除
  1. 1 6
      main_test.go
  2. 24 23
      route/init.go
  3. 2 6
      service/login_auth.go

+ 1 - 6
main_test.go

@@ -7,15 +7,10 @@ import (
 	"youngee_b_api/config"
 	"youngee_b_api/config"
 	"youngee_b_api/model/http_model"
 	"youngee_b_api/model/http_model"
 	"youngee_b_api/service"
 	"youngee_b_api/service"
-	"youngee_b_api/util"
 )
 )
 
 
 func TestGormUser(t *testing.T) {
 func TestGormUser(t *testing.T) {
-	pa := "17695725591"
-	r := util.MD5(pa)
-	r2 := service.LoginAuth.TestEncryptPassword(pa)
-	fmt.Println(r)
-	fmt.Println(r2)
+	
 }
 }
 
 
 func TestDbCreateEnterprise(t *testing.T) {
 func TestDbCreateEnterprise(t *testing.T) {

+ 24 - 23
route/init.go

@@ -1,43 +1,44 @@
 package route
 package route
 
 
 import (
 import (
+	"github.com/gin-gonic/gin"
+	"github.com/sirupsen/logrus"
 	"youngee_b_api/handler"
 	"youngee_b_api/handler"
 	"youngee_b_api/middleware"
 	"youngee_b_api/middleware"
-	"youngee_b_api/model/http_model"
-
-	"github.com/gin-gonic/gin"
 )
 )
 
 
 func InitRoute(r *gin.Engine) {
 func InitRoute(r *gin.Engine) {
 
 
-	r.POST("/project/create", handler.WrapCreateProjectHandler)
-	r.POST("/enterprise/create", handler.WrapCreateEnterpriseHandler)
-	r.POST("/product/create", handler.WrapCreateProductHandler)
 	r.POST("/login", handler.WrapPasswordLoginHandler)
 	r.POST("/login", handler.WrapPasswordLoginHandler)
-	r.GET("/test/ping", func(c *gin.Context) {
-		resp := http_model.CommonResponse{
-			Status:  0,
-			Message: "",
-			Data:    "ping",
-		}
-		c.JSON(200, resp)
-	})
-	r.Any("/testDemo", func(c *gin.Context) {
-		resp := http_model.CommonResponse{
-			Status:  0,
-			Message: "",
-			Data:    "pong",
-		}
-		c.JSON(200, resp)
-		// 注意这里只是debug用的 接口要写成handler形式
-	})
+	//r.GET("/test/ping", func(c *gin.Context) {
+	//	resp := http_model.CommonResponse{
+	//		Status:  0,
+	//		Message: "",
+	//		Data:    "ping",
+	//	}
+	//	c.JSON(200, resp)
+	//})
+	//r.Any("/testDemo", func(c *gin.Context) {
+	//	resp := http_model.CommonResponse{
+	//		Status:  0,
+	//		Message: "",
+	//		Data:    "pong",
+	//	}
+	//	c.JSON(200, resp)
+	//	// 注意这里只是debug用的 接口要写成handler形式
+	//})
 	m := r.Group("/youngee/m")
 	m := r.Group("/youngee/m")
 	{
 	{
 		m.Use(middleware.LoginAuthMiddleware)
 		m.Use(middleware.LoginAuthMiddleware)
 		m.POST("/test", func(c *gin.Context) {
 		m.POST("/test", func(c *gin.Context) {
 			c.JSON(200, "ok")
 			c.JSON(200, "ok")
 			// 注意这里只是debug用的 接口要写成handler形式
 			// 注意这里只是debug用的 接口要写成handler形式
+			auth := middleware.GetSessionAuth(c)
+			logrus.Infof("auth:%+v", auth)
 		})
 		})
+		m.POST("/project/create", handler.WrapCreateProjectHandler)
+		m.POST("/enterprise/create", handler.WrapCreateEnterpriseHandler)
+		m.POST("/product/create", handler.WrapCreateProductHandler)
 	}
 	}
 
 
 }
 }

+ 2 - 6
service/login_auth.go

@@ -31,7 +31,7 @@ type loginAuth struct {
 }
 }
 
 
 func (l *loginAuth) AuthToken(ctx context.Context, token string) (*redis_model.Auth, error) {
 func (l *loginAuth) AuthToken(ctx context.Context, token string) (*redis_model.Auth, error) {
-	phone, err := l.ParseToken(ctx, token)
+	phone, err := l.parseToken(ctx, token)
 	if err != nil {
 	if err != nil {
 		logrus.Debug("token格式错误:%+v", token)
 		logrus.Debug("token格式错误:%+v", token)
 		return nil, err
 		return nil, err
@@ -104,7 +104,7 @@ func (l *loginAuth) getToken(ctx context.Context, phone string) string {
 	token := phone + "." + timeSeed + "." + util.MD5(phone, timeSeed, consts.AuthSalt)
 	token := phone + "." + timeSeed + "." + util.MD5(phone, timeSeed, consts.AuthSalt)
 	return token
 	return token
 }
 }
-func (l *loginAuth) ParseToken(ctx context.Context, token string) (string, error) {
+func (l *loginAuth) parseToken(ctx context.Context, token string) (string, error) {
 	parts := strings.Split(token, ".")
 	parts := strings.Split(token, ".")
 	if len(parts) == 3 {
 	if len(parts) == 3 {
 		phone := parts[0]
 		phone := parts[0]
@@ -118,10 +118,6 @@ func (l *loginAuth) ParseToken(ctx context.Context, token string) (string, error
 func (l *loginAuth) encryptPassword(password string) string {
 func (l *loginAuth) encryptPassword(password string) string {
 	return util.MD5(password)
 	return util.MD5(password)
 }
 }
-
 func (l *loginAuth) getRedisKey(key string) string {
 func (l *loginAuth) getRedisKey(key string) string {
 	return fmt.Sprintf("%s%s", consts.SessionRedisPrefix, key)
 	return fmt.Sprintf("%s%s", consts.SessionRedisPrefix, key)
 }
 }
-func (l *loginAuth) TestEncryptPassword(password string) string {
-	return l.encryptPassword(password)
-}