fix version 1
This commit is contained in:
@@ -5,6 +5,9 @@ import (
|
||||
"time"
|
||||
|
||||
"bsm/full/module/base/passport/internal/impl"
|
||||
"bsm/full/module/base/passport/internal/vars"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -103,21 +106,21 @@ func InvalidateUserCache(ctx context.Context, passportID uint, identity string)
|
||||
|
||||
// SetTokenCache 设置Token缓存
|
||||
func SetTokenCache(ctx context.Context, identity, token string) error {
|
||||
key := impl.RedisService.BuildKey("token", identity)
|
||||
key := vars.TokenPrefix + identity
|
||||
return impl.RedisService.Set(key, token, TokenCacheTTL)
|
||||
}
|
||||
|
||||
// GetTokenCache 获取Token缓存
|
||||
func GetTokenCache(ctx context.Context, identity string) (string, error) {
|
||||
var token string
|
||||
key := impl.RedisService.BuildKey("token", identity)
|
||||
key := vars.TokenPrefix + identity
|
||||
err := impl.RedisService.Get(key, &token)
|
||||
return token, err
|
||||
}
|
||||
|
||||
// InvalidateTokenCache 清除Token缓存
|
||||
func InvalidateTokenCache(ctx context.Context, identity string) error {
|
||||
key := impl.RedisService.BuildKey("token", identity)
|
||||
key := vars.TokenPrefix + identity
|
||||
return impl.RedisService.Client.Del(impl.RedisService.Ctx, key).Err()
|
||||
}
|
||||
|
||||
@@ -141,6 +144,32 @@ func InvalidateVerificationCodeCache(ctx context.Context, phone string) error {
|
||||
return impl.RedisService.Client.Del(impl.RedisService.Ctx, key).Err()
|
||||
}
|
||||
|
||||
// VerifySmsCode 校验短信验证码
|
||||
// 按 sender 模块约定从 Redis 读取 /SMS/Code/{phone} 并比对输入值,
|
||||
// 校验通过后立即删除该 key(一次性),失败返回 errcode.ErrInvalidArgument。
|
||||
func VerifySmsCode(ctx context.Context, phone, code string) error {
|
||||
if phone == "" || code == "" {
|
||||
return errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
key := vars.SmsCodePrefix + phone
|
||||
stored, err := impl.RedisService.Client.Get(impl.RedisService.Ctx, key).Result()
|
||||
if err != nil {
|
||||
printer.Error("Get sms code by phone %v error:%v", phone, err)
|
||||
return errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
if stored != code {
|
||||
printer.Error("Sms code not match by phone %v", phone)
|
||||
return errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// 校验成功后删除,防止同一验证码被重复使用
|
||||
impl.RedisService.Client.Del(impl.RedisService.Ctx, key)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// IncrementLoginAttempts 增加登录尝试次数
|
||||
func IncrementLoginAttempts(ctx context.Context, account string) (int64, error) {
|
||||
key := impl.RedisService.BuildKey("loginattempts", account)
|
||||
|
||||
@@ -18,7 +18,7 @@ func InitData() error {
|
||||
}
|
||||
if cnt == 0 {
|
||||
salt := utils.ULID()
|
||||
hashedPassword, _ := bcrypt.GenerateFromPassword([]byte("welcome"+salt), bcrypt.MinCost)
|
||||
hashedPassword, _ := bcrypt.GenerateFromPassword([]byte("welcome"+salt), bcrypt.DefaultCost)
|
||||
pa := PassportAccount{
|
||||
Std_IICUDS: types.Std_IICUDS{
|
||||
Identity: utils.UUID(),
|
||||
|
||||
Reference in New Issue
Block a user