可以登录

This commit is contained in:
eson 2023-07-24 12:32:05 +08:00
parent 98ae3e2106
commit 4c2f823178
3 changed files with 9 additions and 4 deletions

View File

@ -13,6 +13,7 @@ import (
"fusenapi/utils/basic"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
"gorm.io/gorm"
)
@ -22,6 +23,7 @@ type UserLoginLogic struct {
svcCtx *svc.ServiceContext
token string
resp *basic.Response
}
func NewUserLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserLoginLogic {
@ -36,6 +38,8 @@ func (l *UserLoginLogic) AfterLogic(w http.ResponseWriter, r *http.Request) {
if l.token != "" {
w.Header().Add("Authorization", fmt.Sprintf("Bearer %s", l.token))
}
httpx.OkJsonCtx(r.Context(), w, l.resp)
}
func (l *UserLoginLogic) UserLogin(req *types.RequestUserLogin, userinfo *auth.UserInfo) (resp *basic.Response) {
@ -75,6 +79,7 @@ func (l *UserLoginLogic) UserLogin(req *types.RequestUserLogin, userinfo *auth.U
}
l.token = jwtToken
l.resp = resp.SetStatus(basic.CodeOK, data)
// 返回认证成功的状态码以及数据对象 data 和 JWT Token。
return resp.SetStatus(basic.CodeOK, data)

View File

@ -109,8 +109,8 @@ type RequestBasicInfoForm struct {
}
type RequestUserLogin struct {
Email string `form:"email"`
Password string `form:"password"`
Email string `json:"email"`
Password string `json:"password"`
}
type RequestAddAddress struct {

View File

@ -178,8 +178,8 @@ type RequestBasicInfoForm {
// UserAddAddressHandler 用户登录请求结构
type RequestUserLogin {
Email string `form:"email"`
Password string `form:"password"`
Email string `json:"email"`
Password string `json:"password"`
}
// RequestAddAddress 增加地址结构