2024-05-17 21:40:31 +01:00
|
|
|
-- name: HasUser :one
|
|
|
|
SELECT count(subject) > 0 AS hasUser
|
|
|
|
FROM users;
|
|
|
|
|
2024-09-02 22:54:03 +01:00
|
|
|
-- name: addUser :exec
|
2024-10-05 21:08:02 +01:00
|
|
|
INSERT INTO users (subject, password, email, email_verified, updated_at, registered, active, name, login, change_password, auth_type, auth_namespace, auth_user)
|
|
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
|
2024-09-13 15:31:40 +01:00
|
|
|
|
2024-09-02 22:54:03 +01:00
|
|
|
-- name: checkLogin :one
|
2024-10-06 21:30:39 +01:00
|
|
|
SELECT subject, password, need_factor, email, email_verified
|
2024-05-17 21:40:31 +01:00
|
|
|
FROM users
|
2024-09-02 22:54:03 +01:00
|
|
|
WHERE users.subject = ?
|
|
|
|
LIMIT 1;
|
2024-05-17 21:40:31 +01:00
|
|
|
|
|
|
|
-- name: GetUser :one
|
|
|
|
SELECT *
|
|
|
|
FROM users
|
|
|
|
WHERE subject = ?
|
|
|
|
LIMIT 1;
|
|
|
|
|
2024-09-02 22:54:03 +01:00
|
|
|
-- name: GetUserRoles :many
|
|
|
|
SELECT r.role
|
|
|
|
FROM users_roles
|
|
|
|
INNER JOIN roles r on r.id = users_roles.role_id
|
|
|
|
INNER JOIN users u on u.id = users_roles.user_id
|
|
|
|
WHERE u.subject = ?;
|
2024-05-17 21:40:31 +01:00
|
|
|
|
2024-09-13 15:31:40 +01:00
|
|
|
-- name: UserHasRole :exec
|
2024-09-02 22:54:03 +01:00
|
|
|
SELECT 1
|
|
|
|
FROM roles
|
|
|
|
INNER JOIN users_roles on users_roles.user_id = roles.id
|
|
|
|
INNER JOIN users u on u.id = users_roles.user_id = u.id
|
|
|
|
WHERE roles.role = ?
|
|
|
|
AND u.subject = ?;
|
2024-05-17 21:40:31 +01:00
|
|
|
|
2024-09-02 22:54:03 +01:00
|
|
|
-- name: getUserPassword :one
|
|
|
|
SELECT password
|
2024-05-17 21:40:31 +01:00
|
|
|
FROM users
|
|
|
|
WHERE subject = ?;
|
2024-09-02 22:54:03 +01:00
|
|
|
|
|
|
|
-- name: changeUserPassword :exec
|
|
|
|
UPDATE users
|
|
|
|
SET password = ?,
|
|
|
|
updated_at=?
|
|
|
|
WHERE subject = ?
|
|
|
|
AND password = ?;
|
2024-10-05 21:08:02 +01:00
|
|
|
|
|
|
|
-- name: FlagUserAsDeleted :exec
|
|
|
|
UPDATE users
|
|
|
|
SET active= false,
|
|
|
|
to_delete = true
|
|
|
|
WHERE subject = ?;
|
2024-10-06 15:50:23 +01:00
|
|
|
|
|
|
|
-- name: FindUserByAuth :one
|
|
|
|
SELECT subject
|
|
|
|
FROM users
|
|
|
|
WHERE auth_type = ?
|
|
|
|
AND auth_namespace = ?
|
|
|
|
AND auth_user = ?;
|