Exemple #1
0
//注册
func LoginInfo(w http.ResponseWriter, r *http.Request) {
	data := make(map[string]interface{})
	user := new(models.User)
	t, err := template.ParseFiles("views/login_info.html", "views/common/head.tpl")
	if pageNotFound(w, err) {
		return
	}
	l, err := template.ParseFiles("views/login.html", "views/common/head.tpl")
	if pageNotFound(w, err) {
		return
	}
	if r.Method == "GET" {
		data["user"] = user
		data["error"] = ""
		t.Execute(w, data)
		return
	} else {
		user.Uname = r.PostFormValue("uname")
		user.Email = r.PostFormValue("email")
		user.Passwd = GetMd5String(r.PostFormValue("pwd"))
		user.Status = 1
		user.Subtime = time.Now()
		s := models.GetUserNameOrEmail(user.Uname, user.Email)
		if len(s) > 0 {
			data["error"] = s
			data["user"] = user
			t.Execute(w, data)
			return
		}
		err = models.InsertUser(user)
		if CheckError("数据库连接失败:", err) {
			data["user"] = user
			data["error"] = "网站连接失败,请稍后重试"
			t.Execute(w, data)
			return
		}
		data["success"] = "注册成功,请登录"
		l.Execute(w, data)
		return
	}

}
Exemple #2
0
//发送邮件,找回密码
func LoginForget(w http.ResponseWriter, r *http.Request) {
	data := make(map[string]interface{})
	user := new(models.User)
	t, err := template.ParseFiles("views/login_forget.html", "views/common/head.tpl")
	if pageNotFound(w, err) {
		return
	}
	l, err := template.ParseFiles("views/login.html", "views/common/head.tpl")
	if pageNotFound(w, err) {
		return
	}
	if r.Method == "GET" {
		data["user"] = user
		data["error"] = ""
		t.Execute(w, data)
		return
	} else {
		user.Uname = r.PostFormValue("uname")
		user.Email = r.PostFormValue("email")
		s := models.GetUserNameAndEmail(user.Uname, user.Email)
		if len(s) > 0 {
			data["error"] = s
			data["user"] = user
			t.Execute(w, data)
			return
		}

		//发送邮件
		err = SendToMail(user.Email, user.Uname)
		if CheckError("邮件发送失败:", err) {
			data["error"] = "邮件发送失败,稍后再试"
			data["user"] = user
			t.Execute(w, data)
			return
		}
		data["success"] = "请登录邮箱,修改密码"
		l.Execute(w, data)
		return
	}
}