package controller import ( "fmt" "github.com/gin-gonic/gin" "iot_manager_service/app/user/model" "iot_manager_service/app/user/service" "iot_manager_service/util/cache" "iot_manager_service/util/common" "iot_manager_service/util/token" "net/http" ) var UserController = new(user) type user struct{} func (u *user) Login(c *gin.Context) { loginUser := model.LoginUser{} if err := c.ShouldBindJSON(&loginUser); err != nil { c.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil)) return } info := service.UserService.Login(loginUser.Account, loginUser.PassWord) c.JSON(http.StatusOK, info) } func (u *user) GetPublicKey(c *gin.Context) { key := service.UserService.GetPublicKey() c.JSON(http.StatusOK, key) } func (u *user) GetDeptUsers(c *gin.Context) { depts := model.ReqDepts{} err := c.ShouldBindJSON(&depts) if err != nil { c.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil)) return } users := service.UserService.GetDeptUsers(depts.Depts) c.JSON(http.StatusOK, users) } func (u *user) Logout(c *gin.Context) { header := c.GetHeader("Authorization") claims, _ := token.JwtClaims.ParseJwtToken(header) err := cache.DeleteToken(claims.ID) if err != nil { c.JSON(http.StatusOK, common.ParamsInvalidResponse(err.Error(), nil)) return } c.JSON(http.StatusOK, common.SuccessResponse("退出成功", nil)) } func (u *user) GetUser(c *gin.Context) { fmt.Println("demo。。。") }