MCPcopy
hub / github.com/gotify/server / RequireAdmin

Method RequireAdmin

auth/authentication.go:37–53  ·  view source on GitHub ↗

RequireAdmin returns a gin middleware which requires a client token or basic authentication header to be supplied with the request. Also the authenticated user must be an administrator.

()

Source from the content-addressed store, hash-verified

35// RequireAdmin returns a gin middleware which requires a client token or basic authentication header to be supplied
36// with the request. Also the authenticated user must be an administrator.
37func (a *Auth) RequireAdmin() gin.HandlerFunc {
38 return a.requireToken(func(tokenID string, user *model.User) (bool, bool, uint, error) {
39 if user != nil {
40 return true, user.Admin, user.ID, nil
41 }
42 if token, err := a.DB.GetClientByToken(tokenID); err != nil {
43 return false, false, 0, err
44 } else if token != nil {
45 user, err := a.DB.GetUserByID(token.UserID)
46 if err != nil {
47 return false, false, token.UserID, err
48 }
49 return true, user.Admin, token.UserID, nil
50 }
51 return false, false, 0, nil
52 })
53}
54
55// RequireClient returns a gin middleware which requires a client token or basic authentication header to be supplied
56// with the request.

Callers 1

CreateFunction · 0.95

Calls 3

requireTokenMethod · 0.95
GetClientByTokenMethod · 0.65
GetUserByIDMethod · 0.65

Tested by

no test coverage detected