newsbox/actions/user_verification.go
Adriano Caloiaro 8ae801ae5f
Initial commit
2023-02-15 08:57:48 -08:00

32 lines
722 B
Go

package actions
import (
"fmt"
"net/http"
"newsbox/internal"
"newsbox/models"
"github.com/gobuffalo/buffalo"
"github.com/gobuffalo/pop/v6"
"github.com/pkg/errors"
)
// UserEmailVerificatioHandler
func UserEmailVerificationHandler(c buffalo.Context) error {
tx := c.Value("tx").(*pop.Connection)
q := tx.Where("id = ?", c.Param("email_verification_id"))
uev := &models.UserEmailVerification{}
if err := q.EagerPreload().First(uev); err != nil {
return errors.WithStack(err)
}
tx.Destroy(uev)
c.Session().Set("current_user_id", uev.OwnerID)
c.Flash().Add("success", fmt.Sprintf("Welcome to %s!", internal.SiteName()))
// and redirect to the show page
return c.Redirect(http.StatusSeeOther, "/")
}