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.
()
| 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. |
| 37 | func (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. |
no test coverage detected