feat: add api server
This commit is contained in:
@@ -2,7 +2,7 @@ CREATE EXTENSION IF NOT EXISTS pgcrypto;
|
|||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS public."user" (
|
CREATE TABLE IF NOT EXISTS public."user" (
|
||||||
id text NOT NULL,
|
id text NOT NULL,
|
||||||
identifier text UNIQUE NOT NULL DEFAULT substr(encode(gen_random_bytes(16), 'hex'), 1, 32),
|
ssh_identifier text UNIQUE NOT NULL DEFAULT substr(encode(gen_random_bytes(16), 'hex'), 1, 32),
|
||||||
name text NOT NULL,
|
name text NOT NULL,
|
||||||
email text NOT NULL,
|
email text NOT NULL,
|
||||||
email_verified boolean DEFAULT false NOT NULL,
|
email_verified boolean DEFAULT false NOT NULL,
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
-- name: UserExistsByIdentifier :one
|
-- name: GetVerifiedEmailBySSHIdentifier :one
|
||||||
SELECT EXISTS (
|
SELECT email
|
||||||
SELECT 1
|
|
||||||
FROM public."user"
|
FROM public."user"
|
||||||
WHERE identifier = $1
|
WHERE ssh_identifier = $1
|
||||||
) AS exists;
|
AND email_verified = true;
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ type Session struct {
|
|||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
ID string
|
ID string
|
||||||
Identifier string
|
SshIdentifier string
|
||||||
Name string
|
Name string
|
||||||
Email string
|
Email string
|
||||||
EmailVerified bool
|
EmailVerified bool
|
||||||
|
|||||||
@@ -9,17 +9,16 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
)
|
)
|
||||||
|
|
||||||
const userExistsByIdentifier = `-- name: UserExistsByIdentifier :one
|
const getVerifiedEmailBySSHIdentifier = `-- name: GetVerifiedEmailBySSHIdentifier :one
|
||||||
SELECT EXISTS (
|
SELECT email
|
||||||
SELECT 1
|
|
||||||
FROM public."user"
|
FROM public."user"
|
||||||
WHERE identifier = $1
|
WHERE ssh_identifier = $1
|
||||||
) AS exists
|
AND email_verified = true
|
||||||
`
|
`
|
||||||
|
|
||||||
func (q *Queries) UserExistsByIdentifier(ctx context.Context, identifier string) (bool, error) {
|
func (q *Queries) GetVerifiedEmailBySSHIdentifier(ctx context.Context, sshIdentifier string) (string, error) {
|
||||||
row := q.db.QueryRow(ctx, userExistsByIdentifier, identifier)
|
row := q.db.QueryRow(ctx, getVerifiedEmailBySSHIdentifier, sshIdentifier)
|
||||||
var exists bool
|
var email string
|
||||||
err := row.Scan(&exists)
|
err := row.Scan(&email)
|
||||||
return exists, err
|
return email, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user