summaryrefslogtreecommitdiffstats
path: root/model/user.go
diff options
context:
space:
mode:
author=Corey Hulen <corey@hulen.com>2015-09-04 11:59:10 -0700
committer=Corey Hulen <corey@hulen.com>2015-09-04 11:59:10 -0700
commit58d0d9afd286afd715e9f04825e1305045d404e2 (patch)
tree10615aa68c68106684503fb18ae4e4ef8998bc22 /model/user.go
parent05d95d80a896d14474c7f7384d67b9edd524b922 (diff)
downloadchat-58d0d9afd286afd715e9f04825e1305045d404e2.tar.gz
chat-58d0d9afd286afd715e9f04825e1305045d404e2.tar.bz2
chat-58d0d9afd286afd715e9f04825e1305045d404e2.zip
Adding cmd line options
Diffstat (limited to 'model/user.go')
-rw-r--r--model/user.go47
1 files changed, 46 insertions, 1 deletions
diff --git a/model/user.go b/model/user.go
index d82f96db3..9cec37ac6 100644
--- a/model/user.go
+++ b/model/user.go
@@ -15,7 +15,6 @@ import (
const (
ROLE_ADMIN = "admin"
ROLE_SYSTEM_ADMIN = "system_admin"
- ROLE_SYSTEM_SUPPORT = "system_support"
USER_AWAY_TIMEOUT = 5 * 60 * 1000 // 5 minutes
USER_OFFLINE_TIMEOUT = 1 * 60 * 1000 // 1 minute
USER_OFFLINE = "offline"
@@ -272,6 +271,52 @@ func (u *User) GetDisplayName() string {
}
}
+func IsValidRoles(userRoles string) bool {
+
+ roles := strings.Split(userRoles, " ")
+
+ for _, r := range roles {
+ if !isValidRole(r) {
+ return false
+ }
+ }
+
+ return true
+}
+
+func isValidRole(role string) bool {
+ if role == "" {
+ return true
+ }
+
+ if role == ROLE_ADMIN {
+ return true
+ }
+
+ if role == ROLE_SYSTEM_ADMIN {
+ return true
+ }
+
+ return false
+}
+
+func (u *User) IsInRole(inRole string) bool {
+ return IsInRole(u.Roles, inRole)
+}
+
+func IsInRole(userRoles string, inRole string) bool {
+ roles := strings.Split(userRoles, " ")
+
+ for _, r := range roles {
+ if r == inRole {
+ return true
+ }
+
+ }
+
+ return false
+}
+
// UserFromJson will decode the input and return a User
func UserFromJson(data io.Reader) *User {
decoder := json.NewDecoder(data)