model 格式改变
This commit is contained in:
@@ -5,4 +5,4 @@ SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest
|
||||
|
||||
Auth:
|
||||
AccessSecret: fusen2023
|
||||
AccessExpire: 604800
|
||||
AccessExpire: 60
|
||||
|
||||
@@ -35,6 +35,8 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
@@ -44,5 +46,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
},
|
||||
},
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
|
||||
)
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"fusenapi/home-user-auth/internal/logic"
|
||||
"fusenapi/home-user-auth/internal/svc"
|
||||
"fusenapi/home-user-auth/internal/types"
|
||||
"fusenapi/utils/auth"
|
||||
)
|
||||
|
||||
func UserSaveBasicInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
@@ -26,8 +25,7 @@ func UserSaveBasicInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
|
||||
l := logic.NewUserSaveBasicInfoLogic(r.Context(), svcCtx)
|
||||
userinfo := auth.CheckAuth(r)
|
||||
resp := l.UserSaveBasicInfo(&req, &userinfo)
|
||||
resp := l.UserSaveBasicInfo(&req)
|
||||
if resp != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
} else {
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"fusenapi/model"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"github.com/golang-jwt/jwt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
@@ -25,12 +26,21 @@ func NewUserLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserLog
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UserLoginLogic) getJwtToken(secretKey string, iat, seconds, userId int64) (string, error) {
|
||||
claims := make(jwt.MapClaims)
|
||||
claims["exp"] = iat + seconds
|
||||
claims["iat"] = iat
|
||||
claims["userId"] = userId
|
||||
token := jwt.New(jwt.SigningMethodHS256)
|
||||
token.Claims = claims
|
||||
return token.SignedString([]byte(secretKey))
|
||||
}
|
||||
|
||||
func (l *UserLoginLogic) UserLogin(req *types.RequestUserLogin) (resp *types.Response) {
|
||||
// 必须返回response, 前端需要的是内部约定的Code码, 处理相关的逻辑. 例子(eg): resp.Set(501, "error")
|
||||
resp = &types.Response{}
|
||||
|
||||
userModel, err := model.NewFsUserModel(l.svcCtx.MysqlConn).FindOneByEmail(l.ctx, req.Name)
|
||||
|
||||
// log.Printf("%t %t %v", err, model.ErrNotFound, err == model.ErrNotFound)
|
||||
if err == model.ErrNotFound {
|
||||
logx.Error(err)
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"fusenapi/home-user-auth/internal/svc"
|
||||
"fusenapi/home-user-auth/internal/types"
|
||||
"fusenapi/model"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
@@ -26,16 +25,18 @@ func NewUserSaveBasicInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UserSaveBasicInfoLogic) UserSaveBasicInfo(req *types.RequestBasicInfoForm, userinfo *auth.UserInfo) (resp *types.Response) {
|
||||
func (l *UserSaveBasicInfoLogic) UserSaveBasicInfo(req *types.RequestBasicInfoForm) (resp *types.Response) {
|
||||
// 必须返回response, 前端需要的是内部约定的Code码, 处理相关的逻辑. 例子(eg): resp.Set(501, "error")
|
||||
resp = &types.Response{}
|
||||
// logx.Info(req)
|
||||
if userinfo.UserId == 0 {
|
||||
resp.SetStatusWithMessage(basic.DefaultError, "user is not exists")
|
||||
return resp
|
||||
}
|
||||
// if userinfo.UserId == 0 {
|
||||
// resp.SetStatusWithMessage(basic.DefaultError, "user is not exists")
|
||||
// return resp
|
||||
// }
|
||||
|
||||
fsUserModel, err := model.NewFsUserModel(l.svcCtx.MysqlConn).FindOne(l.ctx, userinfo.UserId)
|
||||
userid := l.ctx.Value("userid").(int64)
|
||||
|
||||
fsUserModel, err := model.NewFsUserModel(l.svcCtx.MysqlConn).FindOne(l.ctx, userid)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user