Этот коммит содержится в:
=Corey Hulen
2016-01-22 16:31:58 -06:00
родитель 6e2c1b7fd5 d352c5b64d
Коммит c2d98c2c1f
1772 изменённых файлов: 1556763 добавлений и 520 удалений

Просмотреть файл

@@ -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 {

Просмотреть файл

@@ -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 {

Просмотреть файл

@@ -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