fix: corrected redis logic to prevent temporary lock-outs on failed database transactions; #8
@@ -348,6 +348,14 @@ func (a *authServiceImpl) RegistrationBegin(request models.RegistrationBeginRequ
|
|||||||
a.log.Error(
|
a.log.Error(
|
||||||
"Failed to commit transaction",
|
"Failed to commit transaction",
|
||||||
zap.Error(err))
|
zap.Error(err))
|
||||||
|
|
||||||
|
redisErr := a.redis.Del(context.TODO(), fmt.Sprintf("email::%s::registration_in_progress", request.Email))
|
||||||
|
if redisErr != nil {
|
||||||
|
a.log.Error(
|
||||||
|
"Failed to delete cooldown redis key while rolling back RegistrationBegin",
|
||||||
|
zap.Error(redisErr.Err()))
|
||||||
|
}
|
||||||
|
|
||||||
return false, errs.ErrServerError
|
return false, errs.ErrServerError
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -808,6 +816,14 @@ func (a *authServiceImpl) PasswordResetBegin(request models.PasswordResetBeginRe
|
|||||||
a.log.Error(
|
a.log.Error(
|
||||||
"Failed to commit transaction",
|
"Failed to commit transaction",
|
||||||
zap.Error(err))
|
zap.Error(err))
|
||||||
|
|
||||||
|
redisErr := a.redis.Del(context.TODO(), fmt.Sprintf("email::%s::reset_cooldown", request.Email))
|
||||||
|
if redisErr != nil {
|
||||||
|
a.log.Error(
|
||||||
|
"Failed to delete cooldown redis key while rolling back PasswordResetBegin",
|
||||||
|
zap.Error(redisErr.Err()))
|
||||||
|
}
|
||||||
|
|
||||||
return false, errs.ErrServerError
|
return false, errs.ErrServerError
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -904,6 +920,7 @@ func (a *authServiceImpl) PasswordResetComplete(request models.PasswordResetComp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: grab client info
|
||||||
session, err = db.TXQueries.CreateSession(db.CTX, database.CreateSessionParams{
|
session, err = db.TXQueries.CreateSession(db.CTX, database.CreateSessionParams{
|
||||||
UserID: user.ID,
|
UserID: user.ID,
|
||||||
Name: utils.NewPointer("First device"),
|
Name: utils.NewPointer("First device"),
|
||||||
@@ -947,6 +964,7 @@ func (a *authServiceImpl) PasswordResetComplete(request models.PasswordResetComp
|
|||||||
return &response, nil
|
return &response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// XXX: Mechanism for loging out existing sessions currently does not exist
|
||||||
func (a *authServiceImpl) ChangePassword(request models.ChangePasswordRequest, uinfo dto.ClientInfo) (bool, error) {
|
func (a *authServiceImpl) ChangePassword(request models.ChangePasswordRequest, uinfo dto.ClientInfo) (bool, error) {
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
@@ -981,7 +999,7 @@ func (a *authServiceImpl) ChangePassword(request models.ChangePasswordRequest, u
|
|||||||
return false, errs.ErrServerError
|
return false, errs.ErrServerError
|
||||||
}
|
}
|
||||||
|
|
||||||
err = db.TXlessQueries.UpdateLoginInformationByUsername(db.CTX, database.UpdateLoginInformationByUsernameParams{
|
err = db.TXQueries.UpdateLoginInformationByUsername(db.CTX, database.UpdateLoginInformationByUsernameParams{
|
||||||
Username: uinfo.Username,
|
Username: uinfo.Username,
|
||||||
PasswordHash: newPasswordHash,
|
PasswordHash: newPasswordHash,
|
||||||
}); if err != nil {
|
}); if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user