auth + creating identities

This commit is contained in:
2026-04-02 01:54:35 -04:00
parent 9f21716805
commit a7109505a2
7 changed files with 147 additions and 172 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"libshared"
"log"
"net/http"
"time"
@@ -73,7 +74,7 @@ func createLocalHandler(w http.ResponseWriter, r *http.Request) {
log.Println("Received Identity Request: AccountID:", accountid, "Username:", req.Username, "Password:", req.Password, "First Name:", req.FirstName, "LastName:", req.LastName)
// Check if policy with the same name already exists for the account
checkExisting = pool.QueryRow(context.Background(),
checkExisting = libshared.Pool.QueryRow(context.Background(),
"SELECT FROM identities WHERE accountid = $1 AND provider_user_id = $2",
accountid, req.Username)
err = checkExisting.Scan()
@@ -87,7 +88,7 @@ func createLocalHandler(w http.ResponseWriter, r *http.Request) {
salt, _ = generateSalt()
hashText = hashPassword(req.Password, salt)
_, err = pool.Exec(context.Background(),
_, err = libshared.Pool.Exec(context.Background(),
"INSERT INTO identities (accountid, provider, provider_user_id, password_hash) VALUES($1, $2, $3, $4) ON CONFLICT DO NOTHING",
accountid, "local", req.Username, hashText)
if err != nil {