update conflict resolution, in the right place

This commit is contained in:
slonkazoid 2024-12-29 22:48:54 +03:00
parent 659ef11451
commit 1f86eafc8a
Signed by: slonk
SSH key fingerprint: SHA256:tbZfJX4IOvZ0LGWOWu5Ijo8jfMPi78TU7x1VoEeCIjM

View file

@ -60,13 +60,13 @@ case "$action" in
exit
fi
{
query="SELECT password FROM users WHERE username=$(escape_sql_str "$username") ON CONFLICT (username) DO SET password=excluded.password"
query="SELECT password FROM users WHERE username=$(escape_sql_str "$username")"
row=$(db_row "$query")
if [[ "$row" == "null" ]]; then
hash=$(printf '%s' "$password" | argon2_hash)
echo "registering user $username" >&2
unset password
db_query "INSERT INTO users (username, password) VALUES ($(escape_sql_str "$username"), $(escape_sql_str "$hash"))" >&2
db_query "INSERT INTO users (username, password) VALUES ($(escape_sql_str "$username"), $(escape_sql_str "$hash")) ON CONFLICT (username) DO SET password=excluded.password" >&2
created=true
else