예제 #1
0
파일: index.go 프로젝트: hogenwang/comcms
//判断是否登陆
func CheckAdminLogin(c *beego.Controller, t int64) {
	id, _ := c.GetSession("adminid").(int)
	username, _ := c.GetSession("adminname").(string)
	adminrole, _ := c.GetSession("adminrole").(int)
	if id == 0 || username == "" || adminrole == 0 {
		switch t {
		case 0:
			c.Redirect("/admin/login", 301)
		case 1:
			//返回JSON
			json := &models.TipJSON{}
			json.Status = models.TipError
			json.Message = "请先登录,再执行此操作"
			json.ReturnUrl = "/admin/login"

			c.Data["json"] = json
			c.ServeJson()
			c.StopRun()
		}

	}
	c.Data["AdminName"] = username
	c.Data["AdminId"] = id
	c.Layout = "admin/layout.tpl"
}