feat: add email_send_log table to track email sends and registration status

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-30 14:29:30 +08:00
parent a07e08a761
commit 87bee98049
3 changed files with 81 additions and 3 deletions

View File

@@ -21,12 +21,14 @@ import (
)
type UserService struct {
userDao *dao.UserDao
userDao *dao.UserDao
emailSendLogDao *dao.EmailSendLogDao
}
func NewUserService() *UserService {
return &UserService{
userDao: dao.NewUserDao(),
userDao: dao.NewUserDao(),
emailSendLogDao: dao.NewEmailSendLogDao(),
}
}
@@ -141,6 +143,12 @@ func (svc *UserService) SendEmailVerifyCode(ctx context.Context, emailAddr strin
if cacheErr := cache.SetUserSendEmailLimit(ctx, emailAddr); cacheErr != nil {
log.Error(ctx, "func", "SendEmailVerifyCode", "msg", "set send email limit error", "error", cacheErr)
}
record := &dao.EmailSendLog{Email: emailAddr, Status: dao.EmailSendStatusSent}
if logErr := svc.emailSendLogDao.Create(dao.DB.WithContext(ctx), record); logErr != nil {
log.Error(ctx, "func", "SendEmailVerifyCode", "msg", "create email send log error", "error", logErr)
}
return nil
}
@@ -156,7 +164,16 @@ func (svc *UserService) RegisterByEmail(ctx context.Context, emailAddr, password
_ = cache.DeleteUserEmailCode(ctx, emailAddr)
return svc.registerByEmailInternal(ctx, emailAddr, password)
uid, err = svc.registerByEmailInternal(ctx, emailAddr, password)
if err != nil {
return 0, err
}
if logErr := svc.emailSendLogDao.MarkRegistered(dao.DB.WithContext(ctx), emailAddr); logErr != nil {
log.Error(ctx, "func", "RegisterByEmail", "msg", "mark email send log registered error", "error", logErr)
}
return uid, nil
}
func (svc *UserService) registerByEmailInternal(ctx context.Context, emailAddr, password string) (uid int64, err error) {