diff options
author | =Corey Hulen <corey@hulen.com> | 2016-01-22 16:31:58 -0600 |
---|---|---|
committer | =Corey Hulen <corey@hulen.com> | 2016-01-22 16:31:58 -0600 |
commit | c2d98c2c1f4860c11aedf43aff5e360256a89835 (patch) | |
tree | 4304f7584025477d74e5e70677c4f5a70c26bb58 /model | |
parent | 6e2c1b7fd5248c6a4a91edcd59fa124c8d3c744a (diff) | |
parent | d352c5b64dddfb8e46b18edbd7352c41495078a1 (diff) | |
download | chat-c2d98c2c1f4860c11aedf43aff5e360256a89835.tar.gz chat-c2d98c2c1f4860c11aedf43aff5e360256a89835.tar.bz2 chat-c2d98c2c1f4860c11aedf43aff5e360256a89835.zip |
merging
Diffstat (limited to 'model')
-rw-r--r-- | model/config.go | 12 | ||||
-rw-r--r-- | model/user.go | 11 | ||||
-rw-r--r-- | model/utils.go | 40 |
3 files changed, 54 insertions, 9 deletions
diff --git a/model/config.go b/model/config.go index 7d9ff41f1..c0e66d50c 100644 --- a/model/config.go +++ b/model/config.go @@ -42,6 +42,8 @@ type ServiceSettings struct { SessionLengthMobileInDays *int SessionLengthSSOInDays *int SessionCacheInMinutes *int + WebsocketSecurePort *int + WebsocketPort *int } type SSOSettings struct { @@ -342,6 +344,16 @@ func (o *Config) SetDefaults() { o.ServiceSettings.EnableOnlyAdminIntegrations = new(bool) *o.ServiceSettings.EnableOnlyAdminIntegrations = true } + + if o.ServiceSettings.WebsocketPort == nil { + o.ServiceSettings.WebsocketPort = new(int) + *o.ServiceSettings.WebsocketPort = 80 + } + + if o.ServiceSettings.WebsocketSecurePort == nil { + o.ServiceSettings.WebsocketSecurePort = new(int) + *o.ServiceSettings.WebsocketSecurePort = 443 + } } func (o *Config) IsValid() *AppError { diff --git a/model/user.go b/model/user.go index 4ba35c6c4..7744b0073 100644 --- a/model/user.go +++ b/model/user.go @@ -6,11 +6,12 @@ package model import ( "encoding/json" "fmt" - "golang.org/x/crypto/bcrypt" "io" "regexp" "strings" "unicode/utf8" + + "golang.org/x/crypto/bcrypt" ) const ( @@ -24,6 +25,7 @@ const ( USER_NOTIFY_ALL = "all" USER_NOTIFY_MENTION = "mention" USER_NOTIFY_NONE = "none" + DEFAULT_LOCALE = "en" ) type User struct { @@ -51,6 +53,7 @@ type User struct { LastPasswordUpdate int64 `json:"last_password_update,omitempty"` LastPictureUpdate int64 `json:"last_picture_update,omitempty"` FailedAttempts int `json:"failed_attempts,omitempty"` + Locale string `json:"locale"` } // IsValid validates the user and returns an error if it isn't configured @@ -130,12 +133,17 @@ func (u *User) PreSave() { u.Username = strings.ToLower(u.Username) u.Email = strings.ToLower(u.Email) + u.Locale = strings.ToLower(u.Locale) u.CreateAt = GetMillis() u.UpdateAt = u.CreateAt u.LastPasswordUpdate = u.CreateAt + if u.Locale == "" { + u.Locale = DEFAULT_LOCALE + } + if u.Props == nil { u.Props = make(map[string]string) } @@ -153,6 +161,7 @@ func (u *User) PreSave() { func (u *User) PreUpdate() { u.Username = strings.ToLower(u.Username) u.Email = strings.ToLower(u.Email) + u.Locale = strings.ToLower(u.Locale) u.UpdateAt = GetMillis() if u.NotifyProps == nil || len(u.NotifyProps) == 0 { diff --git a/model/utils.go b/model/utils.go index 301e36f59..042b5f195 100644 --- a/model/utils.go +++ b/model/utils.go @@ -9,13 +9,15 @@ import ( "encoding/base32" "encoding/json" "fmt" - "github.com/pborman/uuid" "io" "net/mail" "net/url" "regexp" "strings" "time" + + goi18n "github.com/nicksnyder/go-i18n/i18n" + "github.com/pborman/uuid" ) type StringInterface map[string]interface{} @@ -23,20 +25,31 @@ type StringMap map[string]string type StringArray []string type EncryptStringMap map[string]string -// AppError is returned for any http response that's not in the 200 range. type AppError struct { - Message string `json:"message"` // Message to be display to the end user without debugging information - DetailedError string `json:"detailed_error"` // Internal error string to help the developer - RequestId string `json:"request_id"` // The RequestId that's also set in the header - StatusCode int `json:"status_code"` // The http status code - Where string `json:"-"` // The function where it happened in the form of Struct.Func - IsOAuth bool `json:"is_oauth"` // Whether the error is OAuth specific + Id string `json:"id"` + Message string `json:"message"` // Message to be display to the end user without debugging information + DetailedError string `json:"detailed_error"` // Internal error string to help the developer + RequestId string `json:"request_id"` // The RequestId that's also set in the header + StatusCode int `json:"status_code"` // The http status code + Where string `json:"-"` // The function where it happened in the form of Struct.Func + IsOAuth bool `json:"is_oauth"` // Whether the error is OAuth specific + params map[string]interface{} `json:"-"` } func (er *AppError) Error() string { return er.Where + ": " + er.Message + ", " + er.DetailedError } +func (er *AppError) Translate(T goi18n.TranslateFunc) { + if len(er.Message) == 0 { + if er.params == nil { + er.Message = T(er.Id) + } else { + er.Message = T(er.Id, er.params) + } + } +} + func (er *AppError) ToJson() string { b, err := json.Marshal(er) if err != nil { @@ -72,6 +85,17 @@ func NewAppError(where string, message string, details string) *AppError { return ap } +func NewLocAppError(where string, id string, params map[string]interface{}, details string) *AppError { + ap := &AppError{} + ap.Id = id + ap.params = params + ap.Where = where + ap.DetailedError = details + ap.StatusCode = 500 + ap.IsOAuth = false + return ap +} + var encoding = base32.NewEncoding("ybndrfg8ejkmcpqxot1uwisza345h769") // NewId is a globally unique identifier. It is a [A-Z0-9] string 26 |