-
Notifications
You must be signed in to change notification settings - Fork 2
/
supervisor_credentials.go
69 lines (61 loc) · 1.68 KB
/
supervisor_credentials.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*-
* Copyright (c) 2016, Jörg Pernfuß <joerg.pernfuss@1und1.de>
* All rights reserved
*
* Use of this source code is governed by a 2-clause BSD license
* that can be found in the LICENSE file.
*/
package stmt
const LoadAllUserCredentials = `
SELECT aua.user_id,
aua.crypt,
aua.reset_pending,
aua.valid_from,
aua.valid_until,
iu.user_uid
FROM inventory.users iu
JOIN auth.user_authentication aua
ON iu.user_id = aua.user_id
WHERE iu.user_id != '00000000-0000-0000-0000-000000000000'::uuid
AND NOW() < aua.valid_until
AND NOT iu.user_is_deleted
AND iu.user_is_active;`
const FindUserID = `
SELECT user_id
FROM inventory.users
WHERE user_uid = $1::varchar
AND NOT user_is_deleted;`
const CheckUserActive = `
SELECT user_is_active
FROM inventory.users
WHERE user_id = $1::uuid
AND NOT user_is_deleted;`
const SetUserCredential = `
INSERT INTO auth.user_authentication (
user_id,
crypt,
reset_pending,
valid_from,
valid_until
) VALUES (
$1::uuid,
$2::text,
'no'::boolean,
$3::timestamptz,
$4::timestamptz
);`
const ActivateUser = `
UPDATE inventory.users
SET user_is_active = 'yes'::boolean
WHERE user_id = $1::uuid;`
const InvalidateUserCredential = `
UPDATE auth.user_authentication aua
SET valid_until = $1::timestamptz
FROM inventory.users iu
WHERE aua.user_id = iu.user_id
AND aua.user_id = $2::uuid
AND NOW() < aua.valid_until
AND iu.user_is_active = 'yes'::boolean
AND NOT iu.user_is_deleted
AND iu.user_id != '00000000-0000-0000-0000-000000000000';`
// vim: ts=4 sw=4 sts=4 noet fenc=utf-8 ffs=unix