重置密码
This commit is contained in:
@@ -36,7 +36,7 @@ func (l *UserEmailConfirmationLogic) UserEmailConfirmation(req *types.RequestEma
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
|
||||
token, err := l.svcCtx.TokenManger.Decrypt(req.Token)
|
||||
token, err := l.svcCtx.RegisterTokenManger.Decrypt(req.Token)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeOAuthRegisterTokenErr)
|
||||
|
||||
@@ -47,7 +47,7 @@ func (l *UserEmailRegisterLogic) UserEmailRegister(req *types.RequestEmailRegist
|
||||
return resp.SetStatus(basic.CodeOAuthEmailErr)
|
||||
}
|
||||
|
||||
token, err := l.svcCtx.TokenManger.Decrypt(req.RegisterToken)
|
||||
token, err := l.svcCtx.RegisterTokenManger.Decrypt(req.RegisterToken)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeOAuthRegisterTokenErr)
|
||||
@@ -59,10 +59,10 @@ func (l *UserEmailRegisterLogic) UserEmailRegister(req *types.RequestEmailRegist
|
||||
|
||||
// 确认email 重新序列化
|
||||
token.Email = req.Email
|
||||
token.WId = req.Wid
|
||||
token.Wid = req.Wid
|
||||
token.GuestId = req.GuestId
|
||||
|
||||
clurl, err := l.svcCtx.TokenManger.Generate(token)
|
||||
clurl, err := l.svcCtx.RegisterTokenManger.Generate(token)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeOAuthRegisterTokenErr)
|
||||
|
||||
@@ -114,7 +114,7 @@ func (l *UserGoogleLoginLogic) UserGoogleLogin(req *types.RequestGoogleLogin, us
|
||||
}
|
||||
|
||||
l.isRegistered = false
|
||||
token, err := l.svcCtx.TokenManger.Encrypt(l.registerInfo)
|
||||
token, err := l.svcCtx.RegisterTokenManger.Encrypt(l.registerInfo)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeOAuthRegisterTokenErr)
|
||||
|
||||
43
server/auth/internal/logic/userresetpasswordlogic.go
Normal file
43
server/auth/internal/logic/userresetpasswordlogic.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/auth/internal/svc"
|
||||
"fusenapi/server/auth/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UserResetPasswordLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUserResetPasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserResetPasswordLogic {
|
||||
return &UserResetPasswordLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// 处理进入前逻辑w,r
|
||||
// func (l *UserResetPasswordLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||
// }
|
||||
|
||||
func (l *UserResetPasswordLogic) UserResetPassword(req *types.RequestUserLogin, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
||||
|
||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||
// func (l *UserResetPasswordLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
// }
|
||||
65
server/auth/internal/logic/userresettokenlogic.go
Normal file
65
server/auth/internal/logic/userresettokenlogic.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"time"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/auth/internal/svc"
|
||||
"fusenapi/server/auth/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UserResetTokenLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUserResetTokenLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserResetTokenLogic {
|
||||
return &UserResetTokenLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// 处理进入前逻辑w,r
|
||||
// func (l *UserResetTokenLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||
// }
|
||||
|
||||
func (l *UserResetTokenLogic) UserResetToken(req *types.RequestUserResetToken, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
if !userinfo.IsUser() {
|
||||
return resp.SetStatus(basic.CodeUnAuth)
|
||||
}
|
||||
|
||||
user, err := l.svcCtx.AllModels.FsUser.FindUserById(context.TODO(), userinfo.UserId)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeRequestParamsErr, err.Error())
|
||||
}
|
||||
|
||||
token := &auth.ResetToken{
|
||||
// 操作的类型, 验证的token 必须要继承这个
|
||||
OperateType: auth.OpTypeResetToken,
|
||||
UserId: uint64(userinfo.UserId),
|
||||
Wid: req.Wid,
|
||||
Email: *user.Email,
|
||||
Password: *user.PasswordHash,
|
||||
CreateAt: time.Now(),
|
||||
}
|
||||
|
||||
l.svcCtx.ResetTokenManger.Encrypt(token)
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
||||
|
||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||
// func (l *UserResetTokenLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
// }
|
||||
Reference in New Issue
Block a user