Use entity update method rather than query. Fixed password reset form action.

This commit is contained in:
mikestefanello 2022-01-09 21:30:09 -05:00
parent 10c0a23c0a
commit 09c6df7f52
4 changed files with 7 additions and 8 deletions

View File

@ -118,7 +118,7 @@ Go server-side rendered HTML combined with the projects below enable you to crea
### Screenshots
#### Inline validation
#### Inline form validation
<img src="https://user-images.githubusercontent.com/552328/147838632-570a3116-1e74-428f-8bfc-523ed309ef06.png" alt="Inline validation"/>
@ -761,6 +761,7 @@ Many examples of its usage are available in the included examples:
- All navigation links use [boost](https://htmx.org/docs/#boosting) which dynamically replaces the page content with an AJAX request, providing a SPA-like experience.
- All forms use either [boost](https://htmx.org/docs/#boosting) or [hx-post](https://htmx.org/docs/#triggers) to submit via AJAX.
- The mock search autocomplete modal uses [hx-get](https://htmx.org/docs/#targets) to fetch search results from the server via AJAX and update the UI.
- The mock posts on the homepage/dashboard use [hx-get](https://htmx.org/docs/#targets) to fetch and page posts vi AJAX.
All of this can be easily accomplished without writing any JavaScript at all.
@ -947,6 +948,7 @@ Thank you to all of the following amazing projects for making this possible.
- [bulma](https://github.com/jgthms/bulma)
- [docker](https://www.docker.com/)
- [echo](https://github.com/labstack/echo)
- [echo-contrib](https://github.com/labstack/echo-contrib)
- [ent](https://github.com/ent/ent)
- [envdecode](https://github.com/joeshaw/envdecode)
- [go](https://go.dev/)

View File

@ -4,7 +4,6 @@ import (
"github.com/mikestefanello/pagoda/context"
"github.com/mikestefanello/pagoda/controller"
"github.com/mikestefanello/pagoda/ent"
"github.com/mikestefanello/pagoda/ent/user"
"github.com/mikestefanello/pagoda/msg"
"github.com/labstack/echo/v4"
@ -63,10 +62,9 @@ func (c *ResetPassword) Post(ctx echo.Context) error {
usr := ctx.Get(context.UserKey).(*ent.User)
// Update the user
_, err = c.Container.ORM.User.
_, err = usr.
Update().
SetPassword(hash).
Where(user.ID(usr.ID)).
Save(ctx.Request().Context())
if err != nil {

View File

@ -47,11 +47,10 @@ func (c *VerifyEmail) Get(ctx echo.Context) error {
// Verify the user, if needed
if !usr.Verified {
err = c.Container.ORM.User.
usr, err = usr.
Update().
SetVerified(true).
Where(user.ID(usr.ID)).
Exec(ctx.Request().Context())
Save(ctx.Request().Context())
if err != nil {
return c.Fail(ctx, err, "failed to set user as verified")

View File

@ -1,5 +1,5 @@
{{define "content"}}
<form method="post" hx-boost="true" action="{{call .ToURL "forgot_password.post"}}">
<form method="post" hx-boost="true" action="{{.Path}}">
<div class="field">
<label for="password" class="label">Password</label>
<div class="control">