Beispiel #1
0
func createPasswordResetLink(userName string) (string, error) {
	user, err := models.FindUserByName(userName)
	if err != nil {
		return "", err
	}
	secret := createPasswordSecret(user)
	secretLink := fmt.Sprint(MasterAddress, "/update_password/", user.Id, "/", url.QueryEscape(secret))
	return secretLink, nil
}
Beispiel #2
0
func (c PublicApplication) ResetPassword() revel.Result {

	var userName string
	var email string

	c.Params.Bind(&userName, "userName")
	c.Params.Bind(&email, "email")

	user, err := models.FindUserByName(userName)
	if err != nil {
		c.Flash.Error("Cannot find user.")
		return c.Redirect(routes.PublicApplication.Index())
	}

	if user.Email != email {
		c.Flash.Error("User's email did not match.")
		return c.Redirect(routes.PublicApplication.Index())
	}

	resetLink, err := createPasswordResetLink(userName)
	if err != nil {
		c.Flash.Error("Cannot generate reset link:  ", err)
		return c.Redirect(routes.PublicApplication.Index())
	}

	t := template.Must(template.New("resetPasswordTemplate").Parse(resetPasswordTemplate))

	type ResetPasswordTemplateParams struct {
		ResetLink string
	}

	params := ResetPasswordTemplateParams{
		ResetLink: resetLink,
	}

	var buf bytes.Buffer

	if err := t.Execute(&buf, params); err != nil {
		revel.TRACE.Println(err)
		c.Flash.Error("Cannot generate email template.")
		return c.Redirect(routes.PublicApplication.Index())
	}

	if err := SendEmail(ApplicationEmail, email, "Password Reset Request", string(buf.Bytes())); err != nil {
		c.Flash.Error("Cannot send email")
		return c.Redirect(routes.PublicApplication.Index())
	}

	c.Flash.Success("An email has been sent with the password reset link.")
	return c.Redirect(routes.PublicApplication.Index())
}
Beispiel #3
0
func (c PublicApplication) getUser(userName string) models.User {
	if user, err := models.FindUserByName(userName); err == nil {
		return user
	}
	return models.User{}
}