Skip to content

Commit

Permalink
Update providers's Auth API
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhu committed Sep 7, 2017
1 parent 272e5f1 commit f21148b
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion authority/authority.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (authority *Authority) Authorize(roles ...string) func(http.Handler) http.H
return
}

authority.Auth.Flash(req, session.Message{Message: AccessDeniedFlashMessage})
authority.Auth.Flash(w, req, session.Message{Message: AccessDeniedFlashMessage})
http.Redirect(w, req, authority.Config.RedirectPathAfterAccessDenied, http.StatusSeeOther)
})
}
Expand Down
2 changes: 1 addition & 1 deletion authority/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (authority *Authority) Middleware(handler http.Handler) http.Handler {
now := time.Now()
claims.LastActiveAt = &now

authority.Auth.Update(claims, req)
authority.Auth.Update(w, req, claims)
}

handler.ServeHTTP(w, req)
Expand Down
2 changes: 1 addition & 1 deletion providers/password/confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ var DefaultConfirmHandler = func(context *auth.Context) error {
now := time.Now()
authInfo.ConfirmedAt = &now
if err = tx.Model(authIdentity).Update(authInfo).Error; err == nil {
context.SessionStorer.Flash(context.Request, session.Message{Message: ConfirmedAccountFlashMessage, Type: "success"})
context.SessionStorer.Flash(context.Writer, context.Request, session.Message{Message: ConfirmedAccountFlashMessage, Type: "success"})
context.Auth.Redirector.Redirect(context.Writer, context.Request, "confirm")
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion providers/password/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ var DefaultRegisterHandler = func(context *auth.Context) (*claims.Claims, error)
authIdentity := reflect.New(utils.ModelType(context.Auth.Config.AuthIdentityModel)).Interface()
if err = tx.Where(authInfo).FirstOrCreate(authIdentity).Error; err == nil {
if provider.Config.Confirmable {
context.SessionStorer.Flash(req, session.Message{Message: ConfirmFlashMessage, Type: "success"})
context.SessionStorer.Flash(context.Writer, req, session.Message{Message: ConfirmFlashMessage, Type: "success"})
err = provider.Config.ConfirmMailer(schema.Email, context, authInfo.ToClaims(), currentUser)
}

Expand Down
12 changes: 6 additions & 6 deletions providers/password/password.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,22 +147,22 @@ func (provider Provider) ServeHTTP(context *auth.Context) {
}

if err == nil {
context.SessionStorer.Flash(req, session.Message{Message: ConfirmFlashMessage, Type: "success"})
context.SessionStorer.Flash(context.Writer, req, session.Message{Message: ConfirmFlashMessage, Type: "success"})
context.Auth.Redirector.Redirect(context.Writer, context.Request, "send_confirmation")
}
}
}

if err != nil {
context.SessionStorer.Flash(req, session.Message{Message: template.HTML(err.Error()), Type: "error"})
context.SessionStorer.Flash(context.Writer, req, session.Message{Message: template.HTML(err.Error()), Type: "error"})
}
// render new confirmation page
context.Auth.Config.Render.Execute("auth/confirmation/new", context, context.Request, context.Writer)
case "confirm":
// confirm user
err := provider.ConfirmHandler(context)
if err != nil {
context.SessionStorer.Flash(req, session.Message{Message: template.HTML(err.Error()), Type: "error"})
context.SessionStorer.Flash(context.Writer, req, session.Message{Message: template.HTML(err.Error()), Type: "error"})
context.Auth.Redirector.Redirect(context.Writer, context.Request, "confirm_failed")
return
}
Expand All @@ -173,7 +173,7 @@ func (provider Provider) ServeHTTP(context *auth.Context) {
// send recover password mail
err := provider.RecoverPasswordHandler(context)
if err != nil {
context.SessionStorer.Flash(req, session.Message{Message: template.HTML(err.Error()), Type: "error"})
context.SessionStorer.Flash(context.Writer, req, session.Message{Message: template.HTML(err.Error()), Type: "error"})
http.Redirect(context.Writer, context.Request, context.Auth.AuthURL("password/new"), http.StatusSeeOther)
return
}
Expand All @@ -185,13 +185,13 @@ func (provider Provider) ServeHTTP(context *auth.Context) {
}).Execute("auth/password/edit", context, context.Request, context.Writer)
return
}
context.SessionStorer.Flash(req, session.Message{Message: template.HTML(ErrInvalidResetPasswordToken.Error()), Type: "error"})
context.SessionStorer.Flash(context.Writer, req, session.Message{Message: template.HTML(ErrInvalidResetPasswordToken.Error()), Type: "error"})
http.Redirect(context.Writer, context.Request, context.Auth.AuthURL("password/new"), http.StatusSeeOther)
case "update":
// update password
err := provider.ResetPasswordHandler(context)
if err != nil {
context.SessionStorer.Flash(req, session.Message{Message: template.HTML(err.Error()), Type: "error"})
context.SessionStorer.Flash(context.Writer, req, session.Message{Message: template.HTML(err.Error()), Type: "error"})
http.Redirect(context.Writer, context.Request, context.Auth.AuthURL("password/new"), http.StatusSeeOther)
return
}
Expand Down
4 changes: 2 additions & 2 deletions providers/password/reset_password.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ var DefaultRecoverPasswordHandler = func(context *auth.Context) error {
err = provider.ResetPasswordMailer(email, context, authInfo.ToClaims(), currentUser)

if err == nil {
context.SessionStorer.Flash(context.Request, session.Message{Message: SendChangePasswordMailFlashMessage, Type: "success"})
context.SessionStorer.Flash(context.Writer, context.Request, session.Message{Message: SendChangePasswordMailFlashMessage, Type: "success"})
context.Auth.Redirector.Redirect(context.Writer, context.Request, "send_recover_password_mail")
}
return err
Expand Down Expand Up @@ -117,7 +117,7 @@ var DefaultResetPasswordHandler = func(context *auth.Context) error {
}

if err == nil {
context.SessionStorer.Flash(context.Request, session.Message{Message: ChangedPasswordFlashMessage, Type: "success"})
context.SessionStorer.Flash(context.Writer, context.Request, session.Message{Message: ChangedPasswordFlashMessage, Type: "success"})
context.Auth.Redirector.Redirect(context.Writer, context.Request, "reset_password")
}
return err
Expand Down

0 comments on commit f21148b

Please sign in to comment.