This commit is contained in:
Brendan Abolivier 2017-07-07 11:45:42 +01:00
parent a765352d16
commit 89b792cfad
No known key found for this signature in database
GPG key ID: 8EF1500759F70623
2 changed files with 12 additions and 3 deletions

View file

@ -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 {

View file

@ -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 {