+func UserConfirmed(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).Status != db.Confirmed {
+ return &Error{UserNotConfirmed, "user awaiting admin validation", fmt.Errorf("user '%v' not confirmed", user)}
+ }
+
+ 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")
+
+ return user.(db.User)
+}
+