🎨
This commit is contained in:
@@ -84,22 +84,25 @@ func (ClientApi) List(c *gin.Context) {
|
||||
}
|
||||
|
||||
for i, v := range data {
|
||||
// 获取客户端链接信息
|
||||
peer, err := component.Wireguard().GetClientByPublicKey(v.Keys.PublicKey)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
var ipAllocation string
|
||||
for _, iaip := range peer.AllowedIPs {
|
||||
ipAllocation += iaip.String() + ","
|
||||
}
|
||||
data[i].DataTraffic = &vo.DataTraffic{
|
||||
Online: time.Since(peer.LastHandshakeTime).Minutes() < 3,
|
||||
ReceiveBytes: utils.FlowCalculation().Parse(peer.TransmitBytes),
|
||||
TransmitBytes: utils.FlowCalculation().Parse(peer.ReceiveBytes),
|
||||
ConnectEndpoint: ipAllocation,
|
||||
LastHandAt: peer.LastHandshakeTime.Format("2006-01-02 15:04:05"),
|
||||
if v.Keys != nil {
|
||||
// 获取客户端链接信息
|
||||
peer, err := component.Wireguard().GetClientByPublicKey(v.Keys.PublicKey)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
var ipAllocation string
|
||||
for _, iaip := range peer.AllowedIPs {
|
||||
ipAllocation += iaip.String() + ","
|
||||
}
|
||||
data[i].DataTraffic = &vo.DataTraffic{
|
||||
Online: time.Since(peer.LastHandshakeTime).Minutes() < 3,
|
||||
ReceiveBytes: utils.FlowCalculation().Parse(peer.TransmitBytes),
|
||||
TransmitBytes: utils.FlowCalculation().Parse(peer.ReceiveBytes),
|
||||
ConnectEndpoint: ipAllocation,
|
||||
LastHandAt: peer.LastHandshakeTime.Format("2006-01-02 15:04:05"),
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
response.R(c).Paginate(data, total, p.Current, p.Size)
|
||||
|
@@ -10,6 +10,7 @@ import (
|
||||
"wireguard-ui/component"
|
||||
"wireguard-ui/http/param"
|
||||
"wireguard-ui/http/response"
|
||||
"wireguard-ui/http/vo"
|
||||
"wireguard-ui/service"
|
||||
"wireguard-ui/utils"
|
||||
)
|
||||
@@ -89,3 +90,22 @@ func (LoginApi) Login(c *gin.Context) {
|
||||
"expireAt": expireAt,
|
||||
})
|
||||
}
|
||||
|
||||
// Logout
|
||||
// @description: 退出登陆
|
||||
// @receiver LoginApi
|
||||
// @param c
|
||||
func (LoginApi) Logout(c *gin.Context) {
|
||||
loginUser, ok := c.Get("user")
|
||||
if !ok {
|
||||
response.R(c).AuthorizationFailed("未登陆")
|
||||
return
|
||||
}
|
||||
|
||||
if err := component.JWT().Logout(loginUser.(*vo.User).Id); err != nil {
|
||||
response.R(c).FailedWithError("退出登陆失败")
|
||||
return
|
||||
}
|
||||
|
||||
response.R(c).OK()
|
||||
}
|
||||
|
@@ -4,7 +4,9 @@ import (
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
"gitee.ltd/lxh/logger/log"
|
||||
"github.com/gin-gonic/gin"
|
||||
"strings"
|
||||
"wireguard-ui/global/constant"
|
||||
"wireguard-ui/http/param"
|
||||
"wireguard-ui/http/response"
|
||||
@@ -50,7 +52,7 @@ func (UserApi) SaveUser(c *gin.Context) {
|
||||
response.R(c).FailedWithError(errors.New("账号长度在2-20位"))
|
||||
return
|
||||
}
|
||||
if len(p.Password) < 8 || len(p.Password) > 32 {
|
||||
if (len(p.Password) < 8 || len(p.Password) > 32) && p.Password != "" {
|
||||
response.R(c).FailedWithError(errors.New("密码长度在8-32位"))
|
||||
return
|
||||
}
|
||||
@@ -67,6 +69,25 @@ func (UserApi) SaveUser(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
if strings.HasPrefix(p.Avatar, "data:image/png;base64,") {
|
||||
avatar := strings.Replace(p.Avatar, "data:image/png;base64,", "", -1)
|
||||
avatarByte, err := base64.StdEncoding.DecodeString(avatar)
|
||||
if err != nil {
|
||||
log.Errorf("反解析头像失败: %v", err.Error())
|
||||
response.R(c).FailedWithError("上传头像失败")
|
||||
return
|
||||
}
|
||||
|
||||
file, err := utils.FileSystem().UploadFile(avatarByte, ".png")
|
||||
if err != nil {
|
||||
log.Errorf("上传头像失败: %v", err.Error())
|
||||
response.R(c).FailedWithError("上传头像失败")
|
||||
return
|
||||
}
|
||||
|
||||
p.Avatar = file
|
||||
}
|
||||
|
||||
userEnt := &model.User{
|
||||
Base: model.Base{
|
||||
Id: p.Id,
|
||||
|
Reference in New Issue
Block a user