Finished password reset workflow. Remove all password tokens upon successful reset.

This commit is contained in:
mikestefanello 2021-12-16 21:27:52 -05:00
parent bd5bbab47c
commit ed9413ee17
8 changed files with 107 additions and 56 deletions

View file

@ -68,13 +68,12 @@ func (f *ForgotPassword) Post(c echo.Context) error {
Where(user.Email(form.Email)).
Only(c.Request().Context())
if err != nil {
switch err.(type) {
case *ent.NotFoundError:
return succeed()
default:
return fail("error querying user during forgot password", err)
}
switch err.(type) {
case *ent.NotFoundError:
return succeed()
case nil:
default:
return fail("error querying user during forgot password", err)
}
// Generate the token
@ -85,7 +84,8 @@ func (f *ForgotPassword) Post(c echo.Context) error {
c.Logger().Infof("generated password reset token for user %d", u.ID)
// Email the user
err = f.Container.Mail.Send(c, u.Email, fmt.Sprintf("Go here to reset your password: %s", token)) // TODO: route
// TODO: better email
err = f.Container.Mail.Send(c, u.Email, fmt.Sprintf("Go here to reset your password: %s", c.Echo().Reverse("reset_password", u.ID, token)))
if err != nil {
return fail("error sending password reset email", err)
}