Beispiel #1
0
/**
 * 登录接收
 */
func (this *UserController) Signup() {
	//errmsg := make(map[string]string)
	requestEmail := this.GetString("email")
	requestPassword := this.GetString("password")

	svalid := validation.Validation{}

	svalid.Required(requestEmail, "email")
	svalid.MaxSize(requestEmail, 40, "email")
	svalid.Required(requestPassword, "password")

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

	var user models.User
	user.Email = requestEmail
	user.Password = models.Md5([]byte(requestPassword))

	var Ru models.ReturnUser
	Ru = user.Select()

	if Ru.Id > 0 {
		this.SetSession("nickname", Ru.Nickname)
		this.SetSession("email", Ru.Email)
		this.SetSession("isadmin", Ru.Isadmin)
		this.Redirect("/", 302)
	} else {
		this.showmsg("Error", "Email OR Password IS WRONG")
	}
}
Beispiel #2
0
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
	}
}
Beispiel #3
0
/**
 * 注册逻辑处理
 * @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)
}