Example #1
0
func CheckLogin(ctx *context.Context) {
	if ctx.Request.RequestURI != "/login" {
		sess, err := models.GlobalSessions.SessionStart(ctx.ResponseWriter, ctx.Request)
		if err != nil || sess == nil {
			ctx.Abort(401, "session nil")
		}
		sessioner := sess.Get("gosessionkey")
		beego.Debug("session:", sess)
		beego.Debug("check login gosessionkey:", sessioner)
		if fmt.Sprintf("%v", sessioner) != "beego1234" {
			ctx.Redirect(401, "/login")
		}
	}
}