创建验证码

This commit is contained in:
2023-08-23 20:07:56 +08:00
parent 2568659a45
commit 6fe75cf9c8
3 changed files with 66 additions and 2 deletions

View File

@@ -18,15 +18,30 @@ func init() {
configs.ORMDB().AutoMigrate(&Code{})
}
func CodeCreate(email, mobile string) string {
func CodeCreate(email, mobile string) (err error) {
code := fmt.Sprintf("%06v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000))
// 如果是邮箱,发送邮件
if email != "" {
go func() {
// 发送邮件
// ...
}()
}
// 如果是手机,发送短信
if mobile != "" {
go func() {
// 发送短信
// ...
}()
}
// 保存验证码
configs.ORMDB().Create(&Code{
Email: email,
Mobile: mobile,
Code: code,
Expire: time.Now().Add(time.Minute * 5),
})
return code
return nil
}
func EmailCheck(email, code string) (err error) {