2024-03-11 01:25:15 +00:00
|
|
|
-- name: HasUser :one
|
2024-05-13 20:25:44 +01:00
|
|
|
SELECT count(subject) > 0 AS hasUser
|
2024-03-11 01:25:15 +00:00
|
|
|
FROM users;
|
|
|
|
|
|
|
|
-- name: addUser :exec
|
|
|
|
INSERT INTO users (subject, name, username, password, email, email_verified, role, updated_at, active)
|
|
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);
|
|
|
|
|
|
|
|
-- name: checkLogin :one
|
2024-05-13 20:25:44 +01:00
|
|
|
SELECT subject, name, password, EXISTS(SELECT 1 FROM otp WHERE otp.subject = users.subject) == 1 AS has_otp, email, email_verified
|
2024-03-11 01:25:15 +00:00
|
|
|
FROM users
|
|
|
|
WHERE username = ?
|
|
|
|
LIMIT 1;
|
|
|
|
|
|
|
|
-- name: GetUser :one
|
2024-03-11 12:39:52 +00:00
|
|
|
SELECT *
|
2024-03-11 01:25:15 +00:00
|
|
|
FROM users
|
|
|
|
WHERE subject = ?
|
|
|
|
LIMIT 1;
|
|
|
|
|
2024-03-11 12:39:52 +00:00
|
|
|
-- name: GetUserRole :one
|
|
|
|
SELECT role
|
|
|
|
FROM users
|
|
|
|
WHERE subject = ?;
|
|
|
|
|
|
|
|
-- name: GetUserDisplayName :one
|
|
|
|
SELECT name
|
|
|
|
FROM users
|
|
|
|
WHERE subject = ?;
|
|
|
|
|
2024-03-11 01:25:15 +00:00
|
|
|
-- name: getUserPassword :one
|
|
|
|
SELECT password
|
|
|
|
FROM users
|
|
|
|
WHERE subject = ?;
|
|
|
|
|
2024-03-12 21:04:25 +00:00
|
|
|
-- name: changeUserPassword :exec
|
2024-03-11 01:25:15 +00:00
|
|
|
UPDATE users
|
|
|
|
SET password = ?,
|
|
|
|
updated_at = ?
|
|
|
|
WHERE subject = ?
|
|
|
|
AND password = ?;
|
|
|
|
|
2024-03-12 21:04:25 +00:00
|
|
|
-- name: ModifyUser :exec
|
2024-03-11 01:25:15 +00:00
|
|
|
UPDATE users
|
|
|
|
SET name = ?,
|
|
|
|
picture = ?,
|
|
|
|
website=?,
|
|
|
|
pronouns=?,
|
|
|
|
birthdate=?,
|
|
|
|
zoneinfo=?,
|
|
|
|
locale=?,
|
|
|
|
updated_at=?
|
|
|
|
WHERE subject = ?;
|
|
|
|
|
2024-03-12 21:04:25 +00:00
|
|
|
-- name: SetOtp :exec
|
2024-03-11 01:25:15 +00:00
|
|
|
INSERT OR
|
|
|
|
REPLACE
|
|
|
|
INTO otp (subject, secret, digits)
|
|
|
|
VALUES (?, ?, ?);
|
|
|
|
|
2024-03-12 21:04:25 +00:00
|
|
|
-- name: DeleteOtp :exec
|
2024-03-11 01:25:15 +00:00
|
|
|
DELETE
|
|
|
|
FROM otp
|
|
|
|
WHERE otp.subject = ?;
|
|
|
|
|
2024-03-12 21:04:25 +00:00
|
|
|
-- name: GetOtp :one
|
2024-03-11 01:25:15 +00:00
|
|
|
SELECT secret, digits
|
|
|
|
FROM otp
|
|
|
|
WHERE subject = ?;
|
2024-03-11 12:39:52 +00:00
|
|
|
|
2024-03-12 21:04:25 +00:00
|
|
|
-- name: HasOtp :one
|
2024-05-13 20:25:44 +01:00
|
|
|
SELECT EXISTS(SELECT 1 FROM otp WHERE subject = ?) == 1 as hasOtp;
|
2024-03-12 21:04:25 +00:00
|
|
|
|
|
|
|
-- name: GetUserEmail :one
|
|
|
|
SELECT email
|
|
|
|
FROM users
|
|
|
|
WHERE subject = ?;
|