예제 #1
0
파일: user.go 프로젝트: lvzhongyi/canku
/**
 * 注册逻辑处理
 * @param  {[type]} this *UserController) Join( [description]
 * @return {[type]}      [description]
 */
func (this *UserController) Join() {
	beego.AutoRender = false
	errmsg := make(map[string]string)
	requestEmail := this.GetString("email")
	requestNickname := this.GetString("nickname")
	requestPassword := this.GetString("password")

	jvalid := validation.Validation{}

	jvalid.Required(requestEmail, "email")
	jvalid.MaxSize(requestEmail, 40, "email")
	jvalid.Required(requestNickname, "nickname")
	jvalid.MaxSize(requestNickname, 20, "nickname")
	jvalid.Required(requestPassword, "password")

	fmt.Println(jvalid.HasErrors())

	if jvalid.HasErrors() {
		for _, err := range jvalid.Errors {
			//fmt.Println(err.Key, err.Message)
			this.showmsg("Error Message", "["+err.Key+"]"+err.Message)
		}
	}

	if len(errmsg) == 0 {
		var user models.User
		user.Email = requestEmail
		user.Nickname = requestNickname
		user.Password = models.Md5([]byte(requestPassword))
		user.Lastlogin = time.Now().Unix()
		if err := user.Insert(); err != nil {
			this.Ctx.WriteString(err.Error())
		}
	}
	this.SetSession("nickname", requestNickname)
	this.SetSession("email", requestEmail)
	this.SetSession("isadmin", 0)
	this.Redirect("/", 302)
}
예제 #2
0
파일: user.go 프로젝트: lvzhongyi/canku
func (this *UserController) CreatePost() {
	u := m.User{}
	if err := this.ParseForm(&u); err != nil {
		//handle error
		this.Rsp(int64(201), err.Error())
		return
	}
	fmt.Printf("u: %s \n", u)
	//密码与重置登录时间
	//u.Password = m.Md5([]byte(u.Password))
	//u.Lastlogin = time.Now().Unix()

	err := u.Insert()
	if err == nil {
		this.Rsp(int64(200), "Success")
		//this.Redirect(this.UrlFor("admin/UserController.Index"), 302)
		//this.Redirect()
		return
	} else {
		this.Rsp(int64(201), err.Error())
		return
	}
}