修复登录及验证码功能
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"photowall/internal/config"
|
||||
"photowall/internal/model"
|
||||
"photowall/pkg/captcha"
|
||||
"photowall/pkg/hash"
|
||||
@@ -15,12 +14,13 @@ import (
|
||||
)
|
||||
|
||||
type AuthService struct {
|
||||
db *gorm.DB
|
||||
jm *jwt.Manager
|
||||
db *gorm.DB
|
||||
jm *jwt.Manager
|
||||
configSvc *ConfigService
|
||||
}
|
||||
|
||||
func NewAuthService(db *gorm.DB, jm *jwt.Manager) *AuthService {
|
||||
return &AuthService{db: db, jm: jm}
|
||||
func NewAuthService(db *gorm.DB, jm *jwt.Manager, configSvc *ConfigService) *AuthService {
|
||||
return &AuthService{db: db, jm: jm, configSvc: configSvc}
|
||||
}
|
||||
|
||||
// ============ 请求结构 ============
|
||||
@@ -223,9 +223,12 @@ func (s *AuthService) ResetPassword(req *ResetPasswordReq) error {
|
||||
// ============ 发送短信验证码(预留) ============
|
||||
|
||||
func (s *AuthService) SendSmsCode(req *SendSmsReq) (string, error) {
|
||||
cfg := config.C
|
||||
var accessKey, secretKey string
|
||||
if s.configSvc != nil {
|
||||
_, accessKey, secretKey, _, _ = s.configSvc.GetSmsConfig()
|
||||
}
|
||||
// 参数未配置时返回提示(开发阶段直接返回验证码)
|
||||
if cfg.SMSAccessKey == "" || cfg.SMSSecretKey == "" {
|
||||
if accessKey == "" || secretKey == "" {
|
||||
code := fmt.Sprintf("%06d", rand.Intn(1000000))
|
||||
sms := &model.SmsCode{
|
||||
Phone: req.Phone,
|
||||
@@ -256,8 +259,11 @@ type WechatLoginReq struct {
|
||||
}
|
||||
|
||||
func (s *AuthService) WechatLogin(req *WechatLoginReq) (*LoginResp, error) {
|
||||
cfg := config.C
|
||||
if cfg.WechatAppID == "" || cfg.WechatAppSecret == "" {
|
||||
var appID, appSecret string
|
||||
if s.configSvc != nil {
|
||||
appID, appSecret, _ = s.configSvc.GetWechatConfig()
|
||||
}
|
||||
if appID == "" || appSecret == "" {
|
||||
return nil, errors.New("微信登录未配置,请联系管理员")
|
||||
}
|
||||
// TODO: 接入微信开放平台API
|
||||
|
||||
Reference in New Issue
Block a user