Skip to content

Commit

Permalink
feat(admin_controller):新增管理员可以查询用户正方统一绑定状态的功能
Browse files Browse the repository at this point in the history
  • Loading branch information
qianqianzyk committed Sep 16, 2024
1 parent 473755b commit a80a6ad
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
24 changes: 24 additions & 0 deletions app/controllers/adminController/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
23 changes: 23 additions & 0 deletions app/services/adminServices/adminService.go
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions config/router/adminRouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func adminRouterInit(r *gin.RouterGroup) {
user := admin.Group("/user")
{
user.POST("/create", adminController.CreateAdminAccount)
user.GET("/status", adminController.GetUserBindStatus)
}
}

Expand Down

0 comments on commit a80a6ad

Please sign in to comment.