Beispiel #1
0
func ac_user(w http.ResponseWriter, r *http.Request) {
	if r.Method == "POST" {
		email := r.FormValue("email")
		user := r.FormValue("user")
		pwd := r.FormValue("pwd")
		if !forms.Reg_email(email) {
			ExitMsg(w, "邮箱格式错误")
			return
		}

		if !forms.Reg_user(user) {
			ExitMsg(w, "用户名格式错误")
			return
		}
		if pwd == "" {
			ExitMsg(w, "密码不可为空")
			return
		}
		pwd = forms.Tomd5(pwd)

		if !captcha.VerifyString(r.FormValue("captchaId"), r.FormValue("captchaSolution")) {
			ExitMsg(w, "验证码错误")
			return
		}
		if User_ishaveEmail(email) {
			ExitMsg(w, "Email 已存在")
			return
		}
		if User_ishaveName(user) {
			ExitMsg(w, "用户名 已存在")
			return
		}
		C := Db.C("go_user")
		id := bson.NewObjectId()
		err := C.Insert(&User{Id_: id, Username: user, Pwd: pwd, Email: email, Adminid: 0,
			Regip: forms.Ip(r), Lastip: forms.Ip(r), Lasttime: time.Now()})
		CheckErr(err)
		fmt.Fprint(w, "添加成功")
		return
	}

	t, err := template.ParseFiles("template/user/index.html")
	CheckErr(err)
	t.Execute(w, struct{ CaptchaId string }{captcha.New()})
}
Beispiel #2
0
func Login_info(id bson.ObjectId, r *http.Request) {
	err := Db.C("go_user").Update(bson.M{"_id": id}, bson.M{"$set": bson.M{"lastip": forms.Ip(r),
		"lasttime": time.Now()}})
	CheckErr(err)
}