summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api/context.go2
-rw-r--r--api/team.go5
-rw-r--r--api/web_conn.go12
-rw-r--r--api/web_socket.go2
-rw-r--r--i18n/en.json8
-rw-r--r--model/config.go2
-rw-r--r--store/sql_channel_store.go6
-rw-r--r--store/sql_preference_store.go2
-rw-r--r--store/sql_store.go11
-rw-r--r--store/sql_team_store.go4
-rw-r--r--store/sql_user_store.go8
-rw-r--r--utils/config.go2
12 files changed, 37 insertions, 27 deletions
diff --git a/api/context.go b/api/context.go
index 67b04c391..f87a306d9 100644
--- a/api/context.go
+++ b/api/context.go
@@ -568,7 +568,7 @@ func GetSession(token string) *model.Session {
} else {
session = sessionResult.Data.(*model.Session)
- if session.IsExpired() {
+ if session.IsExpired() || session.Token != token {
return nil
} else {
AddSessionToCache(session)
diff --git a/api/team.go b/api/team.go
index 52d01b1cc..3ed9b70af 100644
--- a/api/team.go
+++ b/api/team.go
@@ -222,11 +222,6 @@ func createTeam(c *Context, w http.ResponseWriter, r *http.Request) {
}
func CreateTeam(c *Context, team *model.Team) *model.Team {
- if !utils.Cfg.EmailSettings.EnableSignUpWithEmail {
- c.Err = model.NewLocAppError("createTeam", "api.team.create_team.email_disabled.app_error", nil, "")
- c.Err.StatusCode = http.StatusForbidden
- return nil
- }
if team == nil {
c.SetInvalidParam("createTeam", "team")
diff --git a/api/web_conn.go b/api/web_conn.go
index 21b6f5b91..9a6fc29df 100644
--- a/api/web_conn.go
+++ b/api/web_conn.go
@@ -22,19 +22,19 @@ const (
type WebConn struct {
WebSocket *websocket.Conn
Send chan *model.Message
- SessionId string
+ SessionToken string
UserId string
hasPermissionsToChannel map[string]bool
hasPermissionsToTeam map[string]bool
}
-func NewWebConn(ws *websocket.Conn, userId string, sessionId string) *WebConn {
+func NewWebConn(ws *websocket.Conn, userId string, sessionToken string) *WebConn {
go func() {
- achan := Srv.Store.User().UpdateUserAndSessionActivity(userId, sessionId, model.GetMillis())
+ achan := Srv.Store.User().UpdateUserAndSessionActivity(userId, sessionToken, model.GetMillis())
pchan := Srv.Store.User().UpdateLastPingAt(userId, model.GetMillis())
if result := <-achan; result.Err != nil {
- l4g.Error(utils.T("api.web_conn.new_web_conn.last_activity.error"), userId, sessionId, result.Err)
+ l4g.Error(utils.T("api.web_conn.new_web_conn.last_activity.error"), userId, sessionToken, result.Err)
}
if result := <-pchan; result.Err != nil {
@@ -46,7 +46,7 @@ func NewWebConn(ws *websocket.Conn, userId string, sessionId string) *WebConn {
Send: make(chan *model.Message, 64),
WebSocket: ws,
UserId: userId,
- SessionId: sessionId,
+ SessionToken: sessionToken,
hasPermissionsToChannel: make(map[string]bool),
hasPermissionsToTeam: make(map[string]bool),
}
@@ -125,7 +125,7 @@ func (c *WebConn) InvalidateCacheForChannel(channelId string) {
func (c *WebConn) HasPermissionsToTeam(teamId string) bool {
perm, ok := c.hasPermissionsToTeam[teamId]
if !ok {
- session := GetSession(c.SessionId)
+ session := GetSession(c.SessionToken)
if session == nil {
perm = false
c.hasPermissionsToTeam[teamId] = perm
diff --git a/api/web_socket.go b/api/web_socket.go
index 72a9c61a6..4c4a56c52 100644
--- a/api/web_socket.go
+++ b/api/web_socket.go
@@ -33,7 +33,7 @@ func connect(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- wc := NewWebConn(ws, c.Session.UserId, c.Session.Id)
+ wc := NewWebConn(ws, c.Session.UserId, c.Session.Token)
hub.Register(wc)
go wc.writePump()
wc.readPump()
diff --git a/i18n/en.json b/i18n/en.json
index 40f722add..6ecfece69 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -3512,6 +3512,10 @@
"translation": "An account with that email already exists."
},
{
+ "id": "store.sql_user.save.email_exists.ldap_app_error",
+ "translation": "This account does not use LDAP authentication. Please sign in using email and password."
+ },
+ {
"id": "store.sql_user.save.existing.app_error",
"translation": "Must call update for exisiting user"
},
@@ -3528,6 +3532,10 @@
"translation": "An account with that username already exists."
},
{
+ "id": "store.sql_user.save.username_exists.ldap_app_error",
+ "translation": "An account with that username already exists. Please contact your Administrator."
+ },
+ {
"id": "store.sql_user.update.app_error",
"translation": "We couldn't update the account"
},
diff --git a/model/config.go b/model/config.go
index eb25948fd..9a7e3b7c5 100644
--- a/model/config.go
+++ b/model/config.go
@@ -615,7 +615,7 @@ func (o *Config) GetSanitizeOptions() map[string]bool {
}
func (o *Config) Sanitize() {
- if &o.LdapSettings != nil && len(*o.LdapSettings.BindPassword) > 0 {
+ if o.LdapSettings.BindPassword != nil && len(*o.LdapSettings.BindPassword) > 0 {
*o.LdapSettings.BindPassword = FAKE_SETTING
}
diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go
index 9f9d86454..0a8873b57 100644
--- a/store/sql_channel_store.go
+++ b/store/sql_channel_store.go
@@ -165,7 +165,7 @@ func (s SqlChannelStore) saveChannelT(transaction *gorp.Transaction, channel *mo
}
if err := transaction.Insert(channel); err != nil {
- if IsUniqueConstraintError(err.Error(), "Name", "channels_name_teamid_key") {
+ if IsUniqueConstraintError(err.Error(), []string{"Name", "channels_name_teamid_key"}) {
dupChannel := model.Channel{}
s.GetMaster().SelectOne(&dupChannel, "SELECT * FROM Channels WHERE TeamId = :TeamId AND Name = :Name AND DeleteAt > 0", map[string]interface{}{"TeamId": channel.TeamId, "Name": channel.Name})
if dupChannel.DeleteAt > 0 {
@@ -200,7 +200,7 @@ func (s SqlChannelStore) Update(channel *model.Channel) StoreChannel {
}
if count, err := s.GetMaster().Update(channel); err != nil {
- if IsUniqueConstraintError(err.Error(), "Name", "channels_name_teamid_key") {
+ if IsUniqueConstraintError(err.Error(), []string{"Name", "channels_name_teamid_key"}) {
dupChannel := model.Channel{}
s.GetReplica().SelectOne(&dupChannel, "SELECT * FROM Channels WHERE TeamId = :TeamId AND Name= :Name AND DeleteAt > 0", map[string]interface{}{"TeamId": channel.TeamId, "Name": channel.Name})
if dupChannel.DeleteAt > 0 {
@@ -508,7 +508,7 @@ func (s SqlChannelStore) saveMemberT(transaction *gorp.Transaction, member *mode
}
if err := transaction.Insert(member); err != nil {
- if IsUniqueConstraintError(err.Error(), "ChannelId", "channelmembers_pkey") {
+ if IsUniqueConstraintError(err.Error(), []string{"ChannelId", "channelmembers_pkey"}) {
result.Err = model.NewLocAppError("SqlChannelStore.SaveMember", "store.sql_channel.save_member.exists.app_error", nil, "channel_id="+member.ChannelId+", user_id="+member.UserId+", "+err.Error())
} else {
result.Err = model.NewLocAppError("SqlChannelStore.SaveMember", "store.sql_channel.save_member.save.app_error", nil, "channel_id="+member.ChannelId+", user_id="+member.UserId+", "+err.Error())
diff --git a/store/sql_preference_store.go b/store/sql_preference_store.go
index bb3fca3e3..83bf92ead 100644
--- a/store/sql_preference_store.go
+++ b/store/sql_preference_store.go
@@ -155,7 +155,7 @@ func (s SqlPreferenceStore) insert(transaction *gorp.Transaction, preference *mo
result := StoreResult{}
if err := transaction.Insert(preference); err != nil {
- if IsUniqueConstraintError(err.Error(), "UserId", "preferences_pkey") {
+ if IsUniqueConstraintError(err.Error(), []string{"UserId", "preferences_pkey"}) {
result.Err = model.NewLocAppError("SqlPreferenceStore.insert", "store.sql_preference.insert.exists.app_error", nil,
"user_id="+preference.UserId+", category="+preference.Category+", name="+preference.Name+", "+err.Error())
} else {
diff --git a/store/sql_store.go b/store/sql_store.go
index 688e1b116..0979579df 100644
--- a/store/sql_store.go
+++ b/store/sql_store.go
@@ -582,9 +582,16 @@ func (ss SqlStore) RemoveIndexIfExists(indexName string, tableName string) {
}
}
-func IsUniqueConstraintError(err string, mysql string, postgres string) bool {
+func IsUniqueConstraintError(err string, indexName []string) bool {
unique := strings.Contains(err, "unique constraint") || strings.Contains(err, "Duplicate entry")
- field := strings.Contains(err, mysql) || strings.Contains(err, postgres)
+ field := false
+ for _, contain := range indexName {
+ if strings.Contains(err, contain) {
+ field = true
+ break
+ }
+ }
+
return unique && field
}
diff --git a/store/sql_team_store.go b/store/sql_team_store.go
index daaa1bac1..a9f265273 100644
--- a/store/sql_team_store.go
+++ b/store/sql_team_store.go
@@ -68,7 +68,7 @@ func (s SqlTeamStore) Save(team *model.Team) StoreChannel {
}
if err := s.GetMaster().Insert(team); err != nil {
- if IsUniqueConstraintError(err.Error(), "Name", "teams_name_key") {
+ if IsUniqueConstraintError(err.Error(), []string{"Name", "teams_name_key"}) {
result.Err = model.NewLocAppError("SqlTeamStore.Save", "store.sql_team.save.domain_exists.app_error", nil, "id="+team.Id+", "+err.Error())
} else {
result.Err = model.NewLocAppError("SqlTeamStore.Save", "store.sql_team.save.app_error", nil, "id="+team.Id+", "+err.Error())
@@ -370,7 +370,7 @@ func (s SqlTeamStore) SaveMember(member *model.TeamMember) StoreChannel {
}
if err := s.GetMaster().Insert(member); err != nil {
- if IsUniqueConstraintError(err.Error(), "TeamId", "teammembers_pkey") {
+ if IsUniqueConstraintError(err.Error(), []string{"TeamId", "teammembers_pkey"}) {
result.Err = model.NewLocAppError("SqlTeamStore.SaveMember", "store.sql_team.save_member.exists.app_error", nil, "team_id="+member.TeamId+", user_id="+member.UserId+", "+err.Error())
} else {
result.Err = model.NewLocAppError("SqlTeamStore.SaveMember", "store.sql_team.save_member.save.app_error", nil, "team_id="+member.TeamId+", user_id="+member.UserId+", "+err.Error())
diff --git a/store/sql_user_store.go b/store/sql_user_store.go
index a6b706380..11a915055 100644
--- a/store/sql_user_store.go
+++ b/store/sql_user_store.go
@@ -77,9 +77,9 @@ func (us SqlUserStore) Save(user *model.User) StoreChannel {
}
if err := us.GetMaster().Insert(user); err != nil {
- if IsUniqueConstraintError(err.Error(), "Email", "users_email_key") {
+ if IsUniqueConstraintError(err.Error(), []string{"Email", "users_email_key", "idx_users_email_unique"}) {
result.Err = model.NewLocAppError("SqlUserStore.Save", "store.sql_user.save.email_exists.app_error", nil, "user_id="+user.Id+", "+err.Error())
- } else if IsUniqueConstraintError(err.Error(), "Username", "users_username_key") {
+ } else if IsUniqueConstraintError(err.Error(), []string{"Username", "users_username_key", "idx_users_username_unique"}) {
result.Err = model.NewLocAppError("SqlUserStore.Save", "store.sql_user.save.username_exists.app_error", nil, "user_id="+user.Id+", "+err.Error())
} else {
result.Err = model.NewLocAppError("SqlUserStore.Save", "store.sql_user.save.app_error", nil, "user_id="+user.Id+", "+err.Error())
@@ -155,9 +155,9 @@ func (us SqlUserStore) Update(user *model.User, trustedUpdateData bool) StoreCha
}
if count, err := us.GetMaster().Update(user); err != nil {
- if IsUniqueConstraintError(err.Error(), "Email", "users_email_teamid_key") {
+ if IsUniqueConstraintError(err.Error(), []string{"Email", "users_email_key", "idx_users_email_unique"}) {
result.Err = model.NewLocAppError("SqlUserStore.Update", "store.sql_user.update.email_taken.app_error", nil, "user_id="+user.Id+", "+err.Error())
- } else if IsUniqueConstraintError(err.Error(), "Username", "users_username_teamid_key") {
+ } else if IsUniqueConstraintError(err.Error(), []string{"Username", "users_username_key", "idx_users_username_unique"}) {
result.Err = model.NewLocAppError("SqlUserStore.Update", "store.sql_user.update.username_taken.app_error", nil, "user_id="+user.Id+", "+err.Error())
} else {
result.Err = model.NewLocAppError("SqlUserStore.Update", "store.sql_user.update.updating.app_error", nil, "user_id="+user.Id+", "+err.Error())
diff --git a/utils/config.go b/utils/config.go
index e76cbed63..e4bcb0b85 100644
--- a/utils/config.go
+++ b/utils/config.go
@@ -285,7 +285,7 @@ func ValidateLdapFilter(cfg *model.Config) *model.AppError {
}
func Desanitize(cfg *model.Config) {
- if *cfg.LdapSettings.BindPassword == model.FAKE_SETTING {
+ if cfg.LdapSettings.BindPassword != nil && *cfg.LdapSettings.BindPassword == model.FAKE_SETTING {
*cfg.LdapSettings.BindPassword = *Cfg.LdapSettings.BindPassword
}