Support email verification.
The bulk of this commit is auto-modifying files to export variables (mostly our
request error types and our response type) so that they can be reused in a Go
client for that API.
We also implement the beginnings of a Go client for that API, implementing the
bare minimum we need for our immediate purposes: the ability to retrieve
information about a Login.
This, of course, means we need an API endpoint that will return information
about a Login, which in turn required us to implement a GetLogin method in our
profileStore. Which got in-memory and postgres implementations.
That done, we could add the Verification field and Verified field to the Login
type, to keep track of whether we've verified the user's ownership of those
communication methods (if the Login is, in fact, a communication method). This
required us to update sql/postgres_init.sql to account for the new fields we're
tracking. It also means that when creating a Login, we had to generate a UUID to
use as the Verification field.
To make things complete, we needed a verifyLogin method on the profileStore to
mark a Login as verified. That, in turn, required an endpoint to control this
through the API. While doing so, I lumped things together in an UpdateLogin
handler just so we could reuse the endpoint and logic when resending a
verification email that may have never reached the user, for whatever reason
(the quintessential "send again" button).
Finally, we implemented an email_verification listener that will pull
email_verification events off NSQ, check for the requisite data integrity, and
use mailgun to email out a verification/welcome email.
1 CREATE TABLE IF NOT EXISTS profiles (
2 id VARCHAR(36) PRIMARY KEY,
3 name VARCHAR(64) NOT NULL,
4 passphrase VARCHAR(64) NOT NULL,
5 iterations INTEGER NOT NULL,
6 salt VARCHAR(64) NOT NULL,
7 passphrase_scheme INTEGER NOT NULL,
8 compromised BOOLEAN NOT NULL,
9 locked_until TIMESTAMPTZ NOT NULL,
10 passphrase_reset VARCHAR(64) NOT NULL,
11 passphrase_reset_created TIMESTAMPTZ NOT NULL,
12 created TIMESTAMPTZ NOT NULL,
13 last_seen TIMESTAMPTZ NOT NULL
16 CREATE TABLE IF NOT EXISTS logins (
17 type VARCHAR(16) NOT NULL,
18 value VARCHAR(64) PRIMARY KEY,
19 profile_id VARCHAR(36) NOT NULL,
20 created TIMESTAMPTZ NOT NULL,
21 last_used TIMESTAMPTZ NOT NULL,
22 verification VARCHAR(36) NOT NULL,
23 verified BOOLEAN NOT NULL
26 CREATE TABLE IF NOT EXISTS clients (
27 id VARCHAR(36) PRIMARY KEY,
28 secret VARCHAR(64) NOT NULL,
29 owner_id VARCHAR(36) NOT NULL,
30 name VARCHAR(32) NOT NULL,
31 logo VARCHAR(512) NOT NULL,
32 website VARCHAR(140) NOT NULL,
33 type VARCHAR(16) NOT NULL,
34 deleted BOOLEAN NOT NULL
37 CREATE TABLE IF NOT EXISTS endpoints (
38 id VARCHAR(36) PRIMARY KEY,
39 client_id VARCHAR(36) NOT NULL,
40 uri VARCHAR(512) NOT NULL,
41 normalized_uri VARCHAR(512) NOT NULL,
42 added TIMESTAMPTZ NOT NULL
45 CREATE TABLE IF NOT EXISTS scopes (
46 id VARCHAR(64) PRIMARY KEY,
47 name VARCHAR(64) NOT NULL,
48 description TEXT NOT NULL
51 CREATE TABLE IF NOT EXISTS sessions (
52 id VARCHAR(72) PRIMARY KEY,
53 ip VARCHAR(32) NOT NULL,
54 user_agent TEXT NOT NULL,
55 profile_id VARCHAR(36) NOT NULL,
56 login VARCHAR(64) NOT NULL,
57 created TIMESTAMPTZ NOT NULL,
58 expires TIMESTAMPTZ NOT NULL,
59 active BOOLEAN NOT NULL,
60 csrftoken VARCHAR(72) NOT NULL
63 CREATE TABLE IF NOT EXISTS tokens (
64 access_token TEXT PRIMARY KEY,
65 refresh_token VARCHAR(36) UNIQUE NOT NULL,
66 created TIMESTAMPTZ NOT NULL,
67 created_from VARCHAR(128) NOT NULL,
68 expires_in INTEGER NOT NULL,
69 token_type VARCHAR(64) NOT NULL,
70 profile_id VARCHAR(36) NOT NULL,
71 client_id VARCHAR(36) NOT NULL,
72 revoked BOOLEAN NOT NULL,
73 scopes varchar(64)[] NOT NULL
76 CREATE TABLE IF NOT EXISTS authorization_codes (
77 code VARCHAR(36) PRIMARY KEY,
78 created TIMESTAMPTZ NOT NULL,
79 expires_in INTEGER NOT NULL,
80 client_id VARCHAR(36) NOT NULL,
81 redirect_uri TEXT NOT NULL,
83 profile_id VARCHAR(36) NOT NULL,
84 used BOOLEAN NOT NULL,
85 scopes varchar(64)[] NOT NULL