Improve router base.go

This commit is contained in:
Yang Luo 2021-09-05 14:44:27 +08:00
parent ef1195960e
commit 465d25a272
3 changed files with 19 additions and 21 deletions

View File

@ -37,8 +37,6 @@ func getUsername(ctx *context.Context) (username string) {
}
}()
// bug in Beego: this call will panic when file session store is empty
// so we catch the panic
username = ctx.Input.Session("username").(string)
if username == "" {

View File

@ -22,25 +22,6 @@ import (
"github.com/casbin/casdoor/util"
)
func getSessionUser(ctx *context.Context) string {
user := ctx.Input.CruSession.Get("username")
if user == nil {
return ""
}
return user.(string)
}
func setSessionUser(ctx *context.Context, user string) {
err := ctx.Input.CruSession.Set("username", user)
if err != nil {
panic(err)
}
// https://github.com/beego/beego/issues/3445#issuecomment-455411915
ctx.Input.CruSession.SessionRelease(ctx.ResponseWriter)
}
func AutoSigninFilter(ctx *context.Context) {
//if getSessionUser(ctx) != "" {
// return

View File

@ -62,3 +62,22 @@ func getUsernameByClientIdSecret(ctx *context.Context) string {
return fmt.Sprintf("app/%s", application.Name)
}
func getSessionUser(ctx *context.Context) string {
user := ctx.Input.CruSession.Get("username")
if user == nil {
return ""
}
return user.(string)
}
func setSessionUser(ctx *context.Context, user string) {
err := ctx.Input.CruSession.Set("username", user)
if err != nil {
panic(err)
}
// https://github.com/beego/beego/issues/3445#issuecomment-455411915
ctx.Input.CruSession.SessionRelease(ctx.ResponseWriter)
}