fa465a01f0
CI / changes (push) Successful in 1m35s
CI / ad (push) Successful in 32s
CI / admin (push) Successful in 25s
CI / bff (push) Successful in 22s
CI / chore (push) Successful in 27s
CI / equipment (push) Successful in 24s
CI / express (push) Successful in 24s
CI / factory (push) Successful in 22s
CI / message (push) Successful in 21s
CI / order (push) Successful in 23s
CI / payment (push) Successful in 23s
CI / percutaneous (push) Successful in 21s
CI / product (push) Successful in 22s
CI / record (push) Successful in 21s
CI / sale (push) Successful in 21s
CI / support (push) Successful in 22s
CI / task (push) Successful in 23s
CI / user (push) Successful in 23s
CI / water (push) Successful in 24s
CI / wecom (push) Successful in 24s
49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"lone-services/pkg/redis"
|
|
"lone-services/pkg/utils"
|
|
"lone-services/services/equipment/internal/dao"
|
|
"strconv"
|
|
"time"
|
|
|
|
"lone-services/rpc/equipment/pb"
|
|
"lone-services/services/equipment/internal/svc"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type AuthorizationCodeLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
BaseLogic
|
|
}
|
|
|
|
func NewAuthorizationCodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AuthorizationCodeLogic {
|
|
return &AuthorizationCodeLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *AuthorizationCodeLogic) AuthorizationCode(in *equipment.EmptyRequest) (*equipment.Response, error) {
|
|
adminInfo := utils.GetUserFromCtx(l.ctx)
|
|
if adminInfo.ID < utils.NumberOne {
|
|
return l.fail(utils.ErrorNoLoginInfo)
|
|
}
|
|
|
|
key := dao.CodeName + strconv.FormatInt(adminInfo.ID, utils.NumberTen)
|
|
|
|
code := utils.RandNumber(utils.NumberSix)
|
|
out := utils.GetConfigInt("code.out-time")
|
|
_, err := redis.Client.Set(l.ctx, key, code, time.Duration(out)*time.Second).Result()
|
|
if err != nil {
|
|
l.Logger.Error(err)
|
|
return l.fail(utils.Fail)
|
|
}
|
|
return l.ok(code)
|
|
}
|