dongfeng-pay/boss/controllers/baseController.go

31 lines
664 B
Go
Raw Normal View History

2021-04-27 15:33:49 +08:00
package controllers
2021-11-11 10:30:43 +08:00
import (
"boss/datas"
beego "github.com/beego/beego/v2/server/web"
)
2021-04-27 15:33:49 +08:00
type BaseController struct {
beego.Controller
}
func (c *BaseController) GenerateJSON(dataJSON interface{}) {
c.Data["json"] = dataJSON
2021-11-11 10:30:43 +08:00
_ = c.ServeJSON()
2021-04-27 15:33:49 +08:00
}
func (c *BaseController) Prepare() {
userID, ok := c.GetSession("userID").(string)
if !ok || userID == "" {
//用户没有登录,或者登录到期了,则跳转登录主页面
2021-11-11 10:30:43 +08:00
dataJSON := new(datas.BaseDataJSON)
2021-04-27 15:33:49 +08:00
dataJSON.Code = 404
dataJSON.Msg = "登录已经过期!"
c.Data["json"] = dataJSON
2021-11-11 10:30:43 +08:00
_ = c.ServeJSON()
2021-04-27 15:33:49 +08:00
} else {
//重新赋值给session
2021-11-11 10:30:43 +08:00
_ = c.SetSession("userID", userID)
2021-04-27 15:33:49 +08:00
}
2021-11-11 10:30:43 +08:00
}