Skip to content

Commit

Permalink
Update user login time on password login.
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Oct 26, 2024
1 parent 5b3d6e2 commit 178fa94
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1180,10 +1180,11 @@ SELECT username, password FROM users WHERE status='enabled' AND type='api';
-- name: login-user
WITH u AS (
SELECT users.*, r.name as role_name, r.permissions FROM users
LEFT JOIN roles r ON (r.id = users.user_role_id)
WHERE username=$1 AND status != 'disabled' AND password_login = TRUE
LEFT JOIN roles r ON (r.id = users.user_role_id)
WHERE username = $1 AND status != 'disabled' AND password_login = TRUE
AND CRYPT($2, password) = password
)
SELECT * FROM u WHERE CRYPT($2, password) = password;
UPDATE users SET loggedin_at = NOW() WHERE id = (SELECT id FROM u) RETURNING *;

-- name: update-user-profile
UPDATE users SET name=$2, email=(CASE WHEN password_login THEN $3 ELSE email END),
Expand Down

0 comments on commit 178fa94

Please sign in to comment.