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

Function SetUserCtx

middleware/auth.go:74–84  ·  view source on GitHub ↗

SetUserCtx set the current login user via uid

(c *gin.Context, uid int)

Source from the content-addressed store, hash-verified

72
73// SetUserCtx set the current login user via uid
74func SetUserCtx(c *gin.Context, uid int) error {
75 dep := dependency.FromContext(c)
76 userClient := dep.UserClient()
77 loginUser, err := userClient.GetLoginUserByID(c, uid)
78 if err != nil {
79 return serializer.NewError(serializer.CodeDBError, "failed to get login user", err)
80 }
81
82 SetUserCtxByUser(c, loginUser)
83 return nil
84}
85
86func SetUserCtxByUser(c *gin.Context, user *ent.User) {
87 util.WithValue(c, inventory.UserCtx{}, user)

Callers 5

loadShareThumbnailFunction · 0.85
loadShareForOGFunction · 0.85
CurrentUserFunction · 0.85
uploadCallbackCheckFunction · 0.85
ViewerSessionValidationFunction · 0.85

Calls 5

FromContextFunction · 0.92
NewErrorFunction · 0.92
SetUserCtxByUserFunction · 0.85
UserClientMethod · 0.65
GetLoginUserByIDMethod · 0.65

Tested by

no test coverage detected