u
This commit is contained in:
1 parent
83cbf18572
commit
5ca04f85ca
32 files changed
+1308
-1804
No files matched your search
@@ -39,16 +39,11 @@ func Auth() app.HandlerFunc {
|
||||
}
|
||||
|
||||
// 校验 token
|
||||
token := strings.TrimSpace(string(c.GetHeader("token")))
|
||||
if token == "" {
|
||||
response.Fail(c).Code(response.HttpCode.Unauthorized).Send()
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
token := strings.TrimSpace(string(c.GetHeader("Token")))
|
||||
|
||||
verifyToken, flag := jwtx.VerifyToken(token)
|
||||
if !flag {
|
||||
response.Fail(c).Code(response.HttpCode.RefreshToken).Send()
|
||||
response.Fail(c).Code(response.HttpCode.Unauthorized).Send()
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
@@ -56,18 +51,18 @@ func Auth() app.HandlerFunc {
|
||||
userID := verifyToken.UserID
|
||||
|
||||
// 获取 header 中的 spaceid
|
||||
spaceIDStr := strings.TrimSpace(string(c.GetHeader("spaceid")))
|
||||
spaceIDStr := strings.TrimSpace(string(c.GetHeader("X-Space-Id")))
|
||||
spaceID, err := strconv.ParseInt(spaceIDStr, 10, 64)
|
||||
if err != nil || spaceID == 0 {
|
||||
response.Fail(c).Message("缺少有效 spaceid").Send()
|
||||
response.Fail(c).Code(response.HttpCode.ErrSpaceRequired).Message("请先选择空间").Send()
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
// 判断用户是否在该空间
|
||||
inSpace, err := redisx.HasUserSpace(ctx, userID, spaceID)
|
||||
inSpace, err := redisx.InSpace(ctx, userID, spaceID)
|
||||
if err != nil || !inSpace {
|
||||
response.Fail(c).Message("无权限访问该空间").Send()
|
||||
response.Fail(c).Code(response.HttpCode.ErrSpaceRequired).Message("无权限访问该空间").Send()
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -16,51 +16,6 @@ func _spaceMw() []app.HandlerFunc {
|
||||
return nil
|
||||
}
|
||||
|
||||
func _insertspaceMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
||||
func _deletespaceMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
||||
func _space_userMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
||||
func _exitspaceMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
||||
func _queryspaceusersMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
||||
func _listspaceusersMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
||||
func _removespaceuserMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
||||
func _updatespaceuserroleMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
||||
func _joinspaceMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
||||
func _createspaceMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
@@ -71,42 +26,22 @@ func _dissolvespaceMw() []app.HandlerFunc {
|
||||
return nil
|
||||
}
|
||||
|
||||
func _userMw() []app.HandlerFunc {
|
||||
func _exitspaceMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
||||
func _getuserspaceMw() []app.HandlerFunc {
|
||||
func _joinspaceMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
||||
func _enterspaceMw() []app.HandlerFunc {
|
||||
func _removespaceuserMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
||||
func _user0Mw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
||||
func _listuserspacesMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
||||
func __7bspaceid_7dMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
||||
func _kickoutuserMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
||||
func _quitspaceMw() []app.HandlerFunc {
|
||||
func _listspaceusersMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
@@ -19,9 +19,11 @@ func Register(r *server.Hertz) {
|
||||
root := r.Group("/", rootMw()...)
|
||||
{
|
||||
_space := root.Group("/space", _spaceMw()...)
|
||||
_space.POST("/create", append(_createspaceMw(), space.CreateSpace)...)
|
||||
_space.POST("/dissolve", append(_dissolvespaceMw(), space.DissolveSpace)...)
|
||||
_space.POST("/exit", append(_exitspaceMw(), space.ExitSpace)...)
|
||||
_space.POST("/join", append(_joinspaceMw(), space.JoinSpace)...)
|
||||
_space.POST("/kick", append(_kickoutuserMw(), space.KickOutUser)...)
|
||||
_space.POST("/quit", append(_quitspaceMw(), space.QuitSpace)...)
|
||||
_space.POST("/remove", append(_removespaceuserMw(), space.RemoveSpaceUser)...)
|
||||
_space.POST("/users", append(_listspaceusersMw(), space.ListSpaceUsers)...)
|
||||
}
|
||||
}
|
||||
@@ -20,3 +20,8 @@ func _listuserspacesMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
|
||||
func _getuserspaceMw() []app.HandlerFunc {
|
||||
// your code...
|
||||
return nil
|
||||
}
|
||||
@@ -19,6 +19,6 @@ func Register(r *server.Hertz) {
|
||||
root := r.Group("/", rootMw()...)
|
||||
{
|
||||
_user := root.Group("/user", _userMw()...)
|
||||
_user.GET("/spaces", append(_listuserspacesMw(), user.ListUserSpaces)...)
|
||||
_user.GET("/space", append(_getuserspaceMw(), user.GetUserSpace)...)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user