Let error handler handle all error logic, logging, and canceling.
This commit is contained in:
parent
31a3503021
commit
ecd0120920
10 changed files with 43 additions and 49 deletions
|
|
@ -41,11 +41,11 @@ func (c *contact) Post(ctx echo.Context) error {
|
|||
|
||||
// Parse the form values
|
||||
if err := ctx.Bind(&form); err != nil {
|
||||
return c.Fail(ctx, err, "unable to bind form")
|
||||
return c.Fail(err, "unable to bind form")
|
||||
}
|
||||
|
||||
if err := form.Submission.Process(ctx, form); err != nil {
|
||||
return c.Fail(ctx, err, "unable to process form submission")
|
||||
return c.Fail(err, "unable to process form submission")
|
||||
}
|
||||
|
||||
if !form.Submission.HasErrors() {
|
||||
|
|
@ -57,7 +57,7 @@ func (c *contact) Post(ctx echo.Context) error {
|
|||
Send(ctx)
|
||||
|
||||
if err != nil {
|
||||
return c.Fail(ctx, err, "unable to send email")
|
||||
return c.Fail(err, "unable to send email")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -50,11 +50,11 @@ func (c *forgotPassword) Post(ctx echo.Context) error {
|
|||
|
||||
// Parse the form values
|
||||
if err := ctx.Bind(&form); err != nil {
|
||||
return c.Fail(ctx, err, "unable to parse forgot password form")
|
||||
return c.Fail(err, "unable to parse forgot password form")
|
||||
}
|
||||
|
||||
if err := form.Submission.Process(ctx, form); err != nil {
|
||||
return c.Fail(ctx, err, "unable to process form submission")
|
||||
return c.Fail(err, "unable to process form submission")
|
||||
}
|
||||
|
||||
if form.Submission.HasErrors() {
|
||||
|
|
@ -72,13 +72,13 @@ func (c *forgotPassword) Post(ctx echo.Context) error {
|
|||
return succeed()
|
||||
case nil:
|
||||
default:
|
||||
return c.Fail(ctx, err, "error querying user during forgot password")
|
||||
return c.Fail(err, "error querying user during forgot password")
|
||||
}
|
||||
|
||||
// Generate the token
|
||||
token, pt, err := c.Container.Auth.GeneratePasswordResetToken(ctx, u.ID)
|
||||
if err != nil {
|
||||
return c.Fail(ctx, err, "error generating password reset token")
|
||||
return c.Fail(err, "error generating password reset token")
|
||||
}
|
||||
|
||||
ctx.Logger().Infof("generated password reset token for user %d", u.ID)
|
||||
|
|
@ -93,7 +93,7 @@ func (c *forgotPassword) Post(ctx echo.Context) error {
|
|||
Send(ctx)
|
||||
|
||||
if err != nil {
|
||||
return c.Fail(ctx, err, "error sending password reset email")
|
||||
return c.Fail(err, "error sending password reset email")
|
||||
}
|
||||
|
||||
return succeed()
|
||||
|
|
|
|||
|
|
@ -52,11 +52,11 @@ func (c *login) Post(ctx echo.Context) error {
|
|||
|
||||
// Parse the form values
|
||||
if err := ctx.Bind(&form); err != nil {
|
||||
return c.Fail(ctx, err, "unable to parse login form")
|
||||
return c.Fail(err, "unable to parse login form")
|
||||
}
|
||||
|
||||
if err := form.Submission.Process(ctx, form); err != nil {
|
||||
return c.Fail(ctx, err, "unable to process form submission")
|
||||
return c.Fail(err, "unable to process form submission")
|
||||
}
|
||||
|
||||
if form.Submission.HasErrors() {
|
||||
|
|
@ -74,7 +74,7 @@ func (c *login) Post(ctx echo.Context) error {
|
|||
return authFailed()
|
||||
case nil:
|
||||
default:
|
||||
return c.Fail(ctx, err, "error querying user during login")
|
||||
return c.Fail(err, "error querying user during login")
|
||||
}
|
||||
|
||||
// Check if the password is correct
|
||||
|
|
@ -86,7 +86,7 @@ func (c *login) Post(ctx echo.Context) error {
|
|||
// Log the user in
|
||||
err = c.Container.Auth.Login(ctx, u.ID)
|
||||
if err != nil {
|
||||
return c.Fail(ctx, err, "unable to log in user")
|
||||
return c.Fail(err, "unable to log in user")
|
||||
}
|
||||
|
||||
msg.Success(ctx, fmt.Sprintf("Welcome back, <strong>%s</strong>. You are now logged in.", u.Name))
|
||||
|
|
|
|||
|
|
@ -45,11 +45,11 @@ func (c *register) Post(ctx echo.Context) error {
|
|||
|
||||
// Parse the form values
|
||||
if err := ctx.Bind(&form); err != nil {
|
||||
return c.Fail(ctx, err, "unable to parse register form")
|
||||
return c.Fail(err, "unable to parse register form")
|
||||
}
|
||||
|
||||
if err := form.Submission.Process(ctx, form); err != nil {
|
||||
return c.Fail(ctx, err, "unable to process form submission")
|
||||
return c.Fail(err, "unable to process form submission")
|
||||
}
|
||||
|
||||
if form.Submission.HasErrors() {
|
||||
|
|
@ -59,7 +59,7 @@ func (c *register) Post(ctx echo.Context) error {
|
|||
// Hash the password
|
||||
pwHash, err := c.Container.Auth.HashPassword(form.Password)
|
||||
if err != nil {
|
||||
return c.Fail(ctx, err, "unable to hash password")
|
||||
return c.Fail(err, "unable to hash password")
|
||||
}
|
||||
|
||||
// Attempt creating the user
|
||||
|
|
@ -77,7 +77,7 @@ func (c *register) Post(ctx echo.Context) error {
|
|||
msg.Warning(ctx, "A user with this email address already exists. Please log in.")
|
||||
return c.Redirect(ctx, "login")
|
||||
default:
|
||||
return c.Fail(ctx, err, "unable to create user")
|
||||
return c.Fail(err, "unable to create user")
|
||||
}
|
||||
|
||||
// Log the user in
|
||||
|
|
|
|||
|
|
@ -41,11 +41,11 @@ func (c *resetPassword) Post(ctx echo.Context) error {
|
|||
|
||||
// Parse the form values
|
||||
if err := ctx.Bind(&form); err != nil {
|
||||
return c.Fail(ctx, err, "unable to parse password reset form")
|
||||
return c.Fail(err, "unable to parse password reset form")
|
||||
}
|
||||
|
||||
if err := form.Submission.Process(ctx, form); err != nil {
|
||||
return c.Fail(ctx, err, "unable to process form submission")
|
||||
return c.Fail(err, "unable to process form submission")
|
||||
}
|
||||
|
||||
if form.Submission.HasErrors() {
|
||||
|
|
@ -55,7 +55,7 @@ func (c *resetPassword) Post(ctx echo.Context) error {
|
|||
// Hash the new password
|
||||
hash, err := c.Container.Auth.HashPassword(form.Password)
|
||||
if err != nil {
|
||||
return c.Fail(ctx, err, "unable to hash password")
|
||||
return c.Fail(err, "unable to hash password")
|
||||
}
|
||||
|
||||
// Get the requesting user
|
||||
|
|
@ -68,13 +68,13 @@ func (c *resetPassword) Post(ctx echo.Context) error {
|
|||
Save(ctx.Request().Context())
|
||||
|
||||
if err != nil {
|
||||
return c.Fail(ctx, err, "unable to update password")
|
||||
return c.Fail(err, "unable to update password")
|
||||
}
|
||||
|
||||
// Delete all password tokens for this user
|
||||
err = c.Container.Auth.DeletePasswordTokens(ctx, usr.ID)
|
||||
if err != nil {
|
||||
return c.Fail(ctx, err, "unable to delete password tokens")
|
||||
return c.Fail(err, "unable to delete password tokens")
|
||||
}
|
||||
|
||||
msg.Success(ctx, "Your password has been updated.")
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ func (c *verifyEmail) Get(ctx echo.Context) error {
|
|||
Only(ctx.Request().Context())
|
||||
|
||||
if err != nil {
|
||||
return c.Fail(ctx, err, "query failed loading email verification token user")
|
||||
return c.Fail(err, "query failed loading email verification token user")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ func (c *verifyEmail) Get(ctx echo.Context) error {
|
|||
Save(ctx.Request().Context())
|
||||
|
||||
if err != nil {
|
||||
return c.Fail(ctx, err, "failed to set user as verified")
|
||||
return c.Fail(err, "failed to set user as verified")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue