62 lines
1.7 KiB
Go
62 lines
1.7 KiB
Go
package logic
|
|
|
|
import (
|
|
"fusenapi/utils/auth"
|
|
"fusenapi/utils/basic"
|
|
"net/http"
|
|
|
|
"context"
|
|
|
|
"fusenapi/server/auth/internal/svc"
|
|
"fusenapi/server/auth/internal/types"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
"github.com/zeromicro/go-zero/rest/httpx"
|
|
)
|
|
|
|
type UserResetPasswordHtmlLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
ResetToken string
|
|
}
|
|
|
|
func NewUserResetPasswordHtmlLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserResetPasswordHtmlLogic {
|
|
return &UserResetPasswordHtmlLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
// 处理进入前逻辑w,r
|
|
// func (l *UserResetPasswordHtmlLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
|
// }
|
|
|
|
func (l *UserResetPasswordHtmlLogic) UserResetPasswordHtml(req *types.RequestUserResetHtml, userinfo *auth.UserInfo) (resp *basic.Response) {
|
|
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
|
// userinfo 传入值时, 一定不为null
|
|
|
|
if len(req.ResetToken) <= 16 {
|
|
return resp.SetStatus(basic.CodeOAuthResetTokenDecryptErr)
|
|
}
|
|
|
|
l.ResetToken = req.ResetToken
|
|
|
|
return resp.SetStatus(basic.CodeOK)
|
|
}
|
|
|
|
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
|
func (l *UserResetPasswordHtmlLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
|
|
|
err := tpls.ExecuteTemplate(w, "reset_confirm.tpl", map[string]string{
|
|
"ResetToken": l.ResetToken,
|
|
"ResetPasswordLink": l.svcCtx.Config.MainAddress + "/api/auth/reset/password",
|
|
})
|
|
if err != nil {
|
|
httpx.OkJsonCtx(l.ctx, w, resp.SetStatusWithMessage(basic.CodeTemplateErr, err.Error()))
|
|
} else {
|
|
httpx.Ok(w)
|
|
}
|
|
}
|