aboutsummaryrefslogtreecommitdiff
path: root/api/user.go
diff options
context:
space:
mode:
authorjloup <jloup@jloup.work>2018-05-13 15:47:59 +0100
committerjloup <jloup@jloup.work>2018-05-13 15:47:59 +0100
commitcf5bb85cede5b05b58ed2b40460d0b913e8b2cf6 (patch)
tree0a5de670cf7f03ab8d582e28c006b643b0c6e22d /api/user.go
parent391835378931665f449c2e99dc070292d193409e (diff)
downloadFront-cf5bb85cede5b05b58ed2b40460d0b913e8b2cf6.tar.gz
Front-cf5bb85cede5b05b58ed2b40460d0b913e8b2cf6.tar.zst
Front-cf5bb85cede5b05b58ed2b40460d0b913e8b2cf6.zip
User roles.v0.0.13
Diffstat (limited to 'api/user.go')
-rw-r--r--api/user.go14
1 files changed, 14 insertions, 0 deletions
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 {
30 return nil 30 return nil
31} 31}
32 32
33func UserIsAdmin(c *gin.Context) *Error {
34 user, exists := c.Get("user")
35
36 if !exists {
37 return &Error{NotAuthorized, "not authorized", fmt.Errorf("no user key in context")}
38 }
39
40 if user.(db.User).Role != db.RoleAdmin {
41 return &Error{NotAuthorized, "not authorized", fmt.Errorf("user '%v' is not admin", user)}
42 }
43
44 return nil
45}
46
33func GetUser(c *gin.Context) db.User { 47func GetUser(c *gin.Context) db.User {
34 user, _ := c.Get("user") 48 user, _ := c.Get("user")
35 49