42 lines
918 B
Go
42 lines
918 B
Go
package auth
|
|
|
|
import (
|
|
"context"
|
|
|
|
"muyu-apiserver/gateway/internal/svc"
|
|
"muyu-apiserver/gateway/internal/types"
|
|
"muyu-apiserver/pkg/ctxdata"
|
|
"muyu-apiserver/rpc/system/pb"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type ChangePasswordLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewChangePasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChangePasswordLogic {
|
|
return &ChangePasswordLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *ChangePasswordLogic) ChangePassword(req *types.ChangePasswordReq) (resp *types.IdResp, err error) {
|
|
userId := ctxdata.GetUserId(l.ctx)
|
|
|
|
_, err = l.svcCtx.SystemRpc.ChangePassword(l.ctx, &pb.ChangePasswordReq{
|
|
UserId: userId,
|
|
OldPassword: req.OldPassword,
|
|
NewPassword: req.NewPassword,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &types.IdResp{Id: userId}, nil
|
|
}
|