From 542fb36ae1d23b751709eeb889de98b69de05367 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Fri, 19 May 2017 17:46:22 +0100 Subject: [PATCH] Make it actually work --- .../dendrite/clientapi/auth/storage/accounts_table.go | 6 +++--- .../matrix-org/dendrite/clientapi/auth/storage/storage.go | 2 ++ .../dendrite/cmd/dendrite-client-api-server/main.go | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/github.com/matrix-org/dendrite/clientapi/auth/storage/accounts_table.go b/src/github.com/matrix-org/dendrite/clientapi/auth/storage/accounts_table.go index 94c452e15..891fce5bc 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/auth/storage/accounts_table.go +++ b/src/github.com/matrix-org/dendrite/clientapi/auth/storage/accounts_table.go @@ -41,10 +41,10 @@ const insertAccountSQL = "" + "INSERT INTO accounts(localpart, created_ts, password_hash) VALUES ($1, $2, $3)" const selectAccountByLocalpartSQL = "" + - "SELECT localpart WHERE localpart = $1" + "SELECT localpart FROM accounts WHERE localpart = $1" const selectPasswordHashSQL = "" + - "SELECT password_hash WHERE localpart = $1" + "SELECT password_hash FROM accounts WHERE localpart = $1" // TODO: Update password @@ -78,7 +78,7 @@ func (s *accountsStatements) prepare(db *sql.DB, server gomatrixserverlib.Server // on success. func (s *accountsStatements) insertAccount(localpart, hash string) (acc *types.Account, err error) { createdTimeMS := time.Now().UnixNano() / 1000000 - if _, err = s.insertAccountStmt.Exec(localpart, createdTimeMS, hash); err != nil { + if _, err = s.insertAccountStmt.Exec(localpart, createdTimeMS, hash); err == nil { acc = &types.Account{ Localpart: localpart, UserID: makeUserID(localpart, s.serverName), diff --git a/src/github.com/matrix-org/dendrite/clientapi/auth/storage/storage.go b/src/github.com/matrix-org/dendrite/clientapi/auth/storage/storage.go index 22001ca8a..19bd3d93f 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/auth/storage/storage.go +++ b/src/github.com/matrix-org/dendrite/clientapi/auth/storage/storage.go @@ -19,6 +19,8 @@ import ( "github.com/matrix-org/dendrite/clientapi/auth/types" "github.com/matrix-org/gomatrixserverlib" "golang.org/x/crypto/bcrypt" + // Import the postgres database driver. + _ "github.com/lib/pq" ) // AccountDatabase represents an account database diff --git a/src/github.com/matrix-org/dendrite/cmd/dendrite-client-api-server/main.go b/src/github.com/matrix-org/dendrite/cmd/dendrite-client-api-server/main.go index f2dbcfabb..1a1a1bac1 100644 --- a/src/github.com/matrix-org/dendrite/cmd/dendrite-client-api-server/main.go +++ b/src/github.com/matrix-org/dendrite/cmd/dendrite-client-api-server/main.go @@ -81,7 +81,7 @@ func main() { } queryAPI := api.NewRoomserverQueryAPIHTTP(cfg.RoomserverURL, nil) - accountDB, err := storage.NewAccountDatabase("", serverName) + accountDB, err := storage.NewAccountDatabase(accountDataSource, serverName) if err != nil { log.Panicf("Failed to setup account database(%s): %s", accountDataSource, err.Error()) }