-
Notifications
You must be signed in to change notification settings - Fork 17
/
set_user_enable.go
41 lines (38 loc) · 1.3 KB
/
set_user_enable.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
* @Author: SpenserCai
* @Date: 2023-10-19 14:18:07
* @version:
* @LastEditors: SpenserCai
* @LastEditTime: 2023-10-19 14:21:03
* @Description: file content
*/
package business
import (
"strings"
"github.com/SpenserCai/sd-webui-discord/api/gen/models"
ServiceOperations "github.com/SpenserCai/sd-webui-discord/api/gen/restapi/operations/admin"
"github.com/SpenserCai/sd-webui-discord/global"
DbotUser "github.com/SpenserCai/sd-webui-discord/user"
"github.com/go-openapi/runtime/middleware"
)
func (b BusinessBase) SetSetUserEnableHandler() {
global.ApiService.AdminSetUserEnableHandler = ServiceOperations.SetUserEnableHandlerFunc(func(params ServiceOperations.SetUserEnableParams, principal interface{}) middleware.Responder {
if !strings.Contains(principal.(DbotUser.UserInfo).Roles, "admin") {
return ServiceOperations.NewSetUserEnableOK().WithPayload(&models.BaseResponse{
Code: -1,
Message: "permission denied",
})
}
err := global.UserCenterSvc.SetUserEnable(params.Body.UserID, params.Body.IsEnable)
if err != nil {
return ServiceOperations.NewSetUserEnableOK().WithPayload(&models.BaseResponse{
Code: -1,
Message: err.Error(),
})
}
return ServiceOperations.NewSetUserEnableOK().WithPayload(&models.BaseResponse{
Code: 0,
Message: "success",
})
})
}