mirror of
https://github.com/lejianwen/rustdesk-api.git
synced 2025-11-29 16:43:17 +00:00
111 lines
2.8 KiB
Go
111 lines
2.8 KiB
Go
package admin
|
|
|
|
import (
|
|
"Gwen/global"
|
|
"Gwen/http/request/admin"
|
|
"Gwen/http/response"
|
|
"Gwen/model"
|
|
"Gwen/service"
|
|
"github.com/gin-gonic/gin"
|
|
"gorm.io/gorm"
|
|
"strconv"
|
|
)
|
|
|
|
type LoginLog struct {
|
|
}
|
|
|
|
// Detail 登录日志
|
|
// @Tags 登录日志
|
|
// @Summary 登录日志详情
|
|
// @Description 登录日志详情
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param id path int true "ID"
|
|
// @Success 200 {object} response.Response{data=model.LoginLog}
|
|
// @Failure 500 {object} response.Response
|
|
// @Router /admin/loginLog/detail/{id} [get]
|
|
// @Security token
|
|
func (ct *LoginLog) Detail(c *gin.Context) {
|
|
id := c.Param("id")
|
|
iid, _ := strconv.Atoi(id)
|
|
u := service.AllService.LoginLogService.InfoById(uint(iid))
|
|
if u.Id > 0 {
|
|
response.Success(c, u)
|
|
return
|
|
}
|
|
response.Fail(c, 101, "信息不存在")
|
|
return
|
|
}
|
|
|
|
// List 列表
|
|
// @Tags 登录日志
|
|
// @Summary 登录日志列表
|
|
// @Description 登录日志列表
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param page query int false "页码"
|
|
// @Param page_size query int false "页大小"
|
|
// @Param user_id query int false "用户ID"
|
|
// @Success 200 {object} response.Response{data=model.LoginLogList}
|
|
// @Failure 500 {object} response.Response
|
|
// @Router /admin/loginLog/list [get]
|
|
// @Security token
|
|
func (ct *LoginLog) List(c *gin.Context) {
|
|
query := &admin.LoginLogQuery{}
|
|
if err := c.ShouldBindQuery(query); err != nil {
|
|
response.Fail(c, 101, "参数错误")
|
|
return
|
|
}
|
|
u := service.AllService.UserService.CurUser(c)
|
|
if !service.AllService.UserService.IsAdmin(u) || query.IsMy == 1 {
|
|
query.UserId = int(u.Id)
|
|
}
|
|
res := service.AllService.LoginLogService.List(query.Page, query.PageSize, func(tx *gorm.DB) {
|
|
if query.UserId > 0 {
|
|
tx.Where("user_id = ?", query.UserId)
|
|
}
|
|
})
|
|
response.Success(c, res)
|
|
}
|
|
|
|
// Delete 删除
|
|
// @Tags 登录日志
|
|
// @Summary 登录日志删除
|
|
// @Description 登录日志删除
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param body body model.LoginLog true "登录日志信息"
|
|
// @Success 200 {object} response.Response
|
|
// @Failure 500 {object} response.Response
|
|
// @Router /admin/loginLog/delete [post]
|
|
// @Security token
|
|
func (ct *LoginLog) Delete(c *gin.Context) {
|
|
f := &model.LoginLog{}
|
|
if err := c.ShouldBindJSON(f); err != nil {
|
|
response.Fail(c, 101, "系统错误")
|
|
return
|
|
}
|
|
id := f.Id
|
|
errList := global.Validator.ValidVar(id, "required,gt=0")
|
|
if len(errList) > 0 {
|
|
response.Fail(c, 101, errList[0])
|
|
return
|
|
}
|
|
l := service.AllService.LoginLogService.InfoById(f.Id)
|
|
u := service.AllService.UserService.CurUser(c)
|
|
if !service.AllService.UserService.IsAdmin(u) && l.UserId != u.Id {
|
|
response.Fail(c, 101, "无权限")
|
|
return
|
|
}
|
|
if l.Id > 0 {
|
|
err := service.AllService.LoginLogService.Delete(l)
|
|
if err == nil {
|
|
response.Success(c, nil)
|
|
return
|
|
}
|
|
response.Fail(c, 101, err.Error())
|
|
return
|
|
}
|
|
response.Fail(c, 101, "信息不存在")
|
|
}
|