forked from scalableminds/webknossos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
105-verify-email.sql
35 lines (27 loc) · 1.54 KB
/
105-verify-email.sql
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
START TRANSACTION;
DROP VIEW webknossos.userInfos;
DROP VIEW webknossos.multiUsers_;
ALTER TABLE webknossos.multiusers ADD isEmailVerified BOOLEAN NOT NULL DEFAULT false;
CREATE TABLE webknossos.emailVerificationKeys(
_id CHAR(24) PRIMARY KEY,
key TEXT NOT NULL,
email VARCHAR(512) NOT NULL,
_multiUser CHAR(24) NOT NULL,
validUntil TIMESTAMPTZ,
isUsed BOOLEAN NOT NULL DEFAULT false
);
-- Set email verified for all currently registered users (only require email verification for new users)
UPDATE webknossos.multiUsers SET isEmailVerified = true;
-- Recreate views
CREATE VIEW webknossos.multiUsers_ AS SELECT * FROM webknossos.multiUsers WHERE NOT isDeleted;
CREATE VIEW webknossos.userInfos AS
SELECT
u._id AS _user, m.email, u.firstName, u.lastname, o.displayName AS organization_displayName,
u.isDeactivated, u.isDatasetManager, u.isAdmin, m.isSuperUser,
u._organization, o.name AS organization_name, u.created AS user_created,
m.created AS multiuser_created, u._multiUser, m._lastLoggedInIdentity, u.lastActivity, m.isEmailVerified
FROM webknossos.users_ u
JOIN webknossos.organizations_ o ON u._organization = o._id
JOIN webknossos.multiUsers_ m on u._multiUser = m._id;
UPDATE webknossos.releaseInformation SET schemaVersion = 105;
COMMIT TRANSACTION;