init: hgmj server initial commit

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-10-08 16:50:13 +08:00
co-authored by Claude Opus 4.7
commit 625e89c15d
1870 changed files with 254090 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
package emailser
import (
"context"
"strings"
"91jd-server/app/appg"
"91jd-server/common/constant/redisconst"
"91jd-server/common/log"
"91jd-server/common/stderr"
"github.com/badoux/checkmail"
)
// CheckEmail 校验邮件地址是否合法
func CheckEmail(ctx context.Context, emailStr string) stderr.Code {
if emailStr == "" {
return stderr.ErrInvalidEmail
}
if err := checkmail.ValidateFormat(emailStr); err != nil {
log.ErrorX(ctx, "invalid email", log.Any("email", emailStr), log.E(err))
return stderr.ErrInvalidEmail
}
return stderr.Success
}
// VerifyCaptchaCode 核对验证码
func VerifyCaptchaCode(ctx context.Context, emailAddr, code string) stderr.Code {
emailAddr = strings.TrimSpace(emailAddr)
if strings.HasSuffix(emailAddr, "@dsp.xyz") { // pass the test email
log.InfoX(ctx, "VerifyCaptchaCode dismiss test email", log.Any("email", emailAddr))
return stderr.Success
}
if code := CheckEmail(ctx, emailAddr); code != stderr.Success {
return code
}
redisKey := redisconst.GetEmailCaptchaKey(emailAddr)
redisCode, err := appg.Redis.Get(redisKey)
if err != nil {
log.ErrorX(ctx, "VerifyCaptchaCode redis get err", log.Any("emailAddr", emailAddr),
log.Any("redisKey", redisKey), log.E(err))
return stderr.ErrNetWorkBusy
}
if redisCode == nil {
log.InfoX(ctx, "VerifyCaptchaCode nil code in redis", log.Any("emailAddr", emailAddr), log.Any("code", code))
return stderr.ErrCaptcha
}
if *redisCode != code {
log.InfoX(ctx, "VerifyCaptchaCode invalid", log.Any("emailAddr", emailAddr), log.Any("code", code),
log.Any("redisCode", redisCode))
return stderr.ErrCaptchaInvalid
}
return stderr.Success
}