nie wiedzieju

This commit is contained in:
GitProtogen
2026-03-18 12:07:29 +01:00
parent d3fc2a65d9
commit da5f87d67b
6 changed files with 36 additions and 19 deletions
+14 -14
View File
@@ -4,7 +4,6 @@ import (
"context"
"github.com/jackc/pgx/v5"
"golang.org/x/crypto/bcrypt"
)
var dbConn *pgx.Conn
@@ -46,23 +45,24 @@ func InitDatabase(ctx context.Context) {
dbConn = conn
}
func SaveClientWithoutGroups(ctx context.Context, client *Client) error {
func DbSaveClientWithoutGroups(ctx context.Context, client *Client) error {
var id uint64
var err error
var hashed []byte
hashed, err = bcrypt.GenerateFromPassword([]byte(client.PasswordHash), bcrypt.DefaultCost)
err = dbConn.QueryRow(ctx, `
INSERT INTO users (name, pass_hash, pronouns)
VALUES ($1, $2, $3)
RETURNING id
`, client.Name, client.PasswordHash, client.Pronouns).Scan(&id)
return err
}
func DbGetClient(ctx context.Context, id uint32, client *Client) error {
err := dbConn.QueryRow(ctx, `
SELECT name, pass_hash, pronouns, color WHERE id = $1
`, id).Scan(client.Name, client.PasswordHash, client.Pronouns, client.Color)
if err != nil {
return err
}
password := string(hashed)
c := string(client.Color[:])
err = dbConn.QueryRow(ctx, `
INSERT INTO users (name, pass_hash, pronouns, color)
VALUES ($1, $2, $3)
RETURNING id
`, client.Name, password, client.Pronouns, c).Scan(&id)
return err
return nil
}