|
@@ -36,9 +36,8 @@ var (
|
|
|
)
|
|
|
|
|
|
type HomeURLFunc func(r *http.Request, user interface{}) string
|
|
|
-type NotifyUserOfResetPasswordLinkFunc func(user interface{}, resetLink string) error
|
|
|
type PasswordValidationFunc func(password string) (message string, ok bool)
|
|
|
-type HookFunc func(r *http.Request, user interface{}, vals ...interface{}) error
|
|
|
+type HookFunc func(r *http.Request, user interface{}, extraVals ...interface{}) error
|
|
|
|
|
|
type void struct{}
|
|
|
|
|
@@ -109,19 +108,18 @@ type Builder struct {
|
|
|
totpSetupPageFunc web.PageFunc
|
|
|
totpValidatePageFunc web.PageFunc
|
|
|
|
|
|
- notifyUserOfResetPasswordLinkFunc NotifyUserOfResetPasswordLinkFunc
|
|
|
- passwordValidationFunc PasswordValidationFunc
|
|
|
+ passwordValidationFunc PasswordValidationFunc
|
|
|
|
|
|
- afterLoginHook HookFunc
|
|
|
- afterFailedToLoginHook HookFunc
|
|
|
- afterUserLockedHook HookFunc
|
|
|
- afterLogoutHook HookFunc
|
|
|
- afterSendResetPasswordLinkHook HookFunc
|
|
|
- afterResetPasswordHook HookFunc
|
|
|
- afterChangePasswordHook HookFunc
|
|
|
- afterExtendSessionHook HookFunc
|
|
|
- afterTOTPCodeReusedHook HookFunc
|
|
|
- afterOAuthCompleteHook HookFunc
|
|
|
+ afterLoginHook HookFunc
|
|
|
+ afterFailedToLoginHook HookFunc
|
|
|
+ afterUserLockedHook HookFunc
|
|
|
+ afterLogoutHook HookFunc
|
|
|
+ afterConfirmSendResetPasswordLinkHook HookFunc
|
|
|
+ afterResetPasswordHook HookFunc
|
|
|
+ afterChangePasswordHook HookFunc
|
|
|
+ afterExtendSessionHook HookFunc
|
|
|
+ afterTOTPCodeReusedHook HookFunc
|
|
|
+ afterOAuthCompleteHook HookFunc
|
|
|
|
|
|
db *gorm.DB
|
|
|
userModel interface{}
|
|
@@ -293,11 +291,6 @@ func (b *Builder) TOTPValidatePageFunc(v web.PageFunc) (r *Builder) {
|
|
|
return b
|
|
|
}
|
|
|
|
|
|
-func (b *Builder) NotifyUserOfResetPasswordLinkFunc(v NotifyUserOfResetPasswordLinkFunc) (r *Builder) {
|
|
|
- b.notifyUserOfResetPasswordLinkFunc = v
|
|
|
- return b
|
|
|
-}
|
|
|
-
|
|
|
func (b *Builder) PasswordValidationFunc(v PasswordValidationFunc) (r *Builder) {
|
|
|
b.passwordValidationFunc = v
|
|
|
return b
|
|
@@ -308,11 +301,11 @@ func (b *Builder) wrapHook(v HookFunc) HookFunc {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
- return func(r *http.Request, user interface{}, vals ...interface{}) error {
|
|
|
+ return func(r *http.Request, user interface{}, extraVals ...interface{}) error {
|
|
|
if GetCurrentUser(r) == nil {
|
|
|
r = r.WithContext(context.WithValue(r.Context(), UserKey, user))
|
|
|
}
|
|
|
- return v(r, user, vals...)
|
|
|
+ return v(r, user, extraVals...)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -336,8 +329,10 @@ func (b *Builder) AfterLogout(v HookFunc) (r *Builder) {
|
|
|
return b
|
|
|
}
|
|
|
|
|
|
-func (b *Builder) AfterSendResetPasswordLink(v HookFunc) (r *Builder) {
|
|
|
- b.afterSendResetPasswordLinkHook = b.wrapHook(v)
|
|
|
+// extra vals:
|
|
|
+// - reset link
|
|
|
+func (b *Builder) AfterConfirmSendResetPasswordLink(v HookFunc) (r *Builder) {
|
|
|
+ b.afterConfirmSendResetPasswordLinkHook = b.wrapHook(v)
|
|
|
return b
|
|
|
}
|
|
|
|
|
@@ -351,7 +346,7 @@ func (b *Builder) AfterChangePassword(v HookFunc) (r *Builder) {
|
|
|
return b
|
|
|
}
|
|
|
|
|
|
-// vals:
|
|
|
+// extra vals:
|
|
|
// - old session token
|
|
|
func (b *Builder) AfterExtendSession(v HookFunc) (r *Builder) {
|
|
|
b.afterExtendSessionHook = b.wrapHook(v)
|
|
@@ -1006,17 +1001,8 @@ func (b *Builder) sendResetPasswordLink(w http.ResponseWriter, r *http.Request)
|
|
|
if doTOTP {
|
|
|
link = MustSetQuery(link, "totp", "1")
|
|
|
}
|
|
|
- if err = b.notifyUserOfResetPasswordLinkFunc(u, link); err != nil {
|
|
|
- setFailCodeFlash(w, FailCodeSystemError)
|
|
|
- setWrongForgetPasswordInputFlash(w, WrongForgetPasswordInputFlash{
|
|
|
- Account: account,
|
|
|
- })
|
|
|
- http.Redirect(w, r, failRedirectURL, http.StatusFound)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- if b.afterSendResetPasswordLinkHook != nil {
|
|
|
- if herr := b.afterSendResetPasswordLinkHook(r, u); herr != nil {
|
|
|
+ if b.afterConfirmSendResetPasswordLinkHook != nil {
|
|
|
+ if herr := b.afterConfirmSendResetPasswordLinkHook(r, u, link); herr != nil {
|
|
|
setFailCodeFlash(w, FailCodeSystemError)
|
|
|
http.Redirect(w, r, failRedirectURL, http.StatusFound)
|
|
|
return
|