Example #1
0
func (this Controller) Login(w http.ResponseWriter, r *http.Request) {
	sess, _ := globalSessions.SessionStart(w, r)
	defer sess.SessionRelease(w)
	r.ParseForm()

	if r.Method == "GET" {
		unitl.ReadHtml(w, "admin/login", nil)
	} else {
		//数据库查询
		m := db.NewModel("admin")

		s, err := m.Where("accounts").Find(r.FormValue("accounts"))
		if err != nil {
			errinfo := make(map[string]interface{})
			errinfo["title"] = "账号或者密码错误"
			errinfo["info"] = "账号或者密码错误"
			unitl.ReadHtml(w, "err", errinfo)
			return
		}
		if unitl.GetMD5Hash(r.FormValue("pwd")) != s["pwd"] {
			errinfo := make(map[string]interface{})
			errinfo["title"] = "账号或者密码错误"
			errinfo["info"] = "账号或者密码错误"
			unitl.ReadHtml(w, "err", errinfo)
			return
		}
		//将信息写入session作为认证凭据
		sess.Set("adminName", s["name"])
		sess.Set("adminId", s["accounts"])
		http.Redirect(w, r, "/admin/index", http.StatusFound)
	}

}
Example #2
0
//Login 处理用户登录
func (c *Controller) Login(w http.ResponseWriter, r *http.Request) {

	sess, _ := globalSessions.SessionStart(w, r)
	defer sess.SessionRelease(w)

	//验证学号与学校(如果信息正确,将信息写入session中)
	if r.Method == "POST" {
		stud := db.NewModel("students")
		defer stud.Close()
		student, err := stud.Where("num").Find(unitl.Trim(r,"num"))
        if err != nil {
			errInfo := make(map[string]interface{})
			errInfo["title"] = "账号密码错误"
			errInfo["info"] = "账号或密码错误"
			unitl.ReadHtml(w, "err", errInfo)
		}
        
        sch := db.NewModel("school")
        school,_ := sch.Where("id").Find(unitl.Trim(r,"school"))		
        
		if unitl.GetMD5Hash(unitl.Trim(r,"pwd")) != student["pwd"] && school["id"] != student["school_id"] {
            unitl.ReadHtml(w, "accounterr", nil)
		}
		//将信息写入session作为认证凭据
		sess.Set("studentName", student["name"])
		sess.Set("studentId", student["num"])
		http.Redirect(w, r, "/post", http.StatusFound)
	} else {
		unitl.ReadHtml(w, "404", nil)
	}
}