登录与授权等
This commit is contained in:
@@ -11,7 +11,7 @@ func AdminRequired(c *gin.Context) {
|
||||
res := result.NewResult(c)
|
||||
authorization := c.GetHeader("Authorization")
|
||||
if authorization == "" {
|
||||
res.Unauthorized()
|
||||
res.UnLogin()
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -2,10 +2,37 @@ package middleware
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"mc-client-updater-server/pkg/log"
|
||||
"gorm.io/gorm"
|
||||
"mc-client-updater-server/internal/service"
|
||||
"mc-client-updater-server/pkg/result"
|
||||
)
|
||||
|
||||
func GrantRequired(c *gin.Context) {
|
||||
instName := c.Param("name")
|
||||
log.Logger.Info(instName)
|
||||
// 判断instance name是否存在
|
||||
srv := service.NewInstanceService(c)
|
||||
res := result.NewResult(c)
|
||||
instEntity, err := srv.GetInstanceByName(instName)
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
res.InvalidInstance(instName)
|
||||
return
|
||||
} else if err != nil {
|
||||
res.InternalServerError("查询实例对象时出现错误")
|
||||
return
|
||||
}
|
||||
c.Set("instance", instEntity)
|
||||
|
||||
// 判断grant_code是否合法
|
||||
grantCode := c.GetHeader("GrantCode")
|
||||
if grantCode == "" {
|
||||
res.Unauthorized()
|
||||
return
|
||||
}
|
||||
grantEntity, err := srv.GetGrantByToken(grantCode)
|
||||
if err != nil {
|
||||
res.Unauthorized()
|
||||
return
|
||||
}
|
||||
c.Set("grant", grantEntity)
|
||||
c.Next()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user