From a80a6ad2766f64589db760eabe7aa5db6152bd6c Mon Sep 17 00:00:00 2001 From: qianqianzyk <3265569512@qq.com> Date: Wed, 4 Sep 2024 15:14:30 +0800 Subject: [PATCH] =?UTF-8?q?feat(admin=5Fcontroller):=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=91=98=E5=8F=AF=E4=BB=A5=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=AD=A3=E6=96=B9=E7=BB=9F=E4=B8=80=E7=BB=91?= =?UTF-8?q?=E5=AE=9A=E7=8A=B6=E6=80=81=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/adminController/admin.go | 24 ++++++++++++++++++++++ app/services/adminServices/adminService.go | 23 +++++++++++++++++++++ config/router/adminRouter.go | 1 + 3 files changed, 48 insertions(+) create mode 100644 app/services/adminServices/adminService.go diff --git a/app/controllers/adminController/admin.go b/app/controllers/adminController/admin.go index 5395c54..7c18b00 100644 --- a/app/controllers/adminController/admin.go +++ b/app/controllers/adminController/admin.go @@ -4,10 +4,15 @@ import ( "github.com/gin-gonic/gin" "wejh-go/app/apiException" "wejh-go/app/models" + "wejh-go/app/services/adminServices" "wejh-go/app/services/sessionServices" "wejh-go/app/utils" ) +type GetUserBindStatusData struct { + StudentID string `form:"student_id"` +} + func CheckAdmin(c *gin.Context) { user, err := sessionServices.GetUserSession(c) if err != nil { @@ -20,3 +25,22 @@ func CheckAdmin(c *gin.Context) { } utils.JsonSuccessResponse(c, nil) } + +func GetUserBindStatus(c *gin.Context) { + var data GetUserBindStatusData + err := c.ShouldBindQuery(&data) + if err != nil { + _ = c.AbortWithError(200, apiException.ParamError) + return + } + zfStatus, ouathStatus, err := adminServices.GetBindStatus(data.StudentID) + if err != nil { + _ = c.AbortWithError(200, apiException.ServerError) + return + } + response := gin.H{ + "zf_status": zfStatus, + "oauth_status": ouathStatus, + } + utils.JsonSuccessResponse(c, response) +} diff --git a/app/services/adminServices/adminService.go b/app/services/adminServices/adminService.go new file mode 100644 index 0000000..6d4d91e --- /dev/null +++ b/app/services/adminServices/adminService.go @@ -0,0 +1,23 @@ +package adminServices + +import ( + "wejh-go/app/models" + "wejh-go/config/database" +) + +func GetBindStatus(studentID string) (zfStatus, ouathStatus bool, err error) { + var user models.User + zfStatus = false + ouathStatus = false + result := database.DB.Model(models.User{}).Where("student_id = ?", studentID).First(&user) + if result.Error != nil { + return zfStatus, ouathStatus, result.Error + } + if user.ZFPassword != "" { + zfStatus = true + } + if user.OauthPassword != "" { + ouathStatus = true + } + return zfStatus, ouathStatus, nil +} diff --git a/config/router/adminRouter.go b/config/router/adminRouter.go index 17e9e3a..21da6a9 100755 --- a/config/router/adminRouter.go +++ b/config/router/adminRouter.go @@ -43,6 +43,7 @@ func adminRouterInit(r *gin.RouterGroup) { user := admin.Group("/user") { user.POST("/create", adminController.CreateAdminAccount) + user.GET("/status", adminController.GetUserBindStatus) } }