nie wiedzieju
This commit is contained in:
+14
-14
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user