@@ -0,0 +1,33 @@
|
||||
package notiser
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"91porn-server/app/appg"
|
||||
"91porn-server/app/service/emailser"
|
||||
"91porn-server/common/constant"
|
||||
"91porn-server/common/constant/redisconst"
|
||||
"91porn-server/common/email"
|
||||
"91porn-server/common/log"
|
||||
"91porn-server/common/maths"
|
||||
"91porn-server/common/stderr"
|
||||
)
|
||||
|
||||
func SendEamil(ctx context.Context, emailStr string) stderr.Code {
|
||||
if code := emailser.CheckEmail(ctx, emailStr); code != stderr.Success {
|
||||
return code
|
||||
}
|
||||
code := maths.RandDigits(constant.CaptchaLen)
|
||||
redisKey := redisconst.GetEmailCaptchaKey(emailStr)
|
||||
if err := appg.Redis.Set(redisKey, code, redisconst.EmailCaptchaExpire); err != nil {
|
||||
log.ErrorX(ctx, "save code in redis failed", log.Any("email", emailStr), log.Any("redisKey", redisKey), log.E(err))
|
||||
return stderr.ErrNetWorkBusy
|
||||
}
|
||||
var DefaultEmailSender string = fmt.Sprintf("%s@%s", "no-reply", appg.Conf.AWS.SES.VerifiedDomain)
|
||||
if err := email.Client.Send(ctx, DefaultEmailSender, []*string{&emailStr}, "验证码",
|
||||
fmt.Sprintf("<h2>您的验证码是 %s</h2>", code)); err != nil {
|
||||
return stderr.ErrNetWorkBusy
|
||||
}
|
||||
return stderr.Success
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package notiser
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"91porn-server/app/appg"
|
||||
"91porn-server/app/service/emailser"
|
||||
"91porn-server/app/service/smsser"
|
||||
"91porn-server/common/constant"
|
||||
"91porn-server/common/stderr"
|
||||
)
|
||||
|
||||
const (
|
||||
SMSMobileBind = 1
|
||||
SMSCaptcha = 2
|
||||
EmailCaptcha = 3
|
||||
)
|
||||
|
||||
// SendCaptcha 发送验证码
|
||||
func SendCaptcha(ctx context.Context, mobile, email string, typ int) stderr.Code {
|
||||
switch typ {
|
||||
case SMSCaptcha, SMSMobileBind:
|
||||
return smsser.SendSmsCode(ctx, mobile, typ)
|
||||
case EmailCaptcha:
|
||||
return SendEamil(ctx, email)
|
||||
default:
|
||||
return stderr.ErrNotSupportedCaptcha
|
||||
}
|
||||
}
|
||||
|
||||
// VerifyCaptchaCode 校验验证码
|
||||
func VerifyCaptchaCode(ctx context.Context, mobile, email, code string) stderr.Code {
|
||||
if appg.Conf.Base.Env != constant.ReleaseRunmod { // 测试环境为方便测试不校验验证码
|
||||
return stderr.Success
|
||||
}
|
||||
if mobile != "" {
|
||||
return smsser.VerifySmsCode(mobile, code)
|
||||
}
|
||||
if email != "" {
|
||||
return emailser.VerifyCaptchaCode(ctx, email, code)
|
||||
}
|
||||
return stderr.ErrNotSupportedCaptcha
|
||||
}
|
||||
Reference in New Issue
Block a user