newsbox/actions/user_verification.go

33 lines
722 B
Go
Raw Normal View History

2023-02-15 16:56:06 +00:00
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, "/")
}