大面积重构

Response部分

usersController部分

中间件部分
This commit is contained in:
2022-04-06 13:54:48 +08:00
parent 513b563728
commit 0df2aaa82f
13 changed files with 114 additions and 119 deletions

View File

@@ -3,7 +3,6 @@ package common
import (
"drive-linked/config"
"github.com/golang-jwt/jwt/v4"
"strings"
"time"
)
@@ -13,16 +12,8 @@ type JwtClaims struct {
}
//TODO:token解密验证
func ValidateLogin(authorization string) error {
// 取出Bearer后的内容
var tokenString string
if auths := strings.Split(authorization, " "); len(auths) > 1 {
tokenString = auths[1]
} else {
return jwt.ErrInvalidKey
}
token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
func VerifyToken(authorization string) error {
token, err := jwt.Parse(authorization, func(token *jwt.Token) (interface{}, error) {
return []byte(config.Cfg.Security.Jwt.Secret), nil
})

View File

@@ -19,7 +19,7 @@ func TestValidateLogin(t *testing.T) {
config.SetupConfig()
tokenString, _ := NewToken("eigeen")
err := ValidateLogin(tokenString)
err := VerifyToken(tokenString)
if err == nil {
t.Log("验证通过")
} else {