X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FCryptoportfolio%2FFront.git;a=blobdiff_plain;f=api%2Fuser.go;h=bc24bbb23111d478adb6bb82636cd7bc82dc4e81;hp=a2737fd0a06c9f8e3cdacc81ef1990168982cea3;hb=cf5bb85cede5b05b58ed2b40460d0b913e8b2cf6;hpb=391835378931665f449c2e99dc070292d193409e diff --git a/api/user.go b/api/user.go index a2737fd..bc24bbb 100644 --- a/api/user.go +++ b/api/user.go @@ -30,6 +30,20 @@ func UserConfirmed(c *gin.Context) *Error { return nil } +func UserIsAdmin(c *gin.Context) *Error { + user, exists := c.Get("user") + + if !exists { + return &Error{NotAuthorized, "not authorized", fmt.Errorf("no user key in context")} + } + + if user.(db.User).Role != db.RoleAdmin { + return &Error{NotAuthorized, "not authorized", fmt.Errorf("user '%v' is not admin", user)} + } + + return nil +} + func GetUser(c *gin.Context) db.User { user, _ := c.Get("user")