mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-17 20:03:10 -06:00
Update postgres
This commit is contained in:
parent
abacc13a76
commit
21904bc2cf
|
|
@ -146,8 +146,12 @@ func (s *accountsStatements) selectAccountByLocalpart(
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *accountsStatements) selectNewNumericLocalpart(
|
func (s *accountsStatements) selectNewNumericLocalpart(
|
||||||
ctx context.Context,
|
ctx context.Context, txn *sql.Tx,
|
||||||
) (id int64, err error) {
|
) (id int64, err error) {
|
||||||
err = s.selectNewNumericLocalpartStmt.QueryRowContext(ctx).Scan(&id)
|
stmt := s.selectNewNumericLocalpartStmt
|
||||||
|
if txn != nil {
|
||||||
|
stmt = txn.Stmt(stmt)
|
||||||
|
}
|
||||||
|
err = stmt.QueryRowContext(ctx).Scan(&id)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
||||||
"github.com/matrix-org/dendrite/common"
|
"github.com/matrix-org/dendrite/common"
|
||||||
|
|
@ -118,8 +119,19 @@ func (d *Database) SetDisplayName(
|
||||||
return d.profiles.setDisplayName(ctx, localpart, displayName)
|
return d.profiles.setDisplayName(ctx, localpart, displayName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Database) CreateGuestAccount(ctx context.Context) (*authtypes.Account, error) {
|
// CreateGuestAccount makes a new guest account and creates an empty profile
|
||||||
return nil, nil
|
// for this account.
|
||||||
|
func (d *Database) CreateGuestAccount(ctx context.Context) (acc *authtypes.Account, err error) {
|
||||||
|
err = common.WithTransaction(d.db, func(txn *sql.Tx) error {
|
||||||
|
numLocalpart, err := d.accounts.selectNewNumericLocalpart(ctx, txn)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
localpart := strconv.FormatInt(numLocalpart, 10)
|
||||||
|
acc, err = d.createAccount(ctx, txn, localpart, "", "")
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
return acc, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateAccount makes a new account with the given login name and password, and creates an empty profile
|
// CreateAccount makes a new account with the given login name and password, and creates an empty profile
|
||||||
|
|
@ -127,6 +139,16 @@ func (d *Database) CreateGuestAccount(ctx context.Context) (*authtypes.Account,
|
||||||
// account already exists, it will return nil, nil.
|
// account already exists, it will return nil, nil.
|
||||||
func (d *Database) CreateAccount(
|
func (d *Database) CreateAccount(
|
||||||
ctx context.Context, localpart, plaintextPassword, appserviceID string,
|
ctx context.Context, localpart, plaintextPassword, appserviceID string,
|
||||||
|
) (acc *authtypes.Account, err error) {
|
||||||
|
err = common.WithTransaction(d.db, func(txn *sql.Tx) error {
|
||||||
|
acc, err = d.createAccount(ctx, txn, localpart, plaintextPassword, appserviceID)
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Database) createAccount(
|
||||||
|
ctx context.Context, txn *sql.Tx, localpart, plaintextPassword, appserviceID string,
|
||||||
) (*authtypes.Account, error) {
|
) (*authtypes.Account, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
|
@ -292,7 +314,7 @@ func (d *Database) GetAccountDataByType(
|
||||||
func (d *Database) GetNewNumericLocalpart(
|
func (d *Database) GetNewNumericLocalpart(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
) (int64, error) {
|
) (int64, error) {
|
||||||
return d.accounts.selectNewNumericLocalpart(ctx)
|
return d.accounts.selectNewNumericLocalpart(ctx, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func hashPassword(plaintext string) (hash string, err error) {
|
func hashPassword(plaintext string) (hash string, err error) {
|
||||||
|
|
|
||||||
|
|
@ -119,6 +119,8 @@ func (d *Database) SetDisplayName(
|
||||||
return d.profiles.setDisplayName(ctx, localpart, displayName)
|
return d.profiles.setDisplayName(ctx, localpart, displayName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateGuestAccount makes a new guest account and creates an empty profile
|
||||||
|
// for this account.
|
||||||
func (d *Database) CreateGuestAccount(ctx context.Context) (acc *authtypes.Account, err error) {
|
func (d *Database) CreateGuestAccount(ctx context.Context) (acc *authtypes.Account, err error) {
|
||||||
err = common.WithTransaction(d.db, func(txn *sql.Tx) error {
|
err = common.WithTransaction(d.db, func(txn *sql.Tx) error {
|
||||||
numLocalpart, err := d.accounts.selectNewNumericLocalpart(ctx, txn)
|
numLocalpart, err := d.accounts.selectNewNumericLocalpart(ctx, txn)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue