提供文件上传及静态服务
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
949 B

4 months ago
package service
import (
"errors"
"service-api/model"
"service-api/utils"
"strings"
"time"
)
//@function: EmailTest
//@description: 发送邮件测试
//@return: err error
func EmailTest() (err error) {
subject := "test"
body := "test"
err = utils.EmailTest(subject, body)
return err
}
func EmailCaptcha(email string) (err error) {
subject := "验证码"
body := "您的验证码为:"
code := utils.GetInvitation()
body += code
tos := strings.Split(email, ",")
for _, y := range tos {
RedisSet("email:email-"+y, code, 5*time.Minute)
}
err = utils.EmailCode(email, subject, body)
return err
}
func EmailCheck(email model.Email) (err error) {
captcha := RedisGet("email:email-" + email.Email)
if captcha == "" {
return errors.New("验证码已失效,请重新发送")
}
_, _ = RedisDel("email:email-" + email.Email)
if captcha == strings.ToUpper(email.Captcha) {
return nil
}
return errors.New("验证码错误")
}