Skip to content

Commit 7511efc

Browse files
committed
feat✨ :added dept key
1 parent 06ace72 commit 7511efc

File tree

2 files changed

+40
-11
lines changed

2 files changed

+40
-11
lines changed

sdk/pkg/jwtauth/jwtauth.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,16 +206,26 @@ var (
206206
// IdentityKey default identity key
207207
IdentityKey = "identity"
208208

209-
NiceKey = "nice"
210-
209+
// NiceKey 昵称
210+
NiceKey = "nice"
211211
DataScopeKey = "datascope"
212212

213-
RKey = "r"
214-
RoleIdKey = "roleid"
213+
RKey = "r"
214+
215+
// RoleIdKey 角色id Old
216+
RoleIdKey = "roleid"
215217

216-
RoleKey = "rolekey"
218+
// RoleKey 角色名称 Old
219+
RoleKey = "rolekey"
217220

221+
// RoleNameKey 角色名称 Old
218222
RoleNameKey = "rolename"
223+
224+
// RoleIdKey 部门id
225+
DeptId = "deptId"
226+
227+
// RoleKey 部门名称
228+
DeptName = "deptName"
219229
)
220230

221231
// New for check error with GinJWTMiddleware
@@ -737,4 +747,4 @@ func GetToken(c *gin.Context) string {
737747
}
738748

739749
return token.(string)
740-
}
750+
}

sdk/pkg/jwtauth/user/user.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func GetUserId(c *gin.Context) int {
2323
if data["identity"] != nil {
2424
return int((data["identity"]).(float64))
2525
}
26-
fmt.Println(pkg.GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetUserId 缺少identity")
26+
fmt.Println(pkg.GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetUserId 缺少 identity")
2727
return 0
2828
}
2929

@@ -32,7 +32,7 @@ func GetUserIdStr(c *gin.Context) string {
3232
if data["identity"] != nil {
3333
return pkg.Int64ToString(int64((data["identity"]).(float64)))
3434
}
35-
fmt.Println(pkg.GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetUserIdStr 缺少identity")
35+
fmt.Println(pkg.GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetUserIdStr 缺少 identity")
3636
return ""
3737
}
3838

@@ -41,7 +41,7 @@ func GetUserName(c *gin.Context) string {
4141
if data["nice"] != nil {
4242
return (data["nice"]).(string)
4343
}
44-
fmt.Println(pkg.GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetUserName 缺少nice")
44+
fmt.Println(pkg.GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetUserName 缺少 nice")
4545
return ""
4646
}
4747

@@ -50,7 +50,7 @@ func GetRoleName(c *gin.Context) string {
5050
if data["rolekey"] != nil {
5151
return (data["rolekey"]).(string)
5252
}
53-
fmt.Println(pkg.GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetRoleName 缺少rolekey")
53+
fmt.Println(pkg.GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetRoleName 缺少 rolekey")
5454
return ""
5555
}
5656

@@ -60,6 +60,25 @@ func GetRoleId(c *gin.Context) int {
6060
i := int((data["roleid"]).(float64))
6161
return i
6262
}
63-
fmt.Println(pkg.GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetRoleId 缺少roleid")
63+
fmt.Println(pkg.GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetRoleId 缺少 roleid")
6464
return 0
6565
}
66+
67+
func GetDeptId(c *gin.Context) int {
68+
data := ExtractClaims(c)
69+
if data["deptid"] != nil {
70+
i := int((data["deptid"]).(float64))
71+
return i
72+
}
73+
fmt.Println(pkg.GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetDeptId 缺少 deptid")
74+
return 0
75+
}
76+
77+
func GetDeptName(c *gin.Context) string {
78+
data := ExtractClaims(c)
79+
if data["deptkey"] != nil {
80+
return (data["deptkey"]).(string)
81+
}
82+
fmt.Println(pkg.GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetDeptName 缺少 deptkey")
83+
return ""
84+
}

0 commit comments

Comments
 (0)