From c6c7fc48c845879d3475740e2e1e7165990695e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E4=B8=AB=E8=AE=B2=E6=A2=B5?= Date: Tue, 14 Feb 2023 11:23:08 +0800 Subject: [PATCH] fix_content (#150) Co-authored-by: eryajf --- README.md | 7 ------- controller/base_controller.go | 16 ++++++++++++---- logic/base_logic.go | 17 ++++++++++++++--- model/request/base_req.go | 9 +++++++-- routes/base_routes.go | 3 ++- 5 files changed, 35 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index a337ad5..349e473 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,6 @@ - [🔗 文档快链](#-%E6%96%87%E6%A1%A3%E5%BF%AB%E9%93%BE) - [🥰 感谢](#-%E6%84%9F%E8%B0%A2) - [🤗 另外](#-%E5%8F%A6%E5%A4%96) -- [⚡ 加群](#-%E5%8A%A0%E7%BE%A4) - [🤑 捐赠](#-%E6%8D%90%E8%B5%A0) - [📝 使用登记](#-%E4%BD%BF%E7%94%A8%E7%99%BB%E8%AE%B0) - [💎 优秀软件推荐](#-%E4%BC%98%E7%A7%80%E8%BD%AF%E4%BB%B6%E6%8E%A8%E8%8D%90) @@ -96,12 +95,6 @@ - 如果觉得项目不错,麻烦动动小手点个⭐️star⭐️! - 如果你还有其他想法或者需求,欢迎在issue中交流! -- 程序还有很多bug,欢迎各位朋友一起协同共建! - - -## ⚡ 加群 - -如果想要加群交流,可通过搜索 cWN3ZDg4NDgK (base64)添加我的微信,备注 ldap 拉你进群。 ## 🤑 捐赠 diff --git a/controller/base_controller.go b/controller/base_controller.go index ea9c710..b95b76d 100644 --- a/controller/base_controller.go +++ b/controller/base_controller.go @@ -25,10 +25,18 @@ func (m *BaseController) Dashboard(c *gin.Context) { }) } -// GetPasswd 生成加密密码 -func (m *BaseController) GetPasswd(c *gin.Context) { - req := new(request.GetPasswdReq) +// EncryptPasswd 生成加密密码 +func (m *BaseController) EncryptPasswd(c *gin.Context) { + req := new(request.EncryptPasswdReq) Run(c, req, func() (interface{}, interface{}) { - return logic.Base.GetPasswd(c, req) + return logic.Base.EncryptPasswd(c, req) + }) +} + +// DecryptPasswd 密码解密为明文 +func (m *BaseController) DecryptPasswd(c *gin.Context) { + req := new(request.DecryptPasswdReq) + Run(c, req, func() (interface{}, interface{}) { + return logic.Base.DecryptPasswd(c, req) }) } diff --git a/logic/base_logic.go b/logic/base_logic.go index f00aad6..5385205 100644 --- a/logic/base_logic.go +++ b/logic/base_logic.go @@ -136,9 +136,9 @@ func (l BaseLogic) Dashboard(c *gin.Context, req interface{}) (data interface{}, return rst, nil } -// GetPasswd -func (l BaseLogic) GetPasswd(c *gin.Context, req interface{}) (data interface{}, rspError interface{}) { - r, ok := req.(*request.GetPasswdReq) +// EncryptPasswd +func (l BaseLogic) EncryptPasswd(c *gin.Context, req interface{}) (data interface{}, rspError interface{}) { + r, ok := req.(*request.EncryptPasswdReq) if !ok { return nil, ReqAssertErr } @@ -146,3 +146,14 @@ func (l BaseLogic) GetPasswd(c *gin.Context, req interface{}) (data interface{}, return tools.NewGenPasswd(r.Passwd), nil } + +// DecryptPasswd +func (l BaseLogic) DecryptPasswd(c *gin.Context, req interface{}) (data interface{}, rspError interface{}) { + r, ok := req.(*request.DecryptPasswdReq) + if !ok { + return nil, ReqAssertErr + } + _ = c + + return tools.NewParPasswd(r.Passwd), nil +} diff --git a/model/request/base_req.go b/model/request/base_req.go index c2dd52f..1dfe517 100644 --- a/model/request/base_req.go +++ b/model/request/base_req.go @@ -9,7 +9,12 @@ type BaseChangePwdReq struct { type BaseDashboardReq struct { } -// GetPasswdReq -type GetPasswdReq struct { +// EncryptPasswdReq +type EncryptPasswdReq struct { + Passwd string `json:"passwd" form:"passwd" validate:"required"` +} + +// DecryptPasswdReq +type DecryptPasswdReq struct { Passwd string `json:"passwd" form:"passwd" validate:"required"` } diff --git a/routes/base_routes.go b/routes/base_routes.go index 01b4ab7..e87ada9 100644 --- a/routes/base_routes.go +++ b/routes/base_routes.go @@ -12,7 +12,8 @@ func InitBaseRoutes(r *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) gi base := r.Group("/base") { base.GET("ping", controller.Demo) - base.GET("getpasswd", controller.Base.GetPasswd) // 将明文字符串转为MySQL识别的密码 + base.GET("encryptpwd", controller.Base.EncryptPasswd) // 生成加密密码 + base.GET("decryptpwd", controller.Base.DecryptPasswd) // 密码解密为明文 // 登录登出刷新token无需鉴权 base.POST("/login", authMiddleware.LoginHandler) base.POST("/logout", authMiddleware.LogoutHandler)