diff --git a/src/github.com/matrix-org/dendrite/clientapi/auth/storage/accounts/storage.go b/src/github.com/matrix-org/dendrite/clientapi/auth/storage/accounts/storage.go index 7317721d0..cd6abc09a 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/auth/storage/accounts/storage.go +++ b/src/github.com/matrix-org/dendrite/clientapi/auth/storage/accounts/storage.go @@ -31,7 +31,7 @@ type Database struct { profiles profilesStatements } -// NewDatabase creates a new accounts database +// NewDatabase creates a new accounts and profiles database func NewDatabase(dataSourceName string, serverName gomatrixserverlib.ServerName) (*Database, error) { var db *sql.DB var err error @@ -62,20 +62,26 @@ func (d *Database) GetAccountByPassword(localpart, plaintextPassword string) (*a return d.accounts.selectAccountByLocalpart(localpart) } +// GetProfileByLocalpart returns the profile associated with the given localpart. +// Returns sql.ErrNoRows if no profile exists which matches the given localpart. func (d *Database) GetProfileByLocalpart(localpart string) (*authtypes.Profile, error) { return d.profiles.selectProfileByLocalpart(localpart) } +// SetAvatarURL updates the avatar URL of the profile associated with the given +// localpart. Returns an error if something went wrong with the SQL query func (d *Database) SetAvatarURL(localpart string, avatarURL string) error { return d.profiles.setAvatarURL(localpart, avatarURL) } +// SetDisplayName updates the display name of the profile associated with the given +// localpart. Returns an error if something went wrong with the SQL query func (d *Database) SetDisplayName(localpart string, displayName string) error { return d.profiles.setDisplayName(localpart, displayName) } -// CreateAccount makes a new account with the given login name and password. If no password is supplied, -// the account will be a passwordless account. +// CreateAccount makes a new account with the given login name and password, and creates an empty profile +// for this account. If no password is supplied, the account will be a passwordless account. func (d *Database) CreateAccount(localpart, plaintextPassword string) (*authtypes.Account, error) { hash, err := hashPassword(plaintextPassword) if err != nil { diff --git a/src/github.com/matrix-org/dendrite/clientapi/readers/profile.go b/src/github.com/matrix-org/dendrite/clientapi/readers/profile.go index d854e0be9..65e4dca10 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/readers/profile.go +++ b/src/github.com/matrix-org/dendrite/clientapi/readers/profile.go @@ -39,6 +39,7 @@ type displayName struct { DisplayName string `json:"displayname"` } +// GetProfile implements GET /profile/{userID} func GetProfile( req *http.Request, accountDB *accounts.Database, userID string, ) util.JSONResponse { @@ -66,6 +67,7 @@ func GetProfile( } } +// AvatarURL implements GET and PUT /profile/{userID}/avatar_url func AvatarURL( req *http.Request, accountDB *accounts.Database, userID string, ) util.JSONResponse { @@ -115,6 +117,7 @@ func AvatarURL( } } +// DisplayName implements GET and PUT /profile/{userID}/displayname func DisplayName( req *http.Request, accountDB *accounts.Database, userID string, ) util.JSONResponse {