]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front.git/blobdiff - api/user.go
User roles.
[perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front.git] / api / user.go
index a2737fd0a06c9f8e3cdacc81ef1990168982cea3..bc24bbb23111d478adb6bb82636cd7bc82dc4e81 100644 (file)
@@ -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")