refactor: add jwt auth middleware to files controller
This commit is contained in:
parent
34be432af7
commit
e98e2d0c89
|
@ -5,6 +5,7 @@ import (
|
||||||
"git.lumeweb.com/LumeWeb/portal/cid"
|
"git.lumeweb.com/LumeWeb/portal/cid"
|
||||||
"git.lumeweb.com/LumeWeb/portal/controller/response"
|
"git.lumeweb.com/LumeWeb/portal/controller/response"
|
||||||
"git.lumeweb.com/LumeWeb/portal/logger"
|
"git.lumeweb.com/LumeWeb/portal/logger"
|
||||||
|
"git.lumeweb.com/LumeWeb/portal/middleware"
|
||||||
"git.lumeweb.com/LumeWeb/portal/service/files"
|
"git.lumeweb.com/LumeWeb/portal/service/files"
|
||||||
"github.com/kataras/iris/v12"
|
"github.com/kataras/iris/v12"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
@ -15,6 +16,10 @@ type FilesController struct {
|
||||||
Controller
|
Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *FilesController) BeginRequest(ctx iris.Context) {
|
||||||
|
ctx.AddHandler(middleware.VerifyJwt)
|
||||||
|
}
|
||||||
|
|
||||||
func (f *FilesController) PostUpload() {
|
func (f *FilesController) PostUpload() {
|
||||||
ctx := f.Ctx
|
ctx := f.Ctx
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
package middleware
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.lumeweb.com/LumeWeb/portal/service/auth"
|
||||||
|
"github.com/kataras/iris/v12"
|
||||||
|
)
|
||||||
|
|
||||||
|
func VerifyJwt(ctx iris.Context) {
|
||||||
|
token := auth.GetRequestAuthCode(ctx)
|
||||||
|
|
||||||
|
if len(token) == 0 {
|
||||||
|
ctx.StopWithError(iris.StatusUnauthorized, auth.ErrInvalidToken)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := auth.VerifyLoginToken(token); err != nil {
|
||||||
|
ctx.StopWithError(iris.StatusUnauthorized, auth.ErrInvalidToken)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.Next()
|
||||||
|
}
|
Loading…
Reference in New Issue