diff options
author | =Corey Hulen <corey@hulen.com> | 2016-01-14 09:08:13 -0600 |
---|---|---|
committer | =Corey Hulen <corey@hulen.com> | 2016-01-14 09:08:13 -0600 |
commit | 6d6cada0970a2b341f36dac9b0fed8262ada1865 (patch) | |
tree | fc3728f15deaebd0c870838a63735659a33456e7 /model/license.go | |
parent | 0b986ed3147c885af6b2f33e1ff3eb6754e8f274 (diff) | |
parent | a341dbad2b8a4564b6f270c79f2f9932e499ac80 (diff) | |
download | chat-6d6cada0970a2b341f36dac9b0fed8262ada1865.tar.gz chat-6d6cada0970a2b341f36dac9b0fed8262ada1865.tar.bz2 chat-6d6cada0970a2b341f36dac9b0fed8262ada1865.zip |
Merge branch 'master' into PLT-1429
Diffstat (limited to 'model/license.go')
-rw-r--r-- | model/license.go | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/model/license.go b/model/license.go new file mode 100644 index 000000000..a271b46b7 --- /dev/null +++ b/model/license.go @@ -0,0 +1,85 @@ +// Copyright (c) 2016 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 (f *Features) SetDefaults() { + if f.Users == nil { + f.Users = new(int) + *f.Users = 0 + } + + if f.LDAP == nil { + f.LDAP = new(bool) + *f.LDAP = true + } + + if f.GoogleSSO == nil { + f.GoogleSSO = new(bool) + *f.GoogleSSO = true + } +} + +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 + } +} |