summaryrefslogtreecommitdiffstats
path: root/model/license.go
diff options
context:
space:
mode:
authorJoramWilander <jwawilander@gmail.com>2016-01-04 12:44:22 -0500
committerJoramWilander <jwawilander@gmail.com>2016-01-14 08:24:09 -0500
commit9110dd54a15f3d0fcf6f60936e01d816b667b93c (patch)
treebe6ddca1c4dc47b71de4c7ad8af59cb21a594b56 /model/license.go
parent53b0cd8f2a24798c67505aa447b1d53b9f14197e (diff)
downloadchat-9110dd54a15f3d0fcf6f60936e01d816b667b93c.tar.gz
chat-9110dd54a15f3d0fcf6f60936e01d816b667b93c.tar.bz2
chat-9110dd54a15f3d0fcf6f60936e01d816b667b93c.zip
Added license validation and settings
Diffstat (limited to 'model/license.go')
-rw-r--r--model/license.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/model/license.go b/model/license.go
new file mode 100644
index 000000000..7a955e1f8
--- /dev/null
+++ b/model/license.go
@@ -0,0 +1,68 @@
+// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package model
+
+import (
+ "encoding/json"
+ "io"
+)
+
+type License struct {
+ Id string `json:"id"`
+ IssuedAt int64 `json:"issued_at"`
+ StartsAt int64 `json:"starts_at"`
+ ExpiresAt int64 `json:"expires_at"`
+ Customer *Customer `json:"customer"`
+ Features *Features `json:"features"`
+}
+
+type Customer struct {
+ Id string `json:"id"`
+ Name string `json:"name"`
+ Email string `json:"email"`
+ Company string `json:"company"`
+ PhoneNumber string `json:"phone_number"`
+}
+
+type Features struct {
+ Users int `json:"users"`
+ LDAP bool `json:"ldap"`
+ GoogleSSO bool `json:"google_sso"`
+}
+
+func (l *License) IsExpired() bool {
+ now := GetMillis()
+ if l.ExpiresAt < now {
+ return true
+ }
+ return false
+}
+
+func (l *License) IsStarted() bool {
+ now := GetMillis()
+ if l.StartsAt < now {
+ return true
+ }
+ return false
+}
+
+func (l *License) ToJson() string {
+ b, err := json.Marshal(l)
+ if err != nil {
+ return ""
+ } else {
+ return string(b)
+ }
+}
+
+func LicenseFromJson(data io.Reader) *License {
+ decoder := json.NewDecoder(data)
+ var o License
+ err := decoder.Decode(&o)
+ if err == nil {
+ return &o
+ } else {
+ return nil
+ }
+}