Esempio n. 1
0
File: main.go Progetto: jinzhe/GOSNS
func showFormHandler(w http.ResponseWriter, r *http.Request) {
	if r.URL.Path != "/" {
		http.NotFound(w, r)
		return
	}
	d := struct {
		CaptchaId string
	}{
		captcha.New(),
	}
	if err := formTemplate.Execute(w, &d); err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}
}
Esempio n. 2
0
File: user.go Progetto: jinzhe/GOSNS
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()})
}