Initial commit
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,356 @@
|
||||
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,
|
||||
Pwd: v.Pwd,
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user