修复登录及验证码功能
This commit is contained in:
+10
-4
@@ -5,7 +5,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"photowall/internal/config"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
@@ -15,6 +14,14 @@ import (
|
||||
|
||||
var ErrNotConfigured = errors.New("短信服务未配置,请联系管理员")
|
||||
|
||||
type Config struct {
|
||||
Provider string
|
||||
AccessKey string
|
||||
SecretKey string
|
||||
SignName string
|
||||
TemplateCode string
|
||||
}
|
||||
|
||||
type codeItem struct {
|
||||
code string
|
||||
expireAt time.Time
|
||||
@@ -26,11 +33,10 @@ var (
|
||||
|
||||
// SendCode 发送短信验证码
|
||||
// 开发阶段(未配置短信服务商):验证码输出到日志,方便测试
|
||||
func SendCode(phone string) (string, error) {
|
||||
cfg := config.C
|
||||
func SendCode(cfg Config, phone string) (string, error) {
|
||||
code := generateCode()
|
||||
|
||||
if cfg.SMSAccessKey == "" || cfg.SMSSecretKey == "" || cfg.SMSSignName == "" || cfg.SMSTemplateCode == "" {
|
||||
if cfg.AccessKey == "" || cfg.SecretKey == "" || cfg.SignName == "" || cfg.TemplateCode == "" {
|
||||
// 未配置短信服务商,开发模式:日志输出验证码
|
||||
fmt.Printf("[SMS-DEV] 手机号 %s 的验证码: %s (5分钟有效)\n", phone, code)
|
||||
store.Store(phone, codeItem{code: code, expireAt: time.Now().Add(5 * time.Minute)})
|
||||
|
||||
Reference in New Issue
Block a user