mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-19 17:24:26 +08:00
add failure retry detection to the sending forget password mail
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/core"
|
"github.com/mayswind/ezbookkeeping/pkg/core"
|
||||||
|
"github.com/mayswind/ezbookkeeping/pkg/duplicatechecker"
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/errs"
|
"github.com/mayswind/ezbookkeeping/pkg/errs"
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/log"
|
"github.com/mayswind/ezbookkeeping/pkg/log"
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/models"
|
"github.com/mayswind/ezbookkeeping/pkg/models"
|
||||||
@@ -14,6 +15,7 @@ import (
|
|||||||
// ForgetPasswordsApi represents user forget password api
|
// ForgetPasswordsApi represents user forget password api
|
||||||
type ForgetPasswordsApi struct {
|
type ForgetPasswordsApi struct {
|
||||||
ApiUsingConfig
|
ApiUsingConfig
|
||||||
|
ApiUsingDuplicateChecker
|
||||||
users *services.UserService
|
users *services.UserService
|
||||||
tokens *services.TokenService
|
tokens *services.TokenService
|
||||||
forgetPasswords *services.ForgetPasswordService
|
forgetPasswords *services.ForgetPasswordService
|
||||||
@@ -25,6 +27,12 @@ var (
|
|||||||
ApiUsingConfig: ApiUsingConfig{
|
ApiUsingConfig: ApiUsingConfig{
|
||||||
container: settings.Container,
|
container: settings.Container,
|
||||||
},
|
},
|
||||||
|
ApiUsingDuplicateChecker: ApiUsingDuplicateChecker{
|
||||||
|
ApiUsingConfig: ApiUsingConfig{
|
||||||
|
container: settings.Container,
|
||||||
|
},
|
||||||
|
container: duplicatechecker.Container,
|
||||||
|
},
|
||||||
users: services.Users,
|
users: services.Users,
|
||||||
tokens: services.Tokens,
|
tokens: services.Tokens,
|
||||||
forgetPasswords: services.ForgetPasswords,
|
forgetPasswords: services.ForgetPasswords,
|
||||||
@@ -41,6 +49,13 @@ func (a *ForgetPasswordsApi) UserForgetPasswordRequestHandler(c *core.WebContext
|
|||||||
return nil, errs.ErrEmailIsEmptyOrInvalid
|
return nil, errs.ErrEmailIsEmptyOrInvalid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = a.CheckFailureCount(c, 0)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf(c, "[forget_passwords.UserForgetPasswordRequestHandler] cannot send forget password mail to \"%s\", because %s", request.Email, err.Error())
|
||||||
|
return nil, errs.Or(err, errs.ErrFailureCountLimitReached)
|
||||||
|
}
|
||||||
|
|
||||||
user, err := a.users.GetUserByEmail(c, request.Email)
|
user, err := a.users.GetUserByEmail(c, request.Email)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -48,6 +63,13 @@ func (a *ForgetPasswordsApi) UserForgetPasswordRequestHandler(c *core.WebContext
|
|||||||
log.Errorf(c, "[forget_passwords.UserForgetPasswordRequestHandler] failed to get user, because %s", err.Error())
|
log.Errorf(c, "[forget_passwords.UserForgetPasswordRequestHandler] failed to get user, because %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
failureCheckErr := a.CheckAndIncreaseFailureCount(c, 0)
|
||||||
|
|
||||||
|
if failureCheckErr != nil {
|
||||||
|
log.Warnf(c, "[forget_passwords.UserForgetPasswordRequestHandler] cannot send forget password mail to \"%s\", because %s", request.Email, failureCheckErr.Error())
|
||||||
|
return nil, errs.Or(failureCheckErr, errs.ErrFailureCountLimitReached)
|
||||||
|
}
|
||||||
|
|
||||||
return nil, errs.ErrUserNotFound
|
return nil, errs.ErrUserNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user