659168fe32
- Implemented authz-adapter deployment and service for Envoy gRPC authorization. - Created PowerShell script to generate JWK for JWT authentication. - Documented the integration of ext_authz with user-rpc.ValidateToken in ENVOY_EXT_AUTHZ_ADAPTER.md. - Added comprehensive Envoy Gateway configuration guide with JWT authentication and access control in ENVOY_GATEWAY_GUIDE.md.
60 lines
1.4 KiB
Go
60 lines
1.4 KiB
Go
// Code scaffolded by goctl. Safe to edit.
|
|
// goctl 1.9.2
|
|
|
|
package user
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"juwan-backend/app/users/api/internal/svc"
|
|
"juwan-backend/app/users/api/internal/types"
|
|
"juwan-backend/app/users/rpc/usercenter"
|
|
"time"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type LoginLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
// 用户登录接口
|
|
func NewLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginLogic {
|
|
return &LoginLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *LoginLogic) Login(req *types.LoginReq) (resp *types.LoginResp, err error) {
|
|
if len(req.Username) < 3 || len(req.Password) > 20 || len(req.Password) < 8 || len(req.Password) > 20 {
|
|
return nil, errors.New("the information is illegal")
|
|
}
|
|
|
|
res, err := l.svcCtx.UserRpc.Login(l.ctx, &usercenter.LoginReq{
|
|
Username: req.Username,
|
|
Passwd: req.Password,
|
|
})
|
|
logx.Infof("res:%v", res)
|
|
if err != nil {
|
|
logx.Errorf("rpc login err: %v", err)
|
|
return nil, errors.New("login fail")
|
|
}
|
|
|
|
if res == nil || res.Id <= 0 || res.Username == "" || res.Token == "" {
|
|
logx.Errorf("rpc login returned empty payload, username=%s, resp=%+v", req.Username, res)
|
|
return nil, errors.New("login fail")
|
|
}
|
|
|
|
return &types.LoginResp{
|
|
UserId: res.Id,
|
|
Username: res.Username,
|
|
Email: res.Email,
|
|
Token: res.Token,
|
|
Expires: int64((7 * 24 * time.Hour).Seconds()),
|
|
}, nil
|
|
}
|