|
@@ -4,26 +4,26 @@ import (
|
|
|
"cmf/conf"
|
|
|
"cmf/db"
|
|
|
"cmf/db/repo"
|
|
|
+ "cmf/middleware"
|
|
|
"context"
|
|
|
"fmt"
|
|
|
|
|
|
+ "github.com/casdoor/casdoor-go-sdk/casdoorsdk"
|
|
|
"github.com/gin-contrib/cors"
|
|
|
- "github.com/gin-contrib/sessions"
|
|
|
- "github.com/gin-contrib/sessions/cookie"
|
|
|
"github.com/gin-gonic/gin"
|
|
|
"github.com/go-redis/redis/v8"
|
|
|
)
|
|
|
|
|
|
type Service struct {
|
|
|
- Gin *gin.Engine
|
|
|
- Mongo *db.MongoDB
|
|
|
- Redis *redis.Client
|
|
|
- Port int32
|
|
|
- DebugUserId string
|
|
|
- DebugUserPhone string
|
|
|
- DebugUserRole string
|
|
|
- JWT *UtilsJwt
|
|
|
- Conf *conf.AppConf
|
|
|
+ Gin *gin.Engine
|
|
|
+ Mongo *db.MongoDB
|
|
|
+ Redis *redis.Client
|
|
|
+ Port int32
|
|
|
+ // DebugUserId string
|
|
|
+ // DebugUserPhone string
|
|
|
+ // DebugUserRole string
|
|
|
+ // JWT *UtilsJwt
|
|
|
+ Conf *conf.AppConf
|
|
|
}
|
|
|
|
|
|
func (svc *Service) Run() {
|
|
@@ -31,8 +31,9 @@ func (svc *Service) Run() {
|
|
|
}
|
|
|
|
|
|
type ApiSession struct {
|
|
|
- Svc *Service
|
|
|
- User *JWTUser
|
|
|
+ Svc *Service
|
|
|
+ // User *JWTUser
|
|
|
+ User *casdoorsdk.User
|
|
|
}
|
|
|
|
|
|
func (api *ApiSession) CreateRepoCtx() *repo.RepoSession {
|
|
@@ -46,18 +47,16 @@ func NewHttpService(app *conf.AppConf, dbMongo *db.MongoDB) *Service {
|
|
|
|
|
|
engine := gin.Default()
|
|
|
|
|
|
- store := cookie.NewStore([]byte("spu3d-server"))
|
|
|
- engine.Use(sessions.Sessions("dcsession", store))
|
|
|
- engine.Static("/public", "static")
|
|
|
+ // store := cookie.NewStore([]byte("spu3d-server"))
|
|
|
+ // engine.Use(sessions.Sessions("dcsession", store))
|
|
|
+ // engine.Static("/public", "static")
|
|
|
config := cors.DefaultConfig()
|
|
|
// config.AllowOrigins == []string{"http://google.com", "http://facebook.com"}
|
|
|
config.AllowAllOrigins = true
|
|
|
config.AllowHeaders = append(config.AllowHeaders, "authorization")
|
|
|
engine.Use(cors.New(config))
|
|
|
|
|
|
- jwt := NewUitlsJwt(app)
|
|
|
-
|
|
|
- s := &Service{Conf: app, JWT: jwt, Gin: engine, Mongo: dbMongo, Port: app.Port, DebugUserId: app.Debug.UserId, DebugUserPhone: app.Debug.UserPhone, DebugUserRole: app.Debug.UserRole}
|
|
|
+ s := &Service{Conf: app, Gin: engine, Mongo: dbMongo, Port: app.Port}
|
|
|
|
|
|
RegRouters(s)
|
|
|
|
|
@@ -92,39 +91,15 @@ func (g GinRouter) POST(path string, httpHandler Handler) {
|
|
|
|
|
|
// GETJWT http Get 请求
|
|
|
func (g GinRouter) GETJWT(path string, httpHandler JWTHander) {
|
|
|
- g.group.GET(path, g.svc.JWT.MiddleFunc(), ResultJWTWrapper(httpHandler, g.svc))
|
|
|
-}
|
|
|
-
|
|
|
-// GETJWTTest http Get 请求
|
|
|
-func (g GinRouter) GETJWTTest(path string, httpHandler JWTHander) {
|
|
|
- g.group.GET(path, ResultJWTTestWrapper(httpHandler, g.svc))
|
|
|
+ g.group.GET(path, middleware.CasdoorAuthMiddleware(), ResultJWTWrapper(httpHandler, g.svc))
|
|
|
}
|
|
|
|
|
|
// POSTJWT http POST 请求
|
|
|
func (g GinRouter) POSTJWT(path string, httpHandler JWTHander) {
|
|
|
- g.group.POST(path, g.svc.JWT.MiddleFunc(), ResultJWTWrapper(httpHandler, g.svc))
|
|
|
+ g.group.POST(path, middleware.CasdoorAuthMiddleware(), ResultJWTWrapper(httpHandler, g.svc))
|
|
|
}
|
|
|
|
|
|
// DeleteJWT http POST 请求
|
|
|
func (g GinRouter) DeleteJWT(path string, httpHandler JWTHander) {
|
|
|
- g.group.DELETE(path, g.svc.JWT.MiddleFunc(), ResultJWTWrapper(httpHandler, g.svc))
|
|
|
-}
|
|
|
-
|
|
|
-// DeleteJWT http POST 请求
|
|
|
-func (g GinRouter) DeleteJWTTEST(path string, httpHandler JWTHander) {
|
|
|
- g.group.DELETE(path, ResultJWTTestWrapper(httpHandler, g.svc))
|
|
|
-}
|
|
|
-
|
|
|
-// POSTJWTTest 测试
|
|
|
-func (g GinRouter) POSTJWTTest(path string, httpHandler JWTHander) {
|
|
|
- g.group.POST(path, ResultJWTTestWrapper(httpHandler, g.svc))
|
|
|
-}
|
|
|
-
|
|
|
-// 代参数判断权限
|
|
|
-func (g GinRouter) GETJWTKEY(path string, httpHandler JWTHander, keys ...string) {
|
|
|
- g.group.GET(path, g.svc.JWT.MiddleFunc(), ResultJWTWrapperKey(httpHandler, g.svc, keys))
|
|
|
-}
|
|
|
-
|
|
|
-func (g GinRouter) POSTJWTKEY(path string, httpHandler JWTHander, keys ...string) {
|
|
|
- g.group.POST(path, g.svc.JWT.MiddleFunc(), ResultJWTWrapperKey(httpHandler, g.svc, keys))
|
|
|
+ g.group.DELETE(path, middleware.CasdoorAuthMiddleware(), ResultJWTWrapper(httpHandler, g.svc))
|
|
|
}
|