feat: 合并Gin_Vue

This commit is contained in:
TsMask
2023-10-16 17:10:38 +08:00
parent 5289818fd4
commit 40a32cb67f
203 changed files with 19719 additions and 178 deletions

View File

@@ -1,20 +0,0 @@
package crypto
import (
"golang.org/x/crypto/bcrypt"
)
// BcryptHash Bcrypt密码加密
func BcryptHash(originStr string) string {
hash, err := bcrypt.GenerateFromPassword([]byte(originStr), bcrypt.DefaultCost)
if err != nil {
return ""
}
return string(hash)
}
// BcryptCompare Bcrypt密码匹配检查
func BcryptCompare(originStr, hashStr string) bool {
err := bcrypt.CompareHashAndPassword([]byte(hashStr), []byte(originStr))
return err == nil
}

View File

@@ -8,8 +8,11 @@ import (
"net/url"
"os"
"path/filepath"
"strings"
"ems.agt/lib/core/vo"
commonConstants "ems.agt/src/framework/constants/common"
tokenConst "ems.agt/src/framework/constants/token"
"github.com/gorilla/mux"
)
@@ -101,13 +104,27 @@ func SaveUploadedFile(r *http.Request, dst string) error {
/// ==== 登录用户信息, 通过中间件后预置入
// Authorization 解析请求头
func Authorization(r *http.Request) string {
authHeader := r.Header.Get(tokenConst.HEADER_KEY)
if authHeader == "" {
return ""
}
// 拆分 Authorization 请求头,提取 JWT 令牌部分
arr := strings.Split(authHeader, tokenConst.HEADER_PREFIX)
if len(arr) == 2 && arr[1] == "" {
return ""
}
return arr[1]
}
// 定义自定义类型作为键
type ContextKey string
// LoginUser 登录用户信息需要Authorize中间件
func LoginUser(r *http.Request) (vo.LoginUser, error) {
// 上下文
v := r.Context().Value(ContextKey("LoginUser"))
v := r.Context().Value(ContextKey(commonConstants.CTX_LOGIN_USER))
if v != nil {
return v.(vo.LoginUser), nil
}