This commit is contained in:
@@ -2,15 +2,22 @@ package middleware
|
||||
|
||||
import (
|
||||
"drive-linked/pkg/common"
|
||||
"drive-linked/pkg/dto"
|
||||
"github.com/kataras/iris/v12"
|
||||
)
|
||||
|
||||
func SignRequired(ctx iris.Context) {
|
||||
auth := ctx.GetHeader("Authorization")
|
||||
//TODO:更详细的判断,包括请求格式是否正确
|
||||
|
||||
// 验证token
|
||||
err := common.ValidateLogin(auth)
|
||||
if err == nil {
|
||||
ctx.Values().Set("logged_in", true)
|
||||
ctx.Next()
|
||||
} else {
|
||||
ctx.Values().Set("logged_in", false)
|
||||
resp := dto.NewResponse(ctx)
|
||||
resp.ErrUnauthorized()
|
||||
}
|
||||
ctx.Next()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user