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/accounts_table.go similarity index 99% rename from src/github.com/matrix-org/dendrite/clientapi/auth/storage/accounts_table.go rename to src/github.com/matrix-org/dendrite/clientapi/auth/storage/accounts/accounts_table.go index 891fce5b..dc5b5196 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/accounts_table.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package storage +package accounts import ( "database/sql" diff --git a/src/github.com/matrix-org/dendrite/clientapi/auth/storage/storage.go b/src/github.com/matrix-org/dendrite/clientapi/auth/storage/accounts/storage.go similarity index 81% rename from src/github.com/matrix-org/dendrite/clientapi/auth/storage/storage.go rename to src/github.com/matrix-org/dendrite/clientapi/auth/storage/accounts/storage.go index 19bd3d93..bb08870c 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/auth/storage/storage.go +++ b/src/github.com/matrix-org/dendrite/clientapi/auth/storage/accounts/storage.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package storage +package accounts import ( "database/sql" @@ -23,14 +23,14 @@ import ( _ "github.com/lib/pq" ) -// AccountDatabase represents an account database -type AccountDatabase struct { +// Database represents an account database +type Database struct { db *sql.DB accounts accountsStatements } -// NewAccountDatabase creates a new accounts database -func NewAccountDatabase(dataSourceName string, serverName gomatrixserverlib.ServerName) (*AccountDatabase, error) { +// NewDatabase creates a new accounts database +func NewDatabase(dataSourceName string, serverName gomatrixserverlib.ServerName) (*Database, error) { var db *sql.DB var err error if db, err = sql.Open("postgres", dataSourceName); err != nil { @@ -40,12 +40,12 @@ func NewAccountDatabase(dataSourceName string, serverName gomatrixserverlib.Serv if err = a.prepare(db, serverName); err != nil { return nil, err } - return &AccountDatabase{db, a}, nil + return &Database{db, a}, nil } // GetAccountByPassword returns the account associated with the given localpart and password. // Returns sql.ErrNoRows if no account exists which matches the given credentials. -func (d *AccountDatabase) GetAccountByPassword(localpart, plaintextPassword string) (*types.Account, error) { +func (d *Database) GetAccountByPassword(localpart, plaintextPassword string) (*types.Account, error) { hash, err := d.accounts.selectPasswordHash(localpart) if err != nil { return nil, err @@ -58,7 +58,7 @@ func (d *AccountDatabase) GetAccountByPassword(localpart, plaintextPassword stri // CreateAccount makes a new account with the given login name and password. If no password is supplied, // the account will be a passwordless account. -func (d *AccountDatabase) CreateAccount(localpart, plaintextPassword string) (*types.Account, error) { +func (d *Database) CreateAccount(localpart, plaintextPassword string) (*types.Account, error) { hash, err := hashPassword(plaintextPassword) if err != nil { return nil, err diff --git a/src/github.com/matrix-org/dendrite/clientapi/auth/storage/devices/storage.go b/src/github.com/matrix-org/dendrite/clientapi/auth/storage/devices/storage.go new file mode 100644 index 00000000..842d6bbe --- /dev/null +++ b/src/github.com/matrix-org/dendrite/clientapi/auth/storage/devices/storage.go @@ -0,0 +1,25 @@ +// Copyright 2017 Vector Creations Ltd +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package devices + +// Database represents a device database. +type Database struct { + // TODO +} + +// NewDatabase creates a new device database +func NewDatabase() *Database { + return &Database{} +} diff --git a/src/github.com/matrix-org/dendrite/clientapi/auth/types/account.go b/src/github.com/matrix-org/dendrite/clientapi/auth/types/account.go index 3317d4d6..21b10e03 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/auth/types/account.go +++ b/src/github.com/matrix-org/dendrite/clientapi/auth/types/account.go @@ -24,6 +24,6 @@ type Account struct { Localpart string ServerName gomatrixserverlib.ServerName // TODO: Other flags like IsAdmin, IsGuest - // TODO: Device IDs + // TODO: Devices // TODO: Associations (e.g. with application services) } diff --git a/src/github.com/matrix-org/dendrite/clientapi/auth/types/device.go b/src/github.com/matrix-org/dendrite/clientapi/auth/types/device.go new file mode 100644 index 00000000..72352cde --- /dev/null +++ b/src/github.com/matrix-org/dendrite/clientapi/auth/types/device.go @@ -0,0 +1,23 @@ +// Copyright 2017 Vector Creations Ltd +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package types + +// Device represents a client's device (mobile, web, etc) +type Device struct { + ID string + UserID string + AccessToken string + // TODO: display name, last used timestamp, keys, etc +} 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 1a1a1bac..a2b9c31d 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 @@ -19,7 +19,7 @@ import ( "os" "strings" - "github.com/matrix-org/dendrite/clientapi/auth/storage" + "github.com/matrix-org/dendrite/clientapi/auth/storage/accounts" "github.com/matrix-org/dendrite/clientapi/config" "github.com/matrix-org/dendrite/clientapi/producers" "github.com/matrix-org/dendrite/clientapi/routing" @@ -81,7 +81,7 @@ func main() { } queryAPI := api.NewRoomserverQueryAPIHTTP(cfg.RoomserverURL, nil) - accountDB, err := storage.NewAccountDatabase(accountDataSource, serverName) + accountDB, err := accounts.NewDatabase(accountDataSource, serverName) if err != nil { log.Panicf("Failed to setup account database(%s): %s", accountDataSource, err.Error()) }