mirror of
https://github.com/casdoor/casdoor.git
synced 2025-09-07 19:50:33 +08:00
Improve router base.go
This commit is contained in:
@@ -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)
|
username = ctx.Input.Session("username").(string)
|
||||||
|
|
||||||
if username == "" {
|
if username == "" {
|
||||||
|
@@ -22,25 +22,6 @@ import (
|
|||||||
"github.com/casbin/casdoor/util"
|
"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) {
|
func AutoSigninFilter(ctx *context.Context) {
|
||||||
//if getSessionUser(ctx) != "" {
|
//if getSessionUser(ctx) != "" {
|
||||||
// return
|
// return
|
||||||
|
@@ -62,3 +62,22 @@ func getUsernameByClientIdSecret(ctx *context.Context) string {
|
|||||||
|
|
||||||
return fmt.Sprintf("app/%s", application.Name)
|
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)
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user