dongfeng-pay/legend/filter/loginFilter.go

29 lines
593 B
Go
Raw Normal View History

2021-04-27 15:33:49 +08:00
package filter
import (
"github.com/beego/beego/v2/adapter/logs"
"github.com/beego/beego/v2/server/web/context"
"strings"
)
/**
** 对所有的用户请求进行登录判断如果未登录跳转到登录页面
** 但是对登录请求不进行过滤
*/
var LoginFilter = func(ctx *context.Context) {
_, ok := ctx.Input.Session("userName").(string)
if !ok {
2021-05-16 15:21:52 +08:00
if ctx.Request.RequestURI == "/login.html" {
return
}
2021-04-27 15:33:49 +08:00
if !strings.Contains(ctx.Request.RequestURI, "/login") {
ctx.Redirect(302, "/login.html")
} else {
2021-05-16 15:21:52 +08:00
logs.Error("该用户没有登录.......")
2021-04-27 15:33:49 +08:00
}
}
}