Esempio n. 1
0
//修改密码
func LoginChangePasswd(w http.ResponseWriter, r *http.Request) {
	data := make(map[string]interface{})
	user := new(models.User)
	t, err := template.ParseFiles("views/login_passwd_change.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" {
		emailCode := r.FormValue("emailCode")
		user.Email_change = emailCode
		has, _, _ := models.SelectUser(user)
		if has {
			data["emailCode"] = emailCode
			data["user"] = user
			data["error"] = ""
			t.Execute(w, data)
			return
		} else {
			data["error"] = "密码修改失败,请重试"
			l.Execute(w, data)
			return
		}

	} else {
		pwd := r.PostFormValue("pwd")
		user.Email_change = r.PostFormValue("emailCode")
		has, userInfo, _ := models.SelectUser(user)
		if has {
			id := userInfo.Id
			user = new(models.User)
			user.Passwd = GetMd5String(pwd)
			user.Email_change = GetMd5String(userInfo.Uname + userInfo.Email + userInfo.Passwd)
			err := models.UpdateUser(id, user)
			if CheckError("密码修改失败", err) {
				data["error"] = "密码修改失败,请重试"
				l.Execute(w, data)
				return
			} else {
				data["success"] = "密码修改成功,请登录"
				l.Execute(w, data)
				return
			}
		} else {
			data["error"] = "密码修改失败,请重试"
			l.Execute(w, data)
			return
		}
	}
}
Esempio n. 2
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
	}

}