Example #1
0
func (c User) SignupPost(user models.User) revel.Result {
	user.Validate(c.Validation)
	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.User.Signup())
	}

	salt := uuidName()
	user.Type = MEMBER_GROUP
	user.Avatar = models.DefaultAvatar
	user.ValidateCode = uuidName()
	user.Salt = salt
	user.HashedPassword = models.EncryptPassword(user.Password, salt)

	aff, _ := engine.Insert(&user)
	if aff == 0 {
		c.Flash.Error("注册用户失败")
		return c.Redirect(routes.User.Signup())
	}

	subject := "激活账号 —— Revel中文社区"
	content := `<h2><a href="http://gorevel.cn/user/validate/` + user.ValidateCode + `">激活账号</a></h2>`
	go sendMail(subject, content, []string{user.Email})

	c.Flash.Success(fmt.Sprintf("%s 注册成功,请到您的邮箱 %s 激活账号!", user.Name, user.Email))

	engine.Insert(&models.Permissions{
		UserId: user.Id,
		Perm:   MEMBER_GROUP,
	})

	return c.Redirect(routes.User.Signin())
}
Example #2
0
func (c User) ForgotPasswordPost(email string) revel.Result {
	c.Validation.Required(email).Message("请填写Email")
	c.Validation.Email(email).Message("Email格式不正确")
	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.User.ForgotPassword())
	}

	var user models.User
	has, _ := engine.Where("email = ?", email).Get(&user)
	if !has {
		return c.NotFound("用户不存在")
	}

	user.ValidateCode = uuidName()
	engine.Where("email = ?", email).Cols("validate_code").Update(&user)

	subject := "重设密码 —— Revel社区"
	content := `<h2><a href="http://gorevel.cn/reset_password/` + user.ValidateCode + `">重设密码</a></h2>`

	go sendMail(subject, content, []string{user.Email})

	c.Flash.Success(fmt.Sprintf("你好,重设密码的链接已经发送到您的邮箱,请到您的邮箱 %s 重设密码!", user.Email))

	return c.Redirect(routes.User.Signin())
}
Example #3
0
func (c User) Validate(code string) revel.Result {
	var user models.User
	has, _ := engine.Where("validate_code = ?", code).Get(&user)
	if !has {
		return c.NotFound("用户不存在或校验码错误")
	}

	user.Status = models.USER_STATUS_ACTIVATED
	user.ValidateCode = ""
	aff, _ := engine.Cols("status", "validate_code").Update(&user)
	if aff > 0 {
		c.Flash.Success("您的账号成功激活,请登录!")
	} else {
		c.Flash.Error("抱歉,您的账号未能激活,请与管理员联系!")
	}

	return c.Redirect(routes.User.Signin())
}