add working signup + login

This commit is contained in:
sam 2023-09-04 03:33:13 +02:00
parent bc85b7c340
commit d8cb8c8fa8
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
27 changed files with 600 additions and 39 deletions

View file

@ -37,8 +37,13 @@ func (s *AccountStore) ByID(ctx context.Context, id ulid.ULID) (a database.Accou
}
// ByUsername gets an account by its username.
func (s *AccountStore) ByUsername(ctx context.Context, username string, host *string) (a database.Account, err error) {
q := sqlf.Sprintf("SELECT * FROM accounts WHERE username = %s AND host = %v", username, host)
func (s *AccountStore) ByUsername(ctx context.Context, username, domain string) (a database.Account, err error) {
q := sqlf.Sprintf("SELECT * FROM accounts WHERE username = %s", username)
if domain == "" {
q = sqlf.Sprintf("%v AND domain IS NULL", q)
} else {
q = sqlf.Sprintf("%v AND domain = %s", q, domain)
}
a, err = Get[database.Account](ctx, s.q, q)
if err != nil {
@ -64,7 +69,7 @@ func (s *AccountStore) CreateLocal(
}
q := sqlf.Sprintf(
"INSERT INTO accounts (id, username, host, email, password) VALUES (%s, %v, NULL, %v, %v) RETURNING *",
"INSERT INTO accounts (id, username, domain, email, password) VALUES (%s, %v, NULL, %v, %v) RETURNING *",
makeULID(), username, email, hash)
a, err = Get[database.Account](ctx, s.q, q)