MCPcopy Create free account
hub / github.com/cloudreve/cloudreve / CurrentUser

Function CurrentUser

middleware/auth.go:48–71  ·  view source on GitHub ↗

CurrentUser 获取登录用户

()

Source from the content-addressed store, hash-verified

46
47// CurrentUser 获取登录用户
48func CurrentUser() gin.HandlerFunc {
49 return func(c *gin.Context) {
50 dep := dependency.FromContext(c)
51 shouldContinue, err := dep.TokenAuth().VerifyAndRetrieveUser(c)
52 if err != nil {
53 c.JSON(200, serializer.Err(c, err))
54 c.Abort()
55 return
56 }
57
58 if shouldContinue {
59 // TODO: Logto handler
60 }
61
62 uid := inventory.UserIDFromContext(c)
63 if err := SetUserCtx(c, uid); err != nil {
64 c.JSON(200, serializer.Err(c, err))
65 c.Abort()
66 return
67 }
68
69 c.Next()
70 }
71}
72
73// SetUserCtx set the current login user via uid
74func SetUserCtx(c *gin.Context, uid int) error {

Callers 1

initMasterRouterFunction · 0.92

Calls 7

FromContextFunction · 0.92
ErrFunction · 0.92
UserIDFromContextFunction · 0.92
SetUserCtxFunction · 0.85
VerifyAndRetrieveUserMethod · 0.65
TokenAuthMethod · 0.65
NextMethod · 0.65

Tested by

no test coverage detected