lejianwen 1 год назад
Родитель
Сommit
1c5cd3ae62
4 измененных файлов с 18 добавлено и 20 удалено
  1. 9 20
      http/controller/admin/userToken.go
  2. 4 0
      http/request/admin/user.go
  3. 1 0
      http/router/admin.go
  4. 4 0
      service/user.go

+ 9 - 20
http/controller/admin/userToken.go

@@ -88,37 +88,26 @@ func (ct *UserToken) Delete(c *gin.Context) {
88 88
 // @Description 登录凭证批量删除
89 89
 // @Accept  json
90 90
 // @Produce  json
91
-// @Param body body model.UserToken true "登录凭证信息"
91
+// @Param body body admin.UserTokenBatchDeleteForm true "登录凭证信息"
92 92
 // @Success 200 {object} response.Response
93 93
 // @Failure 500 {object} response.Response
94 94
 // @Router /admin/user_token/delete [post]
95 95
 // @Security token
96 96
 func (ct *UserToken) BatchDelete(c *gin.Context) {
97
-	f := &model.UserToken{}
97
+	f := &admin.UserTokenBatchDeleteForm{}
98 98
 	if err := c.ShouldBindJSON(f); err != nil {
99 99
 		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
100 100
 		return
101 101
 	}
102
-	id := f.Id
103
-	errList := global.Validator.ValidVar(c, id, "required,gt=0")
104
-	if len(errList) > 0 {
105
-		response.Fail(c, 101, errList[0])
106
-		return
107
-	}
108
-	l := service.AllService.UserService.TokenInfoById(f.Id)
109
-	u := service.AllService.UserService.CurUser(c)
110
-	if !service.AllService.UserService.IsAdmin(u) && l.UserId != u.Id {
111
-		response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
102
+	ids := f.Ids
103
+	if len(ids) == 0 {
104
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
112 105
 		return
113 106
 	}
114
-	if l.Id > 0 {
115
-		err := service.AllService.UserService.DeleteToken(l)
116
-		if err == nil {
117
-			response.Success(c, nil)
118
-			return
119
-		}
120
-		response.Fail(c, 101, err.Error())
107
+	err := service.AllService.UserService.BatchDeleteUserToken(ids)
108
+	if err == nil {
109
+		response.Success(c, nil)
121 110
 		return
122 111
 	}
123
-	response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
112
+	response.Fail(c, 101, err.Error())
124 113
 }

+ 4 - 0
http/request/admin/user.go

@@ -69,3 +69,7 @@ type RegisterForm struct {
69 69
 	Password        string `json:"password" validate:"required,gte=4,lte=32"`
70 70
 	ConfirmPassword string `json:"confirm_password" validate:"required,gte=4,lte=32"`
71 71
 }
72
+
73
+type UserTokenBatchDeleteForm struct {
74
+	Ids []uint `json:"ids" validate:"required"`
75
+}

+ 1 - 0
http/router/admin.go

@@ -195,6 +195,7 @@ func UserTokenBind(rg *gin.RouterGroup) {
195 195
 	cont := &admin.UserToken{}
196 196
 	aR.GET("/list", cont.List)
197 197
 	aR.POST("/delete", cont.Delete)
198
+	aR.POST("/batchDelete", cont.BatchDelete)
198 199
 }
199 200
 func ConfigBind(rg *gin.RouterGroup) {
200 201
 	aR := rg.Group("/config")

+ 4 - 0
service/user.go

@@ -458,3 +458,7 @@ func (us *UserService) AutoRefreshAccessToken(ut *model.UserToken) {
458 458
 		us.RefreshAccessToken(ut)
459 459
 	}
460 460
 }
461
+
462
+func (us *UserService) BatchDeleteUserToken(ids []uint) error {
463
+	return global.DB.Where("id in ?", ids).Delete(&model.UserToken{}).Error
464
+}