@@ -0,0 +1,355 @@
|
||||
package web_acc
|
||||
|
||||
import (
|
||||
"time"
|
||||
"videoweb/pub/common"
|
||||
"videoweb/pub/common/crypt"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/google"
|
||||
"videoweb/pub/models/mwacc"
|
||||
"videoweb/web/service/srv_acc"
|
||||
"videoweb/web/service/srv_mwacc"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
|
||||
// @Tags 账号
|
||||
// @Summary 账号-列表
|
||||
// @Description 账号-列表
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param param body MwAccListReq true "参数列表"
|
||||
// @Success 200 {object} MwAccListResp "成功"
|
||||
// @Failure 400 {string} string "获取失败的返回结果"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /api/web/acc/list [GET]
|
||||
func AccGetList(c *gin.Context) {
|
||||
|
||||
var req MwAccListReq
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
common.ServerJSON(c, srvdef.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
search := mwacc.MakeSearch(req.KeyWords, req.Status, req.Page)
|
||||
sort := mwacc.MakeSort(req.PageNum, req.PageSize)
|
||||
|
||||
total, data, _ := mwacc.GetAccList(c, search, sort)
|
||||
|
||||
resp := MwAccListResp{
|
||||
TotalCount: total,
|
||||
AccRec: make([]*MwAccRec, 0),
|
||||
}
|
||||
|
||||
for _, v := range data {
|
||||
resp.AccRec = append(resp.AccRec, &MwAccRec{
|
||||
Id: v.Id,
|
||||
UserName: v.Username,
|
||||
Acc: v.Acc,
|
||||
Email: v.Email,
|
||||
RoleId: v.RoleId,
|
||||
RoleName: v.RoleName,
|
||||
// Base32: v.Base32,
|
||||
IsBase32: v.IsBase32,
|
||||
IsEnb: v.IsEnb,
|
||||
FeedBack: v.Feedback,
|
||||
CreatedAt: v.CreatedAt.Unix(),
|
||||
UpdatedAt: v.UpdatedAt.Unix(),
|
||||
LimitIP: v.LimitIP,
|
||||
})
|
||||
}
|
||||
common.ServerJSON(c, srvdef.Success, resp)
|
||||
}
|
||||
|
||||
// @Tags 账号
|
||||
// @Summary 账号-添加
|
||||
// @Description 账号-添加
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param param body MwAccAddReq true "参数列表"
|
||||
// @Success 200 {object} MwAccAddResp "成功"
|
||||
// @Failure 400 {string} string "获取失败的返回结果"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /api/web/acc/add [POST]
|
||||
func AccAdd(c *gin.Context) {
|
||||
var req MwAccAddReq
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
common.ServerJSON(c, srvdef.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
accCount, err := mwacc.AccCountByFilter(c, bson.M{
|
||||
mwacc.FN.MwAcc.Acc: req.Acc,
|
||||
})
|
||||
if accCount > 0 || err != nil {
|
||||
common.ServerJSON(c, srvdef.ErrParamError, "用户已存在")
|
||||
return
|
||||
}
|
||||
|
||||
secret := google.NewGoogleAuth().GetSecret()
|
||||
|
||||
insertDoc := &mwacc.AccInsertDoc{
|
||||
UserName: req.Name,
|
||||
Pwd: crypt.StrToMd5(req.Pwd), //md5V(req.Pwd),
|
||||
Acc: req.Acc,
|
||||
Email: req.Email,
|
||||
RoleId: req.RoleId,
|
||||
Base32: secret,
|
||||
IsBase32: false,
|
||||
IsEnb: req.IsEnb,
|
||||
LimitIP: req.LimitIP,
|
||||
}
|
||||
|
||||
_, _, err = mwacc.AccAdd(c, insertDoc)
|
||||
if err != nil {
|
||||
common.ServerJSON(c, srvdef.Failure, MwAccAddResp{Result: false})
|
||||
return
|
||||
}
|
||||
common.ServerJSON(c, srvdef.Success, MwAccAddResp{Result: true})
|
||||
return
|
||||
}
|
||||
|
||||
// @Tags 账号
|
||||
// @Summary 账号-删除
|
||||
// @Description 账号-删除
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param param body MwAccDelReq true "参数列表"
|
||||
// @Success 200 {object} MwAccDelResp "成功"
|
||||
// @Failure 400 {string} string "获取失败的返回结果"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /api/web/acc/del [POST]
|
||||
func AccDel(c *gin.Context) {
|
||||
|
||||
var req MwAccDelReq
|
||||
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
common.ServerJSON(c, srvdef.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
err := mwacc.DelAccByFilter(c, bson.M{
|
||||
mwacc.FN.MwAcc.Id: req.Id,
|
||||
})
|
||||
// 删除对应账号的token
|
||||
_ = mwacc.DeleteOneToken(c, bson.M{
|
||||
mwacc.FN.MwAccToken.AccId: req.Id,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
common.ServerJSON(c, srvdef.Failure, MwAccDelResp{Result: true})
|
||||
return
|
||||
}
|
||||
common.ServerJSON(c, srvdef.Success, MwAccDelResp{Result: true})
|
||||
return
|
||||
}
|
||||
|
||||
// @Tags 账号
|
||||
// @Summary 账号-获取信息
|
||||
// @Description 账号-获取信息
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param param body MwAccGetInfoReq true "参数列表"
|
||||
// @Success 200 {object} MwAccGetInfoResp "成功"
|
||||
// @Failure 400 {string} string "获取失败的返回结果"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /api/web/acc/getinfo [GET]
|
||||
func AccGetInfo(c *gin.Context) {
|
||||
var req MwAccGetInfoReq
|
||||
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
common.ServerJSON(c, srvdef.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
rest, err := mwacc.FindOneAccByFilter(c, bson.M{
|
||||
mwacc.FN.MwAcc.Id: req.Id,
|
||||
})
|
||||
if err != nil {
|
||||
common.ServerJSON(c, srvdef.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resq := MwAccGetInfoResp{
|
||||
Id: rest.Id,
|
||||
UserName: rest.UserName,
|
||||
Acc: rest.Acc,
|
||||
Pwd: rest.Pwd,
|
||||
Email: rest.Email,
|
||||
RoleId: rest.RoleId,
|
||||
IsEnb: rest.IsEnb,
|
||||
LimitIP: rest.LimitIP,
|
||||
}
|
||||
common.ServerJSON(c, srvdef.Success, resq)
|
||||
return
|
||||
}
|
||||
|
||||
// @Tags 账号
|
||||
// @Summary 账号-更新
|
||||
// @Description 账号-更新
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param param body MwAccUpReq true "参数列表"
|
||||
// @Success 200 {object} MwAccUpResp "成功"
|
||||
// @Failure 400 {string} string "获取失败的返回结果"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /api/web/acc/up [POST]
|
||||
func AccUp(c *gin.Context) {
|
||||
var req MwAccUpReq
|
||||
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
common.ServerJSON(c, srvdef.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
_, err := srv_mwacc.AccUp(c, &srv_mwacc.AccUpDoc{
|
||||
Id: req.Id,
|
||||
UserName: req.UserName,
|
||||
Acc: req.Acc,
|
||||
Email: req.Email,
|
||||
RoleId: req.RoleId,
|
||||
IsEnb: req.IsEnb,
|
||||
LimitIP: req.LimitIP,
|
||||
})
|
||||
if err != nil {
|
||||
common.ServerJSON(c, srvdef.Failure, MwAccUpResp{Result: false})
|
||||
return
|
||||
}
|
||||
common.ServerJSON(c, srvdef.Success, MwAccUpResp{Result: true})
|
||||
return
|
||||
}
|
||||
|
||||
// @Tags 账号
|
||||
// @Summary 账号-获取状态
|
||||
// @Description 账号-获取状态
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param param body MwAccGetStatusReq true "参数列表"
|
||||
// @Success 200 {object} MwAccGetStatusResp "成功"
|
||||
// @Failure 400 {string} string "获取失败的返回结果"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /api/web/acc/getstatus [GET]
|
||||
func AccGetStatus(c *gin.Context) {
|
||||
var req MwAccGetStatusReq
|
||||
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
common.ServerJSON(c, srvdef.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
rest, err := mwacc.FindOneAccByFilter(c, bson.M{
|
||||
mwacc.FN.MwAcc.Id: req.Id,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
common.ServerJSON(c, srvdef.Failure, err)
|
||||
return
|
||||
}
|
||||
|
||||
resp := MwAccGetStatusResp{
|
||||
Id: rest.Id,
|
||||
UserName: rest.UserName,
|
||||
IsEnb: rest.IsEnb,
|
||||
FeedBack: rest.Feedback,
|
||||
}
|
||||
|
||||
common.ServerJSON(c, srvdef.Success, resp)
|
||||
return
|
||||
}
|
||||
|
||||
// @Tags 账号
|
||||
// @Summary 账号-保存状态
|
||||
// @Description 账号-保存状态
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param param body MwAccSaveStatusReq true "参数列表"
|
||||
// @Success 200 {object} MwAccSaveStatusResp "成功"
|
||||
// @Failure 400 {string} string "获取失败的返回结果"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /api/web/acc/savestatus [POST]
|
||||
func AccSaveStatus(c *gin.Context) {
|
||||
|
||||
var req MwAccSaveStatusReq
|
||||
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
common.ServerJSON(c, srvdef.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
err := mwacc.UpOneAccByFilter(c, bson.M{
|
||||
mwacc.FN.MwAcc.Id: req.Id,
|
||||
}, bson.M{
|
||||
mwacc.FN.MwAcc.UserName: req.UserName,
|
||||
mwacc.FN.MwAcc.IsEnb: req.IsEnb,
|
||||
mwacc.FN.MwAcc.Feedback: req.FeedBack,
|
||||
mwacc.FN.MwAcc.UpdatedAt: time.Now(),
|
||||
})
|
||||
if err != nil {
|
||||
common.ServerJSON(c, srvdef.Failure, "")
|
||||
return
|
||||
}
|
||||
// 封禁时,删除token
|
||||
if !req.IsEnb {
|
||||
mwacc.DeleteOneToken(c, bson.M{mwacc.FN.MwAccToken.AccId: req.Id})
|
||||
}
|
||||
|
||||
common.ServerJSON(c, srvdef.Success, MwAccSaveStatusResp{Result: true})
|
||||
return
|
||||
}
|
||||
|
||||
// @Tags 账号
|
||||
// @Summary 账号-获取操作记录
|
||||
// @Description 账号-获取操作记录
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param param body AccOpLogReq true "参数列表"
|
||||
// @Success 200 {object} AccOpLogResp "成功"
|
||||
// @Failure 400 {string} string "获取失败的返回结果"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /api/web/acc/ops [POST]
|
||||
func GetAccOpRecords(ctx *gin.Context) {
|
||||
var req AccOpLogReq
|
||||
|
||||
if err := ctx.ShouldBindJSON(&req); err != nil {
|
||||
common.ServerJSON(ctx, srvdef.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
total, data, err := srv_acc.GetOpLogs(ctx, &req.OpLogSearch)
|
||||
if err != nil {
|
||||
common.ServerJSON(ctx, srvdef.Failure, err.Error())
|
||||
return
|
||||
}
|
||||
resp := &AccOpLogResp{total, data}
|
||||
common.ServerJSON(ctx, srvdef.Success, resp)
|
||||
}
|
||||
|
||||
// @Tags 账号
|
||||
// @Summary 账号-更新密码
|
||||
// @Description 账号-更新密码
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param param body MwAccUpPwdReq true "参数列表"
|
||||
// @Success 200 {object} MwAccUpPwdReq "成功"
|
||||
// @Failure 400 {string} string "获取失败的返回结果"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /api/web/acc/uppwd [POST]
|
||||
func AccUpdatePwd(c *gin.Context) {
|
||||
var req MwAccUpPwdReq
|
||||
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
common.ServerJSON(c, srvdef.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
_, err := srv_mwacc.AccUpPwd(c, &srv_mwacc.AccUpPwdDoc{
|
||||
Id: req.Id,
|
||||
Pwd: req.Pwd,
|
||||
})
|
||||
if err != nil {
|
||||
common.ServerJSON(c, srvdef.Failure, MwAccUpPwdResp{Result: false})
|
||||
return
|
||||
}
|
||||
common.ServerJSON(c, srvdef.Success, MwAccUpPwdResp{Result: true})
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package web_acc
|
||||
|
||||
import (
|
||||
"videoweb/pub/common"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/models/mwacc"
|
||||
"videoweb/web/service/srv_mwacc"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// @Tags 登录
|
||||
// @Summary 登录-登录
|
||||
// @Description 登录-登录
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param param body MainWebLoginReq true "参数列表"
|
||||
// @Success 200 {object} MainWebLoginResp "成功"
|
||||
// @Failure 400 {string} string "获取失败的返回结果"
|
||||
// @Router /api/web/login/acc [POST]
|
||||
func AccLogin(c *gin.Context) {
|
||||
var req MainWebLoginReq
|
||||
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
common.ServerJSON(c, srvdef.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
accInfo, err := srv_mwacc.AccLogin(c, req.Acc, req.Pwd, req.Code)
|
||||
if err != nil || accInfo == nil {
|
||||
common.ServerJSON(c, err.Code, err.Msg)
|
||||
return
|
||||
}
|
||||
|
||||
resp := MainWebLoginResp{}
|
||||
|
||||
if len(accInfo.Qurl) != 0 {
|
||||
resp.Qurl = accInfo.Qurl
|
||||
} else {
|
||||
// 成功保存token
|
||||
if ok, _ := mwacc.SaveToken(c, accInfo.Id, accInfo.Token); ok != true {
|
||||
common.ServerJSON(c, srvdef.GenerateTokenFailed, srvdef.GenerateTokenFailed.Msg())
|
||||
}
|
||||
|
||||
resp.AccId = accInfo.Id
|
||||
resp.Acc = accInfo.Acc
|
||||
resp.RoleId = accInfo.RoleId
|
||||
resp.Token = accInfo.Token
|
||||
}
|
||||
common.ServerJSON(c, srvdef.Success, resp)
|
||||
return
|
||||
}
|
||||
|
||||
// SLogin doc
|
||||
// @Summary 管理员sso登陆
|
||||
// @Description 管理员sso登陆
|
||||
// @Tags web-单点登陆
|
||||
// @Accept mpfd,json
|
||||
// @Produce json,html
|
||||
// @Param name formData string true "账号"
|
||||
// @Param password formData string true "密码"
|
||||
// @Success 200 {string} json "{"msg": "管理员信息""}"
|
||||
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
||||
// @Router /api/web/login/slogin [post]
|
||||
func SLogin(c *gin.Context) {
|
||||
var req MainWebLoginReq
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
common.ServerJSON(c, srvdef.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
accInfo, err := srv_mwacc.AccSLogin(c, req.Acc, req.Pwd)
|
||||
if err != nil || accInfo == nil {
|
||||
common.ServerJSON(c, err.Code, err.Msg)
|
||||
return
|
||||
}
|
||||
resp := MainWebLoginResp{}
|
||||
// 成功保存token
|
||||
if ok, _ := mwacc.SaveToken(c, accInfo.Id, accInfo.Token); ok != true {
|
||||
common.ServerJSON(c, srvdef.GenerateTokenFailed, srvdef.GenerateTokenFailed.Msg())
|
||||
}
|
||||
resp.AccId = accInfo.Id
|
||||
resp.Acc = accInfo.Acc
|
||||
resp.RoleId = accInfo.RoleId
|
||||
resp.Token = accInfo.Token
|
||||
|
||||
common.ServerJSON(c, srvdef.Success, resp)
|
||||
return
|
||||
}
|
||||
|
||||
// @Tags 登录
|
||||
// @Summary 登录-绑定二维码
|
||||
// @Description 登录-绑定二维码
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param param body BindQurlReq true "参数列表"
|
||||
// @Success 200 {object} BindQurlResp "成功"
|
||||
// @Failure 400 {string} string "获取失败的返回结果"
|
||||
// @Router /api/web/login/bind [POST]
|
||||
func BindQurl(c *gin.Context) {
|
||||
var req BindQurlReq
|
||||
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
common.ServerJSON(c, srvdef.ErrParamError, "tone AccLogin arg error "+err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
ok, _ := mwacc.BindAccQurl(c, req.Acc)
|
||||
if !ok {
|
||||
common.ServerJSON(c, srvdef.Failure, BindQurlResp{Result: false})
|
||||
return
|
||||
}
|
||||
common.ServerJSON(c, srvdef.Success, BindQurlResp{Result: true})
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,477 @@
|
||||
package web_acc
|
||||
|
||||
import (
|
||||
"time"
|
||||
"videoweb/pub/pubdef"
|
||||
"videoweb/web/service/srv_acc"
|
||||
)
|
||||
|
||||
/////////////////////////登录//////////////////////////
|
||||
/******************主后台登录***********************/
|
||||
// POST /web/login/acc
|
||||
|
||||
// 请求参数
|
||||
type MainWebLoginReq struct {
|
||||
// 账户
|
||||
Acc string `json:"acc,omitempty"`
|
||||
// 密码
|
||||
Pwd string `json:"pwd,omitempty"`
|
||||
// 验证码
|
||||
Code string `json:"code,omitempty"`
|
||||
}
|
||||
|
||||
// 返回参数
|
||||
type MainWebLoginResp struct {
|
||||
// 账户id
|
||||
AccId int64 `json:"accId"`
|
||||
// 账户
|
||||
Acc string `json:"acc"`
|
||||
// 角色id
|
||||
RoleId int64 `json:"roleId"`
|
||||
// token
|
||||
Token string `json:"token"`
|
||||
// 二维码
|
||||
Qurl []byte `json:"qurl"`
|
||||
}
|
||||
|
||||
/******************绑定二维码***********************/
|
||||
// POST /web/login/bind
|
||||
|
||||
// 请求参数
|
||||
type BindQurlReq struct {
|
||||
//账户
|
||||
Acc string `json:"acc,omitempty"`
|
||||
}
|
||||
|
||||
// 返回参数
|
||||
type BindQurlResp struct {
|
||||
// 是否成功 true:成功 false:未成功
|
||||
Result bool `json:"result,omitempty"`
|
||||
}
|
||||
|
||||
/******************绑定二维码***********************/
|
||||
|
||||
/////////////////////////角色//////////////////////////
|
||||
// GET /web/role/list
|
||||
// 请求参数
|
||||
|
||||
// 角色记录
|
||||
type MwRoleRec struct {
|
||||
// 角色Id
|
||||
Id int64 `json:"id"`
|
||||
// 角色名称
|
||||
Name string `json:"name"`
|
||||
// 描述
|
||||
Desc string `json:"desc"`
|
||||
// 是否启用 false:禁用 true:启用
|
||||
IsEnb bool `json:"isEnb"`
|
||||
// 已有权限的api
|
||||
ApiMenus []string `json:"apiMenus"`
|
||||
// 创建时间
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
// 更新时间
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
// 返回参数
|
||||
type MwRoleListResp struct {
|
||||
// 总共数量
|
||||
TotalCount int64 `json:"totalCount"`
|
||||
// 当前页配置记录
|
||||
RoleRecs []*MwRoleRec `json:"roleRecs"`
|
||||
}
|
||||
|
||||
/******************角色添加***********************/
|
||||
// POST /web/role/add
|
||||
|
||||
// 请求参数
|
||||
type MwRoleAddReq struct {
|
||||
// 名称
|
||||
Name string `json:"name"`
|
||||
// 描述
|
||||
Desc string `json:"desc"`
|
||||
// 状态
|
||||
IsEnb bool `json:"isEnb"`
|
||||
}
|
||||
|
||||
// 返回参数
|
||||
type MwRoleAddResp struct {
|
||||
// 是否成功 true:成功 false:未成功
|
||||
Result bool `json:"result,omitempty"`
|
||||
}
|
||||
|
||||
/******************角色删除***********************/
|
||||
// POST /web/role/del
|
||||
|
||||
// 请求参数
|
||||
type MwRoleDelReq struct {
|
||||
// 角色id
|
||||
Id int64 `json:"id,omitempty"`
|
||||
}
|
||||
|
||||
// 返回参数
|
||||
type MwRoleDelResp struct {
|
||||
// 是否成功 true:成功 false:未成功
|
||||
Result bool `json:"result,omitempty"`
|
||||
}
|
||||
|
||||
/******************角色获取信息***********************/
|
||||
// GET /web/role/getinfo
|
||||
|
||||
// 请求参数
|
||||
type MwRoleGetInfoReq struct {
|
||||
// 角色id
|
||||
Id int64 `form:"id" json:"id,omitempty"`
|
||||
}
|
||||
|
||||
// 返回参数
|
||||
type MwRoleGetInfoResp struct {
|
||||
RoleRec *MwRoleRec `json:"roleRec"`
|
||||
}
|
||||
|
||||
/******************角色更新***********************/
|
||||
// POST /web/role/up
|
||||
|
||||
// 请求参数
|
||||
type MwRoleUpReq struct {
|
||||
// 角色id
|
||||
Id int64 `json:"id"`
|
||||
// 名称
|
||||
Name string `json:"name"`
|
||||
// 描述
|
||||
Desc string `json:"desc"`
|
||||
// 状态
|
||||
IsEnb bool `json:"isEnb"`
|
||||
}
|
||||
|
||||
// 返回参数
|
||||
type MwRoleUpResp struct {
|
||||
// 是否成功 true:成功 false:未成功
|
||||
Result bool `json:"result,omitempty"`
|
||||
}
|
||||
|
||||
/******************角色使能***********************/
|
||||
// POST /web/role/enable
|
||||
|
||||
// 请求参数
|
||||
type MwRoleEnableReq struct {
|
||||
// 角色id
|
||||
Id int64 `json:"id"`
|
||||
// 状态
|
||||
IsEnb bool `json:"isEnb"`
|
||||
}
|
||||
|
||||
// 返回参数
|
||||
type MwRoleEnableResp struct {
|
||||
// 是否成功 true:成功 false:未成功
|
||||
Result bool `json:"result,omitempty"`
|
||||
}
|
||||
|
||||
/******************角色下拉***********************/
|
||||
// GET /web/role/drop
|
||||
|
||||
// 请求参数
|
||||
|
||||
type MwRoleDrop struct {
|
||||
// 角色Id
|
||||
Id int64 `json:"id,omitempty"`
|
||||
// 角色名称
|
||||
Name string `json:"name,omitempty"`
|
||||
}
|
||||
|
||||
// 返回参数
|
||||
type MwRoleDropResp struct {
|
||||
// 是否成功 true:成功 false:未成功
|
||||
RoleDrop []*MwRoleDrop `json:"roleDrop"`
|
||||
}
|
||||
|
||||
/******************获取权限***********************/
|
||||
// GET /web/role/getauth
|
||||
|
||||
type Router_Meta struct {
|
||||
//
|
||||
Title string `json:"title"`
|
||||
//
|
||||
Icon string `json:"icon"`
|
||||
//
|
||||
NoCache bool `json:"noCache"`
|
||||
}
|
||||
|
||||
type Router_ApiUrl struct {
|
||||
//
|
||||
Url []string `json:"url,omitempty"`
|
||||
//
|
||||
Desc string `json:"desc,omitempty"`
|
||||
//
|
||||
Status bool `json:"status,omitempty"`
|
||||
//
|
||||
Method []string `json:"method,omitempty"`
|
||||
}
|
||||
|
||||
type Router struct {
|
||||
//
|
||||
Path string `json:"path"`
|
||||
//
|
||||
Component string `json:"component"`
|
||||
//
|
||||
Redirect string `json:"redirect"`
|
||||
//
|
||||
Name string `json:"name"`
|
||||
//
|
||||
IsShow bool `json:"isShow"`
|
||||
//
|
||||
Hidden bool `json:"hidden"`
|
||||
//
|
||||
Meta *Router_Meta `json:"meta"`
|
||||
//
|
||||
Children []*Router `json:"children"`
|
||||
ApiUrl []*Router_ApiUrl `json:"apiUrl"`
|
||||
}
|
||||
|
||||
// 请求参数
|
||||
type MwRoleGetAuthReq struct {
|
||||
// 角色id
|
||||
Id int64 `form:"id" json:"id,omitempty"`
|
||||
}
|
||||
|
||||
// 返回参数
|
||||
type MwRoleGetAuthResp struct {
|
||||
// 角色id
|
||||
Id int64 `json:"id,omitempty"`
|
||||
//
|
||||
Router []*Router `json:"router,omitempty"`
|
||||
}
|
||||
|
||||
/******************更新权限***********************/
|
||||
// POST /web/role/upauth
|
||||
|
||||
// 请求参数
|
||||
type MwRoleUpAuthReq struct {
|
||||
// 角色id
|
||||
Id int64 `json:"id,omitempty"`
|
||||
Router []*Router `json:"router,omitempty"`
|
||||
}
|
||||
|
||||
// 返回参数
|
||||
type MwRoleUpAuthResp struct {
|
||||
// 是否成功 true:成功 false:未成功
|
||||
Result bool `json:"result,omitempty"`
|
||||
}
|
||||
|
||||
/////////////////////////账号//////////////////////////
|
||||
|
||||
type MwAccRec struct {
|
||||
// 账号Id
|
||||
Id int64 `json:"id"`
|
||||
// 用户名
|
||||
UserName string `json:"userName"`
|
||||
// 账号
|
||||
Acc string `json:"acc"`
|
||||
// 邮箱
|
||||
Email string `json:"email"`
|
||||
// 角色Id
|
||||
RoleId int64 `json:"roleId"`
|
||||
// 角色名
|
||||
RoleName string `json:"roleName"`
|
||||
// // 二步签名
|
||||
// Base32 string `json:"base32"`
|
||||
// 是否已签名
|
||||
IsBase32 bool `json:"isBase32"`
|
||||
// 使能
|
||||
IsEnb bool `json:"isEnb"`
|
||||
//禁用原因
|
||||
FeedBack string `json:"feedBack"`
|
||||
// 创建时间
|
||||
CreatedAt int64 `json:"createdAt"`
|
||||
// 更新时间
|
||||
UpdatedAt int64 `json:"updatedAt"`
|
||||
// 允许访问的IP
|
||||
LimitIP []string `json:"limitIP"`
|
||||
}
|
||||
|
||||
/******************账号列表***********************/
|
||||
// GET /web/acc/list
|
||||
|
||||
// 请求参数
|
||||
type MwAccListReq struct {
|
||||
// 搜索条件
|
||||
KeyWords string `json:"keyWords" form:"keyWords"`
|
||||
//状态 1正常 2 禁用
|
||||
Status int64 `json:"status" form:"status"`
|
||||
// 页码
|
||||
pubdef.Page
|
||||
}
|
||||
|
||||
// 返回参数
|
||||
type MwAccListResp struct {
|
||||
// 总共数量
|
||||
TotalCount int64 `json:"totalCount"`
|
||||
// 当前页配置记录
|
||||
AccRec []*MwAccRec `json:"accRec"`
|
||||
}
|
||||
|
||||
/******************账号添加***********************/
|
||||
// POST /web/acc/add
|
||||
|
||||
// 请求参数
|
||||
type MwAccAddReq struct {
|
||||
// 名称
|
||||
Name string `json:"name"`
|
||||
// 密码
|
||||
Pwd string `json:"pwd"`
|
||||
// 账户
|
||||
Acc string `json:"acc"`
|
||||
// 邮箱
|
||||
Email string `json:"email"`
|
||||
// 角色ID
|
||||
RoleId int64 `json:"roleId"`
|
||||
// 使能
|
||||
IsEnb bool `json:"isEnb"`
|
||||
// 允许访问的IP
|
||||
LimitIP []string `json:"limitIP"`
|
||||
}
|
||||
|
||||
type MwAccAddResp struct {
|
||||
// 是否成功 true:成功 false:未成功
|
||||
Result bool `json:"result,omitempty"`
|
||||
}
|
||||
|
||||
/******************账号删除***********************/
|
||||
// POST web/mw/acc/del
|
||||
|
||||
// 请求参数
|
||||
type MwAccDelReq struct {
|
||||
// 账号Id
|
||||
Id int64 `json:"id,omitempty"`
|
||||
}
|
||||
|
||||
// 返回参数
|
||||
type MwAccDelResp struct {
|
||||
// 是否成功 true:成功 false:未成功
|
||||
Result bool `json:"result,omitempty"`
|
||||
}
|
||||
|
||||
/******************账号获取信息***********************/
|
||||
// GET /web/acc/getinfo
|
||||
// 请求参数
|
||||
type MwAccGetInfoReq struct {
|
||||
// 角色id
|
||||
Id int64 `form:"id" json:"id,omitempty"`
|
||||
}
|
||||
|
||||
// 返回参数
|
||||
type MwAccGetInfoResp struct {
|
||||
// 账号Id
|
||||
Id int64 `json:"id"`
|
||||
// 用户名
|
||||
UserName string `json:"userName"`
|
||||
// 账号
|
||||
Acc string `json:"acc"`
|
||||
// 密码
|
||||
Pwd string `json:"pwd"`
|
||||
// 邮箱
|
||||
Email string `json:"email"`
|
||||
// 角色Id
|
||||
RoleId int64 `json:"roleId"`
|
||||
// 使能
|
||||
IsEnb bool `json:"isEnb"`
|
||||
// 允许访问的IP
|
||||
LimitIP []string `json:"limitIP"`
|
||||
}
|
||||
|
||||
/******************角色更新***********************/
|
||||
// POST web/mw/acc/up
|
||||
|
||||
// 请求参数
|
||||
type MwAccUpReq struct {
|
||||
// 账号Id
|
||||
Id int64 `json:"id"`
|
||||
// 用户名
|
||||
UserName string `json:"userName"`
|
||||
// 账号
|
||||
Acc string `json:"acc"`
|
||||
// 密码
|
||||
Pwd string `json:"pwd"`
|
||||
// 邮箱
|
||||
Email string `json:"email"`
|
||||
// 角色Id
|
||||
RoleId int64 `json:"roleId"`
|
||||
// 使能
|
||||
IsEnb bool `json:"isEnb"`
|
||||
// 允许访问的IP
|
||||
LimitIP []string `json:"limitIP"`
|
||||
}
|
||||
|
||||
// 返回参数
|
||||
type MwAccUpResp struct {
|
||||
// 是否成功 true:成功 false:未成功
|
||||
Result bool `json:"result,omitempty"`
|
||||
}
|
||||
|
||||
/******************账号获取状态***********************/
|
||||
// GET web/mw/acc/getstatus
|
||||
|
||||
// 请求参数
|
||||
type MwAccGetStatusReq struct {
|
||||
// 角色id
|
||||
Id int64 `form:"id" json:"id,omitempty"`
|
||||
}
|
||||
|
||||
// 返回参数
|
||||
type MwAccGetStatusResp struct {
|
||||
|
||||
// 账号Id
|
||||
Id int64 `json:"id"`
|
||||
// 用户名
|
||||
UserName string `json:"userName"`
|
||||
// 使能
|
||||
IsEnb bool `json:"isEnb"`
|
||||
//禁用原因
|
||||
FeedBack string `json:"feedBack"`
|
||||
}
|
||||
|
||||
/******************账号保存状态***********************/
|
||||
// POST web/mw/acc/savestatus
|
||||
// 请求参数
|
||||
type MwAccSaveStatusReq struct {
|
||||
// 账号Id
|
||||
Id int64 `json:"id"`
|
||||
// 用户名
|
||||
UserName string `json:"userName"`
|
||||
// 使能
|
||||
IsEnb bool `json:"isEnb"`
|
||||
//禁用原因
|
||||
FeedBack string `json:"feedBack"`
|
||||
}
|
||||
|
||||
// 返回参数
|
||||
type MwAccSaveStatusResp struct {
|
||||
// 是否成功 true:成功 false:未成功
|
||||
Result bool `json:"result,omitempty"`
|
||||
}
|
||||
|
||||
/******************获取账号操作列表***********************/
|
||||
// POST web/acc/ops
|
||||
// 请求参数
|
||||
type AccOpLogReq struct {
|
||||
srv_acc.OpLogSearch
|
||||
}
|
||||
|
||||
// AccOpLogResp 返回参数
|
||||
type AccOpLogResp struct {
|
||||
Total int64 `json:"total" bson:"total"`
|
||||
List []*srv_acc.OpLogInfo `json:"list" bson:"list"`
|
||||
}
|
||||
|
||||
// 修改账号密码
|
||||
type MwAccUpPwdReq struct {
|
||||
// 账号Id
|
||||
Id int64 `json:"id" binding:"required"`
|
||||
// 密码
|
||||
Pwd string `json:"pwd"`
|
||||
}
|
||||
|
||||
type MwAccUpPwdResp struct {
|
||||
// 是否成功 true:成功 false:未成功
|
||||
Result bool `json:"result,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,400 @@
|
||||
package web_acc
|
||||
|
||||
import (
|
||||
"videoweb/pub/common"
|
||||
"videoweb/pub/common/pageopt"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/models/mwacc"
|
||||
"videoweb/pub/pubdef"
|
||||
"videoweb/web/service/srv_mwacc"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
|
||||
// @Tags 角色
|
||||
// @Summary 角色-列表
|
||||
// @Description 角色-列表
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param param body pubdef.Page true "参数列表"
|
||||
// @Success 200 {object} MwRoleListResp "成功"
|
||||
// @Failure 400 {string} string "获取失败的返回结果"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /api/web/role/list [GET]
|
||||
func RoleGetList(c *gin.Context) {
|
||||
var req pubdef.Page
|
||||
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
common.ServerJSON(c, srvdef.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
if req.PageNum <= 0 {
|
||||
req.PageNum = 1
|
||||
}
|
||||
if req.PageSize <= 0 {
|
||||
req.PageSize = 10
|
||||
}
|
||||
|
||||
skip := (req.PageNum - 1) * req.PageSize
|
||||
limit := req.PageSize
|
||||
|
||||
// 获取分页信息
|
||||
var mats []pageopt.Matcher
|
||||
dbRoleRec, err := mwacc.GetRoleList(c, skip, limit, mats...)
|
||||
if err != nil {
|
||||
common.ServerJSON(c, srvdef.Failure, "")
|
||||
return
|
||||
}
|
||||
|
||||
// 获取总条数
|
||||
roleCount, err := mwacc.RoleCountByFilter(c, bson.M{})
|
||||
|
||||
if err != nil {
|
||||
common.ServerJSON(c, srvdef.Failure, "")
|
||||
return
|
||||
}
|
||||
|
||||
webRoleRec := make([]*MwRoleRec, 0)
|
||||
for _, v := range dbRoleRec {
|
||||
webRoleRec = append(webRoleRec, &MwRoleRec{
|
||||
Id: v.Id,
|
||||
Name: v.Name,
|
||||
Desc: v.Desc,
|
||||
IsEnb: v.IsEnb,
|
||||
ApiMenus: v.ApiMenus[:],
|
||||
CreatedAt: v.CreatedAt,
|
||||
UpdatedAt: v.UpdatedAt,
|
||||
})
|
||||
}
|
||||
|
||||
// 返回正确信息
|
||||
common.ServerJSON(c, srvdef.Success, MwRoleListResp{TotalCount: roleCount, RoleRecs: webRoleRec})
|
||||
return
|
||||
}
|
||||
|
||||
// @Tags 角色
|
||||
// @Summary 角色-添加
|
||||
// @Description 角色-添加
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param param body MwRoleAddReq true "参数列表"
|
||||
// @Success 200 {object} MwRoleAddResp "成功"
|
||||
// @Failure 400 {string} string "获取失败的返回结果"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /api/web/role/add [POST]
|
||||
func RoleAdd(c *gin.Context) {
|
||||
var req MwRoleAddReq
|
||||
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
common.ServerJSON(c, srvdef.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
ok, _ := mwacc.RoleAdd(c, req.Name, req.Desc, req.IsEnb)
|
||||
if !ok {
|
||||
common.ServerJSON(c, srvdef.Failure, "")
|
||||
return
|
||||
}
|
||||
// 返回正确信息
|
||||
common.ServerJSON(c, srvdef.Success, MwRoleAddResp{Result: true})
|
||||
return
|
||||
}
|
||||
|
||||
// @Tags 角色
|
||||
// @Summary 角色-删除
|
||||
// @Description 角色-删除
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param param body MwRoleDelReq true "参数列表"
|
||||
// @Success 200 {object} MwRoleDelResp "成功"
|
||||
// @Failure 400 {string} string "获取失败的返回结果"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /api/web/role/del [POST]
|
||||
func RoleDel(c *gin.Context) {
|
||||
var req MwRoleDelReq
|
||||
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
common.ServerJSON(c, srvdef.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
ok, err := srv_mwacc.RoleDel(c, req.Id)
|
||||
if !ok {
|
||||
common.ServerJSON(c, srvdef.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
common.ServerJSON(c, srvdef.Success, MwRoleDelResp{Result: true})
|
||||
return
|
||||
}
|
||||
|
||||
// @Tags 角色
|
||||
// @Summary 角色-获取信息
|
||||
// @Description 角色-获取信息
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param param body MwRoleGetInfoReq true "参数列表"
|
||||
// @Success 200 {object} MwRoleGetInfoResp "成功"
|
||||
// @Failure 400 {string} string "获取失败的返回结果"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /api/web/role/getinfo [GET]
|
||||
func RoleGetInfo(c *gin.Context) {
|
||||
|
||||
var req MwRoleGetInfoReq
|
||||
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
common.ServerJSON(c, srvdef.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
roleInfo, err := srv_mwacc.RoleGetInfo(c, req.Id)
|
||||
|
||||
if err != nil {
|
||||
common.ServerJSON(c, srvdef.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resq := &MwRoleGetInfoResp{
|
||||
RoleRec: &MwRoleRec{
|
||||
Id: roleInfo.Id,
|
||||
Name: roleInfo.Name,
|
||||
Desc: roleInfo.Desc,
|
||||
IsEnb: roleInfo.IsEnb,
|
||||
ApiMenus: roleInfo.ApiMenus[:],
|
||||
CreatedAt: roleInfo.CreatedAt,
|
||||
UpdatedAt: roleInfo.UpdatedAt,
|
||||
},
|
||||
}
|
||||
common.ServerJSON(c, srvdef.Success, resq)
|
||||
return
|
||||
}
|
||||
|
||||
// @Tags 角色
|
||||
// @Summary 角色-更新
|
||||
// @Description 角色-更新
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param param body MwRoleUpReq true "参数列表"
|
||||
// @Success 200 {object} MwRoleUpResp "成功"
|
||||
// @Failure 400 {string} string "获取失败的返回结果"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /api/web/role/up [POST]
|
||||
func RoleUp(c *gin.Context) {
|
||||
|
||||
var req MwRoleUpReq
|
||||
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
common.ServerJSON(c, srvdef.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// RoleUp
|
||||
_, err := srv_mwacc.RoleUp(c, req.Id, req.Name, req.Desc, req.IsEnb)
|
||||
if err != nil {
|
||||
common.ServerJSON(c, srvdef.Failure, MwRoleUpResp{Result: false})
|
||||
return
|
||||
}
|
||||
|
||||
common.ServerJSON(c, srvdef.Success, MwRoleUpResp{Result: true})
|
||||
return
|
||||
}
|
||||
|
||||
// @Tags 角色
|
||||
// @Summary 角色-使能
|
||||
// @Description 角色-使能
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param param body MwRoleEnableReq true "参数列表"
|
||||
// @Success 200 {object} MwRoleEnableResp "成功"
|
||||
// @Failure 400 {string} string "获取失败的返回结果"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /api/web/role/enable [POST]
|
||||
func RoleEnable(c *gin.Context) {
|
||||
|
||||
var req MwRoleEnableReq
|
||||
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
common.ServerJSON(c, srvdef.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
_, err := srv_mwacc.RoleEnable(c, req.Id, req.IsEnb)
|
||||
if err != nil {
|
||||
common.ServerJSON(c, err.Code, err.Msg)
|
||||
return
|
||||
}
|
||||
common.ServerJSON(c, srvdef.Success, MwRoleEnableResp{Result: true})
|
||||
return
|
||||
}
|
||||
|
||||
// @Tags 角色
|
||||
// @Summary 角色-下拉列表
|
||||
// @Description 角色-下拉列表
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} MwRoleDropResp "成功"
|
||||
// @Failure 400 {string} string "获取失败的返回结果"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /api/web/role/drop [POST]
|
||||
func RoleGetDrop(c *gin.Context) {
|
||||
data, _ := mwacc.RoleDrop(c)
|
||||
|
||||
roleDropArr := make([]*MwRoleDrop, 0)
|
||||
for _, v := range data {
|
||||
roleDropArr = append(roleDropArr, &MwRoleDrop{Id: v.Id, Name: v.Name})
|
||||
}
|
||||
common.ServerJSON(c, srvdef.Success, MwRoleDropResp{RoleDrop: roleDropArr})
|
||||
return
|
||||
}
|
||||
|
||||
func DbRouterToWebRouter(dbRouter *mwacc.Router) (webRouter *Router) {
|
||||
if dbRouter == nil {
|
||||
return
|
||||
}
|
||||
|
||||
webRouter = &Router{
|
||||
Path: dbRouter.Path,
|
||||
Component: dbRouter.Component,
|
||||
Redirect: dbRouter.Redirect,
|
||||
Name: dbRouter.Name,
|
||||
IsShow: dbRouter.IsShow,
|
||||
Hidden: dbRouter.Hidden,
|
||||
Meta: &Router_Meta{
|
||||
Title: dbRouter.Meta.Title,
|
||||
Icon: dbRouter.Meta.Icon,
|
||||
NoCache: dbRouter.Meta.NoCache,
|
||||
},
|
||||
Children: make([]*Router, 0),
|
||||
ApiUrl: make([]*Router_ApiUrl, 0),
|
||||
}
|
||||
for _, v := range dbRouter.Children {
|
||||
webRouter.Children = append(webRouter.Children, DbRouterToWebRouter(&v))
|
||||
}
|
||||
for _, v := range dbRouter.ApiUrl {
|
||||
webRouter.ApiUrl = append(webRouter.ApiUrl, &Router_ApiUrl{
|
||||
Url: v.Url[:],
|
||||
Desc: v.Desc,
|
||||
Status: v.Status,
|
||||
Method: v.Method[:],
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// @Tags 角色
|
||||
// @Summary 角色-获取权限
|
||||
// @Description 角色-获取权限
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param param body MwRoleGetAuthReq true "参数列表"
|
||||
// @Success 200 {object} MwRoleGetAuthResp "成功"
|
||||
// @Failure 400 {string} string "获取失败的返回结果"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /api/web/role/getauth [GET]
|
||||
func RoleGetAuth(c *gin.Context) {
|
||||
var req MwRoleGetAuthReq
|
||||
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
common.ServerJSON(c, srvdef.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
roleInfo, err := srv_mwacc.RoleGetInfo(c, req.Id)
|
||||
if err != nil {
|
||||
common.ServerJSON(c, srvdef.Failure, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if roleInfo == nil {
|
||||
common.ServerJSON(c, srvdef.Failure, "没找到角色")
|
||||
return
|
||||
}
|
||||
|
||||
if roleInfo.Id == 0 {
|
||||
common.ServerJSON(c, srvdef.Failure, "没找到角色2")
|
||||
return
|
||||
}
|
||||
|
||||
resq := &MwRoleGetAuthResp{
|
||||
Id: req.Id,
|
||||
Router: make([]*Router, 0),
|
||||
}
|
||||
|
||||
for _, v := range roleInfo.Router {
|
||||
|
||||
resq.Router = append(resq.Router, DbRouterToWebRouter(&v))
|
||||
}
|
||||
|
||||
common.ServerJSON(c, srvdef.Success, resq)
|
||||
return
|
||||
}
|
||||
|
||||
// 网站Router转数据库Router
|
||||
func WebRouterToDbRouter(webRouter *Router) (dbRouter *mwacc.Router) {
|
||||
|
||||
if webRouter == nil {
|
||||
return
|
||||
}
|
||||
|
||||
dbRouter = &mwacc.Router{
|
||||
Path: webRouter.Path,
|
||||
Component: webRouter.Component,
|
||||
Redirect: webRouter.Redirect,
|
||||
Name: webRouter.Name,
|
||||
IsShow: webRouter.IsShow,
|
||||
Hidden: webRouter.Hidden,
|
||||
Meta: mwacc.Meta{
|
||||
Title: webRouter.Meta.Title,
|
||||
Icon: webRouter.Meta.Icon,
|
||||
NoCache: webRouter.Meta.NoCache,
|
||||
},
|
||||
Children: make([]mwacc.Router, 0),
|
||||
ApiUrl: make([]mwacc.Apiurl, 0),
|
||||
}
|
||||
for _, v := range webRouter.Children {
|
||||
dbRouter.Children = append(dbRouter.Children, *WebRouterToDbRouter(v))
|
||||
}
|
||||
for _, v := range webRouter.ApiUrl {
|
||||
dbRouter.ApiUrl = append(dbRouter.ApiUrl, mwacc.Apiurl{
|
||||
Url: v.Url[:],
|
||||
Desc: v.Desc,
|
||||
Status: v.Status,
|
||||
Method: v.Method[:],
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// @Tags 角色
|
||||
// @Summary 角色-更新权限
|
||||
// @Description 角色-更新权限
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param param body MwRoleUpAuthReq true "参数列表"
|
||||
// @Success 200 {object} MwRoleUpAuthResp "成功"
|
||||
// @Failure 400 {string} string "获取失败的返回结果"
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /api/web/role/upauth [GET]
|
||||
func RoleUpAuth(c *gin.Context) {
|
||||
|
||||
var req MwRoleUpAuthReq
|
||||
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
common.ServerJSON(c, srvdef.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
dataSave := make([]*mwacc.Router, 0)
|
||||
for _, v := range req.Router {
|
||||
dataSave = append(dataSave, WebRouterToDbRouter(v))
|
||||
}
|
||||
|
||||
_, err := srv_mwacc.UpAuth(c, req.Id, dataSave)
|
||||
if err != nil {
|
||||
common.ServerJSON(c, srvdef.Failure, MwRoleUpAuthResp{Result: false})
|
||||
return
|
||||
}
|
||||
|
||||
// auth.ClearRoleMap()
|
||||
common.ServerJSON(c, srvdef.Success, MwRoleUpAuthResp{Result: true})
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user