diff options
author | =Corey Hulen <corey@hulen.com> | 2015-08-02 09:41:12 -0800 |
---|---|---|
committer | =Corey Hulen <corey@hulen.com> | 2015-08-02 09:41:12 -0800 |
commit | 247708d924770737a3c03f956b19d8096da2bdea (patch) | |
tree | 3d6bd381545e660808f74a1379048e57cc0c6717 /store/sql_user_store.go | |
parent | e76fc37b6df7d53ea86a5b42009d5d1161741270 (diff) | |
parent | 718d670d699e295fcad903d507bc989c51a1ef50 (diff) | |
download | chat-247708d924770737a3c03f956b19d8096da2bdea.tar.gz chat-247708d924770737a3c03f956b19d8096da2bdea.tar.bz2 chat-247708d924770737a3c03f956b19d8096da2bdea.zip |
Merge branch 'master' into mm-1619
Diffstat (limited to 'store/sql_user_store.go')
-rw-r--r-- | store/sql_user_store.go | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/store/sql_user_store.go b/store/sql_user_store.go index 552d12843..cd25b488b 100644 --- a/store/sql_user_store.go +++ b/store/sql_user_store.go @@ -59,6 +59,8 @@ func (us SqlUserStore) UpgradeSchemaIfNeeded() { } us.CreateColumnIfNotExists("Users", "AuthService", "AuthData", "varchar(32)", "") // for OAuth Client + + us.CreateColumnIfNotExists("Users", "FailedAttempts", "LastPictureUpdate", "int(11)", "0") } //func (ss SqlStore) CreateColumnIfNotExists(tableName string, columnName string, afterName string, colType string, defaultValue string) bool { @@ -150,6 +152,7 @@ func (us SqlUserStore) Update(user *model.User, allowActiveUpdate bool) StoreCha user.LastActivityAt = oldUser.LastActivityAt user.LastPingAt = oldUser.LastPingAt user.EmailVerified = oldUser.EmailVerified + user.FailedAttempts = oldUser.FailedAttempts if !allowActiveUpdate { user.Roles = oldUser.Roles @@ -271,7 +274,7 @@ func (us SqlUserStore) UpdatePassword(userId, hashedPassword string) StoreChanne updateAt := model.GetMillis() - if _, err := us.GetMaster().Exec("UPDATE Users SET Password = :Password, LastPasswordUpdate = :LastPasswordUpdate, UpdateAt = :UpdateAt WHERE Id = :UserId", map[string]interface{}{"Password": hashedPassword, "LastPasswordUpdate": updateAt, "UpdateAt": updateAt, "UserId": userId}); err != nil { + if _, err := us.GetMaster().Exec("UPDATE Users SET Password = :Password, LastPasswordUpdate = :LastPasswordUpdate, UpdateAt = :UpdateAt, FailedAttempts = 0 WHERE Id = :UserId", map[string]interface{}{"Password": hashedPassword, "LastPasswordUpdate": updateAt, "UpdateAt": updateAt, "UserId": userId}); err != nil { result.Err = model.NewAppError("SqlUserStore.UpdatePassword", "We couldn't update the user password", "id="+userId+", "+err.Error()) } else { result.Data = userId @@ -284,6 +287,25 @@ func (us SqlUserStore) UpdatePassword(userId, hashedPassword string) StoreChanne return storeChannel } +func (us SqlUserStore) UpdateFailedPasswordAttempts(userId string, attempts int) StoreChannel { + storeChannel := make(StoreChannel) + + go func() { + result := StoreResult{} + + if _, err := us.GetMaster().Exec("UPDATE Users SET FailedAttempts = :FailedAttempts WHERE Id = :UserId", map[string]interface{}{"FailedAttempts": attempts, "UserId": userId}); err != nil { + result.Err = model.NewAppError("SqlUserStore.UpdateFailedPasswordAttempts", "We couldn't update the failed_attempts", "user_id="+userId) + } else { + result.Data = userId + } + + storeChannel <- result + close(storeChannel) + }() + + return storeChannel +} + func (us SqlUserStore) Get(id string) StoreChannel { storeChannel := make(StoreChannel) |