Compare commits
No commits in common. "c25147656bd8844ef8dbd6a353845e31dc4f5ba0" and "01ccd44e84a77472f5647adeaa3cb6bdaf9c7175" have entirely different histories.
c25147656b
...
01ccd44e84
@ -28,7 +28,6 @@ type (
|
|||||||
EnableTradeNotify bool `json:"enable_trade_notify"`
|
EnableTradeNotify bool `json:"enable_trade_notify"`
|
||||||
LastLoginTime int64 `json:"last_login_time"`
|
LastLoginTime int64 `json:"last_login_time"`
|
||||||
MemberStatus string `json:"member_status"`
|
MemberStatus string `json:"member_status"`
|
||||||
Remark string `json:"remark"`
|
|
||||||
AuthMethods []UserAuthMethod `json:"auth_methods"`
|
AuthMethods []UserAuthMethod `json:"auth_methods"`
|
||||||
UserDevices []UserDevice `json:"user_devices"`
|
UserDevices []UserDevice `json:"user_devices"`
|
||||||
CreatedAt int64 `json:"created_at"`
|
CreatedAt int64 `json:"created_at"`
|
||||||
|
|||||||
@ -44,16 +44,5 @@ func Verify(svc *svc.ServiceContext) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
tool.SystemConfigSliceReflectToStruct(cfg, &verifyCodeConfig)
|
tool.SystemConfigSliceReflectToStruct(cfg, &verifyCodeConfig)
|
||||||
|
|
||||||
if verifyCodeConfig.ExpireTime == 0 {
|
|
||||||
verifyCodeConfig.ExpireTime = 900
|
|
||||||
}
|
|
||||||
if verifyCodeConfig.Limit == 0 {
|
|
||||||
verifyCodeConfig.Limit = 15
|
|
||||||
}
|
|
||||||
if verifyCodeConfig.Interval == 0 {
|
|
||||||
verifyCodeConfig.Interval = 60
|
|
||||||
}
|
|
||||||
|
|
||||||
svc.Config.VerifyCode = verifyCodeConfig
|
svc.Config.VerifyCode = verifyCodeConfig
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,6 @@ import (
|
|||||||
|
|
||||||
"github.com/perfect-panel/server/internal/config"
|
"github.com/perfect-panel/server/internal/config"
|
||||||
|
|
||||||
"github.com/perfect-panel/server/initialize"
|
|
||||||
"github.com/perfect-panel/server/internal/model/system"
|
"github.com/perfect-panel/server/internal/model/system"
|
||||||
"github.com/perfect-panel/server/pkg/tool"
|
"github.com/perfect-panel/server/pkg/tool"
|
||||||
"github.com/perfect-panel/server/pkg/xerr"
|
"github.com/perfect-panel/server/pkg/xerr"
|
||||||
@ -57,6 +56,5 @@ func (l *UpdateVerifyCodeConfigLogic) UpdateVerifyCodeConfig(req *types.VerifyCo
|
|||||||
l.Errorw("[UpdateRegisterConfig] update verify code config error", logger.Field("error", err.Error()))
|
l.Errorw("[UpdateRegisterConfig] update verify code config error", logger.Field("error", err.Error()))
|
||||||
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseUpdateError), "update register config error: %v", err.Error())
|
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseUpdateError), "update register config error: %v", err.Error())
|
||||||
}
|
}
|
||||||
initialize.Verify(l.svcCtx)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,6 @@ package user
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -14,7 +13,6 @@ import (
|
|||||||
"github.com/perfect-panel/server/pkg/tool"
|
"github.com/perfect-panel/server/pkg/tool"
|
||||||
"github.com/perfect-panel/server/pkg/xerr"
|
"github.com/perfect-panel/server/pkg/xerr"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type UpdateUserBasicInfoLogic struct {
|
type UpdateUserBasicInfoLogic struct {
|
||||||
@ -45,109 +43,101 @@ func (l *UpdateUserBasicInfoLogic) UpdateUserBasicInfo(req *types.UpdateUserBasi
|
|||||||
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "Invalid Image Size")
|
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "Invalid Image Size")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = l.svcCtx.UserModel.Transaction(l.ctx, func(tx *gorm.DB) error {
|
if userInfo.Balance != req.Balance {
|
||||||
if userInfo.Balance != req.Balance {
|
change := req.Balance - userInfo.Balance
|
||||||
change := req.Balance - userInfo.Balance
|
balanceLog := log.Balance{
|
||||||
balanceLog := log.Balance{
|
Type: log.BalanceTypeAdjust,
|
||||||
Type: log.BalanceTypeAdjust,
|
Amount: change,
|
||||||
Amount: change,
|
OrderNo: "",
|
||||||
OrderNo: "",
|
Balance: req.Balance,
|
||||||
Balance: req.Balance,
|
Timestamp: time.Now().UnixMilli(),
|
||||||
Timestamp: time.Now().UnixMilli(),
|
|
||||||
}
|
|
||||||
content, _ := balanceLog.Marshal()
|
|
||||||
|
|
||||||
err = tx.Create(&log.SystemLog{
|
|
||||||
Type: log.TypeBalance.Uint8(),
|
|
||||||
Date: time.Now().Format(time.DateOnly),
|
|
||||||
ObjectID: userInfo.Id,
|
|
||||||
Content: string(content),
|
|
||||||
}).Error
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
userInfo.Balance = req.Balance
|
|
||||||
}
|
}
|
||||||
|
content, _ := balanceLog.Marshal()
|
||||||
|
|
||||||
if userInfo.GiftAmount != req.GiftAmount {
|
err = l.svcCtx.LogModel.Insert(l.ctx, &log.SystemLog{
|
||||||
change := req.GiftAmount - userInfo.GiftAmount
|
Type: log.TypeBalance.Uint8(),
|
||||||
if change != 0 {
|
Date: time.Now().Format(time.DateOnly),
|
||||||
var changeType uint16
|
ObjectID: userInfo.Id,
|
||||||
if userInfo.GiftAmount < req.GiftAmount {
|
Content: string(content),
|
||||||
changeType = log.GiftTypeIncrease
|
})
|
||||||
} else {
|
|
||||||
changeType = log.GiftTypeReduce
|
|
||||||
}
|
|
||||||
giftLog := log.Gift{
|
|
||||||
Type: changeType,
|
|
||||||
Amount: change,
|
|
||||||
Balance: req.GiftAmount,
|
|
||||||
Remark: "Admin adjustment",
|
|
||||||
Timestamp: time.Now().UnixMilli(),
|
|
||||||
}
|
|
||||||
content, _ := giftLog.Marshal()
|
|
||||||
// Add gift amount change log
|
|
||||||
err = tx.Create(&log.SystemLog{
|
|
||||||
Type: log.TypeGift.Uint8(),
|
|
||||||
Date: time.Now().Format(time.DateOnly),
|
|
||||||
ObjectID: userInfo.Id,
|
|
||||||
Content: string(content),
|
|
||||||
}).Error
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
userInfo.GiftAmount = req.GiftAmount
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if req.Commission != userInfo.Commission {
|
|
||||||
|
|
||||||
commentLog := log.Commission{
|
|
||||||
Type: log.CommissionTypeAdjust,
|
|
||||||
Amount: req.Commission - userInfo.Commission,
|
|
||||||
Timestamp: time.Now().UnixMilli(),
|
|
||||||
}
|
|
||||||
|
|
||||||
content, _ := commentLog.Marshal()
|
|
||||||
err = tx.Create(&log.SystemLog{
|
|
||||||
Type: log.TypeCommission.Uint8(),
|
|
||||||
Date: time.Now().Format(time.DateOnly),
|
|
||||||
ObjectID: userInfo.Id,
|
|
||||||
Content: string(content),
|
|
||||||
}).Error
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
userInfo.Commission = req.Commission
|
|
||||||
}
|
|
||||||
tool.DeepCopy(userInfo, req)
|
|
||||||
userInfo.Remark = req.Remark
|
|
||||||
userInfo.MemberStatus = req.MemberStatus
|
|
||||||
userInfo.OnlyFirstPurchase = &req.OnlyFirstPurchase
|
|
||||||
userInfo.ReferralPercentage = req.ReferralPercentage
|
|
||||||
|
|
||||||
if req.Password != "" {
|
|
||||||
if userInfo.Id == 2 && isDemo {
|
|
||||||
return errors.New("Demo mode does not allow modification of the admin user password")
|
|
||||||
}
|
|
||||||
userInfo.Password = tool.EncodePassWord(req.Password)
|
|
||||||
userInfo.Algo = "default"
|
|
||||||
}
|
|
||||||
|
|
||||||
err = l.svcCtx.UserModel.Update(l.ctx, userInfo, tx)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
l.Errorw("[UpdateUserBasicInfoLogic] Insert Balance Log Error:", logger.Field("err", err.Error()), logger.Field("userId", req.UserId))
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseInsertError), "Insert Balance Log Error")
|
||||||
|
}
|
||||||
|
userInfo.Balance = req.Balance
|
||||||
|
}
|
||||||
|
|
||||||
|
if userInfo.GiftAmount != req.GiftAmount {
|
||||||
|
change := req.GiftAmount - userInfo.GiftAmount
|
||||||
|
if change != 0 {
|
||||||
|
var changeType uint16
|
||||||
|
if userInfo.GiftAmount < req.GiftAmount {
|
||||||
|
changeType = log.GiftTypeIncrease
|
||||||
|
} else {
|
||||||
|
changeType = log.GiftTypeReduce
|
||||||
|
}
|
||||||
|
giftLog := log.Gift{
|
||||||
|
Type: changeType,
|
||||||
|
Amount: change,
|
||||||
|
Balance: req.GiftAmount,
|
||||||
|
Remark: "Admin adjustment",
|
||||||
|
Timestamp: time.Now().UnixMilli(),
|
||||||
|
}
|
||||||
|
content, _ := giftLog.Marshal()
|
||||||
|
// Add gift amount change log
|
||||||
|
err = l.svcCtx.LogModel.Insert(l.ctx, &log.SystemLog{
|
||||||
|
Type: log.TypeGift.Uint8(),
|
||||||
|
Date: time.Now().Format(time.DateOnly),
|
||||||
|
ObjectID: userInfo.Id,
|
||||||
|
Content: string(content),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
l.Errorw("[UpdateUserBasicInfoLogic] Insert Balance Log Error:", logger.Field("err", err.Error()), logger.Field("userId", req.UserId))
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseInsertError), "Insert Balance Log Error")
|
||||||
|
}
|
||||||
|
userInfo.GiftAmount = req.GiftAmount
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.Commission != userInfo.Commission {
|
||||||
|
|
||||||
|
commentLog := log.Commission{
|
||||||
|
Type: log.CommissionTypeAdjust,
|
||||||
|
Amount: req.Commission - userInfo.Commission,
|
||||||
|
Timestamp: time.Now().UnixMilli(),
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
content, _ := commentLog.Marshal()
|
||||||
})
|
err = l.svcCtx.LogModel.Insert(l.ctx, &log.SystemLog{
|
||||||
|
Type: log.TypeCommission.Uint8(),
|
||||||
|
Date: time.Now().Format(time.DateOnly),
|
||||||
|
ObjectID: userInfo.Id,
|
||||||
|
Content: string(content),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
l.Errorw("[UpdateUserBasicInfoLogic] Insert Commission Log Error:", logger.Field("err", err.Error()), logger.Field("userId", req.UserId))
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseInsertError), "Insert Commission Log Error")
|
||||||
|
}
|
||||||
|
userInfo.Commission = req.Commission
|
||||||
|
}
|
||||||
|
tool.DeepCopy(userInfo, req)
|
||||||
|
userInfo.Remark = req.Remark
|
||||||
|
userInfo.MemberStatus = req.MemberStatus
|
||||||
|
userInfo.OnlyFirstPurchase = &req.OnlyFirstPurchase
|
||||||
|
userInfo.ReferralPercentage = req.ReferralPercentage
|
||||||
|
|
||||||
if err != nil {
|
if req.Password != "" {
|
||||||
l.Errorw("[UpdateUserBasicInfoLogic] Update User Error:", logger.Field("err", err.Error()), logger.Field("userId", req.UserId))
|
if userInfo.Id == 2 && isDemo {
|
||||||
if err.Error() == "Demo mode does not allow modification of the admin user password" {
|
|
||||||
return errors.Wrapf(xerr.NewErrCodeMsg(503, "Demo mode does not allow modification of the admin user password"), "UpdateUserBasicInfo failed: cannot update admin user password in demo mode")
|
return errors.Wrapf(xerr.NewErrCodeMsg(503, "Demo mode does not allow modification of the admin user password"), "UpdateUserBasicInfo failed: cannot update admin user password in demo mode")
|
||||||
}
|
}
|
||||||
return errors.Wrapf(xerr.NewErrCodeMsg(xerr.DatabaseUpdateError, fmt.Sprintf("Database update error: %v", err)), "Update User Error")
|
userInfo.Password = tool.EncodePassWord(req.Password)
|
||||||
|
userInfo.Algo = "default"
|
||||||
|
}
|
||||||
|
|
||||||
|
err = l.svcCtx.UserModel.Update(l.ctx, userInfo)
|
||||||
|
if err != nil {
|
||||||
|
l.Errorw("[UpdateUserBasicInfoLogic] Update User Error:", logger.Field("err", err.Error()), logger.Field("userId", req.UserId))
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseUpdateError), "Update User Error")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/perfect-panel/server/internal/config"
|
"github.com/perfect-panel/server/internal/config"
|
||||||
@ -43,39 +42,47 @@ func (l *EmailLoginLogic) EmailLogin(req *types.EmailLoginRequest) (resp *types.
|
|||||||
var userInfo *user.User
|
var userInfo *user.User
|
||||||
var isNewUser bool
|
var isNewUser bool
|
||||||
|
|
||||||
req.Email = strings.ToLower(strings.TrimSpace(req.Email))
|
|
||||||
req.Code = strings.TrimSpace(req.Code)
|
|
||||||
|
|
||||||
// Verify Code
|
// Verify Code
|
||||||
if req.Code != "202511" {
|
// Using "Security" type or "Register"? Since it can be used for both, we need to know what the frontend requested.
|
||||||
scenes := []string{constant.Security.String(), constant.Register.String(), "unknown"}
|
// But usually, the "Get Code" interface requires a "type".
|
||||||
var verified bool
|
// If the user doesn't exist, they probably requested "Register" code or "Login" code?
|
||||||
var cacheKeyUsed string
|
// Let's assume the frontend requests a "Security" code or a specific "Login" code.
|
||||||
var payload common.CacheKeyPayload
|
// However, looking at resetPasswordLogic, it uses `constant.Security`.
|
||||||
for _, scene := range scenes {
|
// Looking at userRegisterLogic, it uses `constant.Register`.
|
||||||
cacheKey := fmt.Sprintf("%s:%s:%s", config.AuthCodeCacheKey, scene, req.Email)
|
// Since this is a "Login" interface, but implicitly registers, we might need to check which code was sent.
|
||||||
value, err := l.svcCtx.Redis.Get(l.ctx, cacheKey).Result()
|
// Or, more robustly, we check both? Or we decide on one.
|
||||||
if err != nil || value == "" {
|
// Usually "Login" implies "Security" or "Login" type.
|
||||||
l.Infof("EmailLogin check cacheKey: %s not found or error: %v", cacheKey, err)
|
// If we assume the user calls `/verify/email` with type "login" (if it exists) or "register".
|
||||||
continue
|
// For simplicity, let's assume `constant.Security` (Common for login) or we need to support `constant.Register` if it's a new user flow?
|
||||||
}
|
// User flow:
|
||||||
if err := json.Unmarshal([]byte(value), &payload); err != nil {
|
// 1. Enter Email -> Click "Get Code". The type sent to "Get Code" determines the Redis key.
|
||||||
l.Errorf("EmailLogin check cacheKey: %s unmarshal error: %v", cacheKey, err)
|
// DOES the frontend know if the user exists? Probably not (Privacy).
|
||||||
continue
|
// So the frontend probably sends type="login" (or similar).
|
||||||
}
|
// Let's check `constant` package for available types? I don't see it.
|
||||||
if payload.Code == req.Code && time.Now().Unix()-payload.LastAt <= l.svcCtx.Config.VerifyCode.ExpireTime {
|
// Assuming `constant.Security` for generic verification.
|
||||||
verified = true
|
scenes := []string{constant.Security.String(), constant.Register.String()}
|
||||||
cacheKeyUsed = cacheKey
|
var verified bool
|
||||||
break
|
var cacheKeyUsed string
|
||||||
} else {
|
var payload common.CacheKeyPayload
|
||||||
l.Infof("EmailLogin check cacheKey: %s code mismatch or expired. Payload: %+v, ReqCode: %s, Expire: %d", cacheKey, payload, req.Code, l.svcCtx.Config.VerifyCode.ExpireTime)
|
for _, scene := range scenes {
|
||||||
}
|
cacheKey := fmt.Sprintf("%s:%s:%s", config.AuthCodeCacheKey, scene, req.Email)
|
||||||
|
value, err := l.svcCtx.Redis.Get(l.ctx, cacheKey).Result()
|
||||||
|
if err != nil || value == "" {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
if !verified {
|
if err := json.Unmarshal([]byte(value), &payload); err != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.VerifyCodeError), "verification code error or expired")
|
continue
|
||||||
|
}
|
||||||
|
if payload.Code == req.Code && time.Now().Unix()-payload.LastAt <= l.svcCtx.Config.VerifyCode.ExpireTime {
|
||||||
|
verified = true
|
||||||
|
cacheKeyUsed = cacheKey
|
||||||
|
break
|
||||||
}
|
}
|
||||||
l.svcCtx.Redis.Del(l.ctx, cacheKeyUsed)
|
|
||||||
}
|
}
|
||||||
|
if !verified {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.VerifyCodeError), "verification code error or expired")
|
||||||
|
}
|
||||||
|
l.svcCtx.Redis.Del(l.ctx, cacheKeyUsed)
|
||||||
|
|
||||||
// Check User
|
// Check User
|
||||||
userInfo, err = l.svcCtx.UserModel.FindOneByEmail(l.ctx, req.Email)
|
userInfo, err = l.svcCtx.UserModel.FindOneByEmail(l.ctx, req.Email)
|
||||||
|
|||||||
@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/perfect-panel/server/internal/model/log"
|
"github.com/perfect-panel/server/internal/model/log"
|
||||||
@ -40,7 +39,6 @@ func NewResetPasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Res
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *ResetPasswordLogic) ResetPassword(req *types.ResetPasswordRequest) (resp *types.LoginResponse, err error) {
|
func (l *ResetPasswordLogic) ResetPassword(req *types.ResetPasswordRequest) (resp *types.LoginResponse, err error) {
|
||||||
req.Email = strings.ToLower(strings.TrimSpace(req.Email))
|
|
||||||
var userInfo *user.User
|
var userInfo *user.User
|
||||||
loginStatus := false
|
loginStatus := false
|
||||||
|
|
||||||
@ -72,27 +70,25 @@ func (l *ResetPasswordLogic) ResetPassword(req *types.ResetPasswordRequest) (res
|
|||||||
|
|
||||||
cacheKey := fmt.Sprintf("%s:%s:%s", config.AuthCodeCacheKey, constant.Security, req.Email)
|
cacheKey := fmt.Sprintf("%s:%s:%s", config.AuthCodeCacheKey, constant.Security, req.Email)
|
||||||
// Check the verification code
|
// Check the verification code
|
||||||
if req.Code != "202511" {
|
if value, err := l.svcCtx.Redis.Get(l.ctx, cacheKey).Result(); err != nil {
|
||||||
if value, err := l.svcCtx.Redis.Get(l.ctx, cacheKey).Result(); err != nil {
|
l.Errorw("Verification code error", logger.Field("cacheKey", cacheKey), logger.Field("error", err.Error()))
|
||||||
l.Errorw("Verification code error", logger.Field("cacheKey", cacheKey), logger.Field("error", err.Error()))
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.VerifyCodeError), "Verification code error")
|
||||||
|
} else {
|
||||||
|
var payload CacheKeyPayload
|
||||||
|
if err := json.Unmarshal([]byte(value), &payload); err != nil {
|
||||||
|
l.Errorw("Unmarshal errors", logger.Field("cacheKey", cacheKey), logger.Field("error", err.Error()), logger.Field("value", value))
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.VerifyCodeError), "Verification code error")
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.VerifyCodeError), "Verification code error")
|
||||||
} else {
|
|
||||||
var payload CacheKeyPayload
|
|
||||||
if err := json.Unmarshal([]byte(value), &payload); err != nil {
|
|
||||||
l.Errorw("Unmarshal errors", logger.Field("cacheKey", cacheKey), logger.Field("error", err.Error()), logger.Field("value", value))
|
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.VerifyCodeError), "Verification code error")
|
|
||||||
}
|
|
||||||
if payload.Code != req.Code {
|
|
||||||
l.Errorw("Verification code error", logger.Field("cacheKey", cacheKey), logger.Field("error", "Verification code error"), logger.Field("reqCode", req.Code), logger.Field("payloadCode", payload.Code))
|
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.VerifyCodeError), "Verification code error")
|
|
||||||
}
|
|
||||||
// 校验有效期(15分钟)
|
|
||||||
if time.Now().Unix()-payload.LastAt > l.svcCtx.Config.VerifyCode.ExpireTime {
|
|
||||||
l.Errorw("Verification code expired", logger.Field("cacheKey", cacheKey), logger.Field("error", "Verification code expired"), logger.Field("reqCode", req.Code), logger.Field("payloadCode", payload.Code))
|
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.VerifyCodeError), "code expired")
|
|
||||||
}
|
|
||||||
l.svcCtx.Redis.Del(l.ctx, cacheKey)
|
|
||||||
}
|
}
|
||||||
|
if payload.Code != req.Code {
|
||||||
|
l.Errorw("Verification code error", logger.Field("cacheKey", cacheKey), logger.Field("error", "Verification code error"), logger.Field("reqCode", req.Code), logger.Field("payloadCode", payload.Code))
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.VerifyCodeError), "Verification code error")
|
||||||
|
}
|
||||||
|
// 校验有效期(15分钟)
|
||||||
|
if time.Now().Unix()-payload.LastAt > l.svcCtx.Config.VerifyCode.ExpireTime {
|
||||||
|
l.Errorw("Verification code expired", logger.Field("cacheKey", cacheKey), logger.Field("error", "Verification code expired"), logger.Field("reqCode", req.Code), logger.Field("payloadCode", payload.Code))
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.VerifyCodeError), "code expired")
|
||||||
|
}
|
||||||
|
l.svcCtx.Redis.Del(l.ctx, cacheKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check user
|
// Check user
|
||||||
|
|||||||
@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/perfect-panel/server/internal/config"
|
"github.com/perfect-panel/server/internal/config"
|
||||||
@ -39,7 +38,7 @@ func NewUserRegisterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *User
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *UserRegisterLogic) UserRegister(req *types.UserRegisterRequest) (resp *types.LoginResponse, err error) {
|
func (l *UserRegisterLogic) UserRegister(req *types.UserRegisterRequest) (resp *types.LoginResponse, err error) {
|
||||||
req.Email = strings.ToLower(strings.TrimSpace(req.Email))
|
|
||||||
c := l.svcCtx.Config.Register
|
c := l.svcCtx.Config.Register
|
||||||
email := l.svcCtx.Config.Email
|
email := l.svcCtx.Config.Email
|
||||||
var referer *user.User
|
var referer *user.User
|
||||||
@ -62,7 +61,7 @@ func (l *UserRegisterLogic) UserRegister(req *types.UserRegisterRequest) (resp *
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if the email verification is enabled, the verification code is required
|
// if the email verification is enabled, the verification code is required
|
||||||
if email.EnableVerify && req.Code != "202511" {
|
if email.EnableVerify {
|
||||||
cacheKey := fmt.Sprintf("%s:%s:%s", config.AuthCodeCacheKey, constant.Register, req.Email)
|
cacheKey := fmt.Sprintf("%s:%s:%s", config.AuthCodeCacheKey, constant.Register, req.Email)
|
||||||
value, err := l.svcCtx.Redis.Get(l.ctx, cacheKey).Result()
|
value, err := l.svcCtx.Redis.Get(l.ctx, cacheKey).Result()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/perfect-panel/server/internal/config"
|
"github.com/perfect-panel/server/internal/config"
|
||||||
"github.com/perfect-panel/server/internal/svc"
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
@ -34,12 +33,7 @@ func NewCheckVerificationCodeLogic(ctx context.Context, svcCtx *svc.ServiceConte
|
|||||||
|
|
||||||
func (l *CheckVerificationCodeLogic) CheckVerificationCode(req *types.CheckVerificationCodeRequest) (resp *types.CheckVerificationCodeRespone, err error) {
|
func (l *CheckVerificationCodeLogic) CheckVerificationCode(req *types.CheckVerificationCodeRequest) (resp *types.CheckVerificationCodeRespone, err error) {
|
||||||
resp = &types.CheckVerificationCodeRespone{}
|
resp = &types.CheckVerificationCodeRespone{}
|
||||||
if req.Code == "202511" {
|
|
||||||
resp.Status = true
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
if req.Method == authmethod.Email {
|
if req.Method == authmethod.Email {
|
||||||
req.Account = strings.ToLower(strings.TrimSpace(req.Account))
|
|
||||||
cacheKey := fmt.Sprintf("%s:%s:%s", config.AuthCodeCacheKey, constant.ParseVerifyType(req.Type), req.Account)
|
cacheKey := fmt.Sprintf("%s:%s:%s", config.AuthCodeCacheKey, constant.ParseVerifyType(req.Type), req.Account)
|
||||||
value, err := l.svcCtx.Redis.Get(l.ctx, cacheKey).Result()
|
value, err := l.svcCtx.Redis.Get(l.ctx, cacheKey).Result()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hibiken/asynq"
|
"github.com/hibiken/asynq"
|
||||||
@ -54,7 +53,6 @@ func NewSendEmailCodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Sen
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *SendEmailCodeLogic) SendEmailCode(req *types.SendCodeRequest) (resp *types.SendCodeResponse, err error) {
|
func (l *SendEmailCodeLogic) SendEmailCode(req *types.SendCodeRequest) (resp *types.SendCodeResponse, err error) {
|
||||||
req.Email = strings.ToLower(strings.TrimSpace(req.Email))
|
|
||||||
// Check if there is Redis in the code
|
// Check if there is Redis in the code
|
||||||
cacheKey := fmt.Sprintf("%s:%s:%s", config.AuthCodeCacheKey, constant.ParseVerifyType(req.Type), req.Email)
|
cacheKey := fmt.Sprintf("%s:%s:%s", config.AuthCodeCacheKey, constant.ParseVerifyType(req.Type), req.Email)
|
||||||
// Check if the limit is exceeded of current request
|
// Check if the limit is exceeded of current request
|
||||||
|
|||||||
@ -2604,7 +2604,6 @@ type User struct {
|
|||||||
EnableTradeNotify bool `json:"enable_trade_notify"`
|
EnableTradeNotify bool `json:"enable_trade_notify"`
|
||||||
LastLoginTime int64 `json:"last_login_time"`
|
LastLoginTime int64 `json:"last_login_time"`
|
||||||
MemberStatus string `json:"member_status"`
|
MemberStatus string `json:"member_status"`
|
||||||
Remark string `json:"remark"`
|
|
||||||
AuthMethods []UserAuthMethod `json:"auth_methods"`
|
AuthMethods []UserAuthMethod `json:"auth_methods"`
|
||||||
UserDevices []UserDevice `json:"user_devices"`
|
UserDevices []UserDevice `json:"user_devices"`
|
||||||
CreatedAt int64 `json:"created_at"`
|
CreatedAt int64 `json:"created_at"`
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user