fix
This commit is contained in:
@@ -2,6 +2,7 @@ package logic
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fusenapi/utils/check"
|
||||
"log"
|
||||
"net/smtp"
|
||||
"sync"
|
||||
@@ -9,8 +10,35 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var TimeLimit *check.TimeLimit[string]
|
||||
var EmailManager *EmailSender
|
||||
|
||||
func init() {
|
||||
|
||||
TimeLimit = check.NewTimelimit[string](time.Second * 25)
|
||||
|
||||
// Initialize the email manager
|
||||
EmailManager = &EmailSender{
|
||||
EmailTasks: make(chan *EmailFormat, 10),
|
||||
Auth: smtp.PlainAuth(
|
||||
"",
|
||||
"support@fusenpack.com",
|
||||
"wfbjpdgvaozjvwah",
|
||||
"smtp.gmail.com",
|
||||
),
|
||||
FromEmail: "support@fusenpack.com",
|
||||
emailSending: make(map[string]*EmailTask, 10),
|
||||
ResendTimeLimit: time.Minute * 1,
|
||||
semaphore: make(chan struct{}, 10), // Initialize semaphore with a capacity of 10
|
||||
}
|
||||
|
||||
// Start processing email tasks
|
||||
go EmailManager.ProcessEmailTasks()
|
||||
|
||||
// Start clearing expired tasks
|
||||
go EmailManager.ClearExpiredTasks()
|
||||
}
|
||||
|
||||
type EmailFormat struct {
|
||||
TargetEmail string // 发送的目标email
|
||||
CompanyName string // fs公司名
|
||||
@@ -110,30 +138,6 @@ func (m *EmailSender) ClearExpiredTasks() {
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
// Initialize the email manager
|
||||
EmailManager = &EmailSender{
|
||||
EmailTasks: make(chan *EmailFormat, 10),
|
||||
Auth: smtp.PlainAuth(
|
||||
"",
|
||||
"support@fusenpack.com",
|
||||
"wfbjpdgvaozjvwah",
|
||||
"smtp.gmail.com",
|
||||
),
|
||||
FromEmail: "support@fusenpack.com",
|
||||
emailSending: make(map[string]*EmailTask, 10),
|
||||
ResendTimeLimit: time.Minute * 1,
|
||||
semaphore: make(chan struct{}, 10), // Initialize semaphore with a capacity of 10
|
||||
}
|
||||
|
||||
// Start processing email tasks
|
||||
go EmailManager.ProcessEmailTasks()
|
||||
|
||||
// Start clearing expired tasks
|
||||
go EmailManager.ClearExpiredTasks()
|
||||
}
|
||||
|
||||
const emailTemplate = `Subject: Your {{.CompanyName}} Account Confirmation
|
||||
|
||||
Dear
|
||||
|
||||
@@ -47,6 +47,10 @@ func (l *UserEmailRegisterLogic) UserEmailRegister(req *types.RequestEmailRegist
|
||||
return resp.SetStatus(basic.CodeOAuthEmailErr)
|
||||
}
|
||||
|
||||
if !TimeLimit.Is(req.Email) {
|
||||
return resp.SetStatus(basic.CodeEmailTimeShortErr)
|
||||
}
|
||||
|
||||
token, err := l.svcCtx.OAuthTokenManger.Decrypt(req.RegisterToken)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
|
||||
@@ -46,6 +46,10 @@ func (l *UserRegisterLogic) UserRegister(req *types.RequestUserRegister, userinf
|
||||
return resp.SetStatus(basic.CodeEmailExistsErr)
|
||||
}
|
||||
|
||||
if !TimeLimit.Is(req.Email) {
|
||||
return resp.SetStatus(basic.CodeEmailTimeShortErr)
|
||||
}
|
||||
|
||||
token := &auth.RegisterToken{
|
||||
OperateType: auth.OpTypeRegister,
|
||||
GuestId: userinfo.GuestId,
|
||||
|
||||
Reference in New Issue
Block a user