summaryrefslogtreecommitdiffstats
path: root/model/user.go
diff options
context:
space:
mode:
authorCorey Hulen <corey@hulen.com>2016-05-11 11:04:30 -0700
committerChristopher Speller <crspeller@gmail.com>2016-05-11 14:04:30 -0400
commit3928535456f9fcb025ed86edeb4d258f2c524150 (patch)
tree010f4bd298f23b92711affcdef81cc329c522e67 /model/user.go
parenta574397a7256bed7738f499019f97ab468b5161d (diff)
downloadchat-3928535456f9fcb025ed86edeb4d258f2c524150.tar.gz
chat-3928535456f9fcb025ed86edeb4d258f2c524150.tar.bz2
chat-3928535456f9fcb025ed86edeb4d258f2c524150.zip
PLT-2905 fixing upgrade of SSO accounts (#2962)
* PLT-2905 fixing upgrade of SSO accounts * Fixing multiple Auths mapped to different emails
Diffstat (limited to 'model/user.go')
-rw-r--r--model/user.go27
1 files changed, 19 insertions, 8 deletions
diff --git a/model/user.go b/model/user.go
index 7563de8ae..15c281401 100644
--- a/model/user.go
+++ b/model/user.go
@@ -37,7 +37,7 @@ type User struct {
DeleteAt int64 `json:"delete_at"`
Username string `json:"username"`
Password string `json:"password,omitempty"`
- AuthData string `json:"auth_data,omitempty"`
+ AuthData *string `json:"auth_data,omitempty"`
AuthService string `json:"auth_service"`
Email string `json:"email"`
EmailVerified bool `json:"email_verified,omitempty"`
@@ -99,15 +99,15 @@ func (u *User) IsValid() *AppError {
return NewLocAppError("User.IsValid", "model.user.is_valid.pwd.app_error", nil, "user_id="+u.Id)
}
- if len(u.AuthData) > 128 {
+ if u.AuthData != nil && len(*u.AuthData) > 128 {
return NewLocAppError("User.IsValid", "model.user.is_valid.auth_data.app_error", nil, "user_id="+u.Id)
}
- if len(u.AuthData) > 0 && len(u.AuthService) == 0 {
+ if u.AuthData != nil && len(*u.AuthData) > 0 && len(u.AuthService) == 0 {
return NewLocAppError("User.IsValid", "model.user.is_valid.auth_data_type.app_error", nil, "user_id="+u.Id)
}
- if len(u.Password) > 0 && len(u.AuthData) > 0 {
+ if len(u.Password) > 0 && u.AuthData != nil && len(*u.AuthData) > 0 {
return NewLocAppError("User.IsValid", "model.user.is_valid.auth_data_pwd.app_error", nil, "user_id="+u.Id)
}
@@ -130,6 +130,10 @@ func (u *User) PreSave() {
u.Username = NewId()
}
+ if u.AuthData != nil && *u.AuthData == "" {
+ u.AuthData = nil
+ }
+
u.Username = strings.ToLower(u.Username)
u.Email = strings.ToLower(u.Email)
u.Locale = strings.ToLower(u.Locale)
@@ -165,6 +169,10 @@ func (u *User) PreUpdate() {
u.Locale = strings.ToLower(u.Locale)
u.UpdateAt = GetMillis()
+ if u.AuthData != nil && *u.AuthData == "" {
+ u.AuthData = nil
+ }
+
if u.NotifyProps == nil || len(u.NotifyProps) == 0 {
u.SetDefaultNotifications()
} else if _, ok := u.NotifyProps["mention_keys"]; ok {
@@ -237,7 +245,8 @@ func (u *User) IsAway() bool {
// Remove any private data from the user object
func (u *User) Sanitize(options map[string]bool) {
u.Password = ""
- u.AuthData = ""
+ u.AuthData = new(string)
+ *u.AuthData = ""
u.MfaSecret = ""
if len(options) != 0 && !options["email"] {
@@ -255,7 +264,8 @@ func (u *User) Sanitize(options map[string]bool) {
func (u *User) ClearNonProfileFields() {
u.UpdateAt = 0
u.Password = ""
- u.AuthData = ""
+ u.AuthData = new(string)
+ *u.AuthData = ""
u.AuthService = ""
u.MfaActive = false
u.MfaSecret = ""
@@ -376,7 +386,8 @@ func (u *User) IsLDAPUser() bool {
func (u *User) PreExport() {
u.Password = ""
- u.AuthData = ""
+ u.AuthData = new(string)
+ *u.AuthData = ""
u.LastActivityAt = 0
u.LastPingAt = 0
u.LastPasswordUpdate = 0
@@ -429,7 +440,7 @@ func HashPassword(password string) string {
// ComparePassword compares the hash
func ComparePassword(hash string, password string) bool {
- if len(password) == 0 {
+ if len(password) == 0 || len(hash) == 0 {
return false
}