Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop
This commit is contained in:
commit
30abb2bb06
|
@ -8,6 +8,7 @@ import (
|
|||
"errors"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/encryption_decryption"
|
||||
"fusenapi/utils/websocket_data"
|
||||
"net/http"
|
||||
|
@ -118,7 +119,7 @@ func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request)
|
|||
return
|
||||
}
|
||||
//设置连接
|
||||
ws, err := l.setConnPool(conn, *userInfo, isFirefoxBrowser)
|
||||
ws, err := l.setConnPool(conn, userInfo, isFirefoxBrowser)
|
||||
if err != nil {
|
||||
conn.Close()
|
||||
return
|
||||
|
@ -138,7 +139,7 @@ func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request)
|
|||
}
|
||||
|
||||
// 设置连接
|
||||
func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo auth.UserInfo, isFirefoxBrowser bool) (wsConnectItem, error) {
|
||||
func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.UserInfo, isFirefoxBrowser bool) (wsConnectItem, error) {
|
||||
//生成连接唯一标识(失败重试10次)
|
||||
uniqueId, err := l.getUniqueId(userInfo, 10)
|
||||
if err != nil {
|
||||
|
@ -171,7 +172,7 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo auth.User
|
|||
}
|
||||
|
||||
// 获取唯一id
|
||||
func (l *DataTransferLogic) getUniqueId(userInfo auth.UserInfo, retryTimes int) (uniqueId string, err error) {
|
||||
func (l *DataTransferLogic) getUniqueId(userInfo *auth.UserInfo, retryTimes int) (uniqueId string, err error) {
|
||||
if retryTimes < 0 {
|
||||
return "", errors.New("failed to get unique id")
|
||||
}
|
||||
|
@ -195,24 +196,12 @@ func (l *DataTransferLogic) getUniqueId(userInfo auth.UserInfo, retryTimes int)
|
|||
// 鉴权
|
||||
func (l *DataTransferLogic) checkAuth(r *http.Request) (isAuth bool, userInfo *auth.UserInfo) {
|
||||
// 解析JWT token,并对空用户进行判断
|
||||
claims, err := l.svcCtx.ParseJwtToken(r)
|
||||
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
||||
userInfo, err := basic.ParseJwtToken(r, l.svcCtx)
|
||||
if err != nil {
|
||||
logx.Error("ParseJwtToken err:", err)
|
||||
return false, nil
|
||||
}
|
||||
if claims != nil {
|
||||
// 从token中获取对应的用户信息
|
||||
userInfo, err = auth.GetUserInfoFormMapClaims(claims)
|
||||
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
||||
if err != nil {
|
||||
logx.Error("GetUserInfoFormMapClaims err:", err)
|
||||
return false, nil
|
||||
}
|
||||
return true, userInfo
|
||||
}
|
||||
//白板用户
|
||||
return true, &auth.UserInfo{}
|
||||
return true, userInfo
|
||||
}
|
||||
|
||||
// 鉴权失败通知
|
||||
|
|
Loading…
Reference in New Issue
Block a user