Compare commits
No commits in common. "main" and "v1.2.1" have entirely different histories.
@ -3,7 +3,6 @@ package component
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"wireguard-dashboard/client"
|
"wireguard-dashboard/client"
|
||||||
@ -50,8 +49,8 @@ func (CaptchaStore) Get(id string, clear bool) string {
|
|||||||
// @param clear
|
// @param clear
|
||||||
// @return bool
|
// @return bool
|
||||||
func (c CaptchaStore) Verify(id, answer string, clear bool) bool {
|
func (c CaptchaStore) Verify(id, answer string, clear bool) bool {
|
||||||
if os.Getenv("GIN_MODE") != "release" {
|
//if os.Getenv("GIN_MODE") != "release" {
|
||||||
return true
|
// return true
|
||||||
}
|
//}
|
||||||
return strings.ToUpper(answer) == strings.ToUpper(c.Get(id, clear))
|
return strings.ToUpper(answer) == strings.ToUpper(c.Get(id, clear))
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,9 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"gitee.ltd/lxh/logger/log"
|
"gitee.ltd/lxh/logger/log"
|
||||||
"github.com/golang-jwt/jwt/v5"
|
"github.com/golang-jwt/jwt/v5"
|
||||||
"github.com/google/uuid"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"wireguard-dashboard/client"
|
"wireguard-dashboard/client"
|
||||||
"wireguard-dashboard/config"
|
|
||||||
"wireguard-dashboard/constant"
|
"wireguard-dashboard/constant"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -18,7 +16,7 @@ const Secret = "IK8MSs76Pb2VJxleTDadf1Wzu3h9QROLv0XtmnCUErYgBG5wAyjk4cioqFZHNpZG
|
|||||||
|
|
||||||
type JwtClaims struct {
|
type JwtClaims struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
jwt.RegisteredClaims
|
jwt.RegisteredClaims `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func JWT() JwtClaims {
|
func JWT() JwtClaims {
|
||||||
@ -38,12 +36,10 @@ func (j JwtClaims) GenerateToken(userId string) (token string, expireTime *jwt.N
|
|||||||
claims := JwtClaims{
|
claims := JwtClaims{
|
||||||
ID: userId,
|
ID: userId,
|
||||||
RegisteredClaims: jwt.RegisteredClaims{
|
RegisteredClaims: jwt.RegisteredClaims{
|
||||||
Issuer: config.Config.Http.Endpoint, // 颁发站点
|
Subject: "wireguard-dashboard",
|
||||||
Subject: "wg-dashboard",
|
|
||||||
ExpiresAt: expireTime,
|
ExpiresAt: expireTime,
|
||||||
NotBefore: notBefore,
|
NotBefore: notBefore,
|
||||||
IssuedAt: issuedAt,
|
IssuedAt: issuedAt,
|
||||||
ID: uuid.NewString(),
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,5 +2,4 @@ package config
|
|||||||
|
|
||||||
type http struct {
|
type http struct {
|
||||||
Port uint `yaml:"port"`
|
Port uint `yaml:"port"`
|
||||||
Endpoint string `yaml:"endpoint"`
|
|
||||||
}
|
}
|
||||||
|
@ -28,13 +28,6 @@ func Authorization() gin.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果token的颁发者与请求的站点不一致,则直接给它狗日的丢出去
|
|
||||||
if userClaims.Issuer != utils.GetHost(c.Request.Header.Get("Referer")) {
|
|
||||||
utils.GinResponse(c).AuthorizationFailed()
|
|
||||||
c.Abort()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 查询用户
|
// 查询用户
|
||||||
user, err := repository.User().GetUserById(userClaims.ID)
|
user, err := repository.User().GetUserById(userClaims.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
16
utils/url.go
16
utils/url.go
@ -1,16 +0,0 @@
|
|||||||
package utils
|
|
||||||
|
|
||||||
import "net/url"
|
|
||||||
|
|
||||||
// GetHost
|
|
||||||
// @description: 获取指定地址的host
|
|
||||||
// @param addr
|
|
||||||
// @return string
|
|
||||||
func GetHost(addr string) string {
|
|
||||||
uu, err := url.Parse(addr)
|
|
||||||
if err != nil {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
return uu.Host
|
|
||||||
}
|
|
@ -163,15 +163,6 @@ class PureHttp {
|
|||||||
resolve(response);
|
resolve(response);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
// 401直接跳转回去
|
|
||||||
if (error.response.status === 401) {
|
|
||||||
router.replace({
|
|
||||||
path: "/login",
|
|
||||||
query: {
|
|
||||||
redirect: router.currentRoute.value.fullPath
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (error.response === null || error.response === undefined) {
|
if (error.response === null || error.response === undefined) {
|
||||||
message(error.message, { type: "error" });
|
message(error.message, { type: "error" });
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user