Skip to content

Commit

Permalink
Better account verification.
Browse files Browse the repository at this point in the history
  • Loading branch information
Syfaro committed May 30, 2024
1 parent bd41138 commit ee8fc77
Show file tree
Hide file tree
Showing 13 changed files with 255 additions and 98 deletions.
2 changes: 2 additions & 0 deletions migrations/20240530173905_better_verification.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE
linked_account DROP COLUMN verification_key, DROP COLUMN verified_at;
22 changes: 22 additions & 0 deletions migrations/20240530173905_better_verification.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
ALTER TABLE
linked_account
ADD
COLUMN created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT current_timestamp,
ADD
COLUMN verification_key TEXT,
ADD
COLUMN verified_at TIMESTAMP WITH TIME ZONE;

UPDATE
linked_account
SET
verified_at = current_timestamp
WHERE
linked_account.data->'verification_key' IS NULL;

UPDATE
linked_account
SET
verification_key = linked_account.data->>'verification_key'
WHERE
linked_account.data->'verification_key' IS NOT NULL;
6 changes: 4 additions & 2 deletions queries/linked_account/create.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ INSERT INTO
owner_id,
source_site,
username,
data
data,
verification_key,
verified_at
)
VALUES
($1, $2, $3, $4) RETURNING *;
($1, $2, $3, $4, $5, $6) RETURNING *;
7 changes: 7 additions & 0 deletions queries/linked_account/verify.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
UPDATE
linked_account
SET
verification_key = NULL,
verified_at = current_timestamp
WHERE
id = $1;
222 changes: 154 additions & 68 deletions sqlx-data.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/jobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ pub async fn start_job_processing(ctx: JobContext) -> Result<(), Error> {
.await?
.ok_or(Error::Missing)?;

let key = match account.verification_key() {
let key = match account.verification_key {
Some(key) => key,
None => return Err(Error::Missing),
};
Expand Down Expand Up @@ -718,10 +718,10 @@ pub async fn start_job_processing(ctx: JobContext) -> Result<(), Error> {
.map(|elem| elem.text().collect::<String>())
.unwrap_or_default();

let verifier_found = text.contains(key);
let verifier_found = text.contains(&key);

if verifier_found {
models::LinkedAccount::update_data(&ctx.conn, account.id, None).await?;
models::LinkedAccount::verify(&ctx.conn, account.id).await?;
}

verifier_found
Expand All @@ -745,10 +745,10 @@ pub async fn start_job_processing(ctx: JobContext) -> Result<(), Error> {
.and_then(|profile_text| profile_text.as_str())
.ok_or_else(|| Error::unknown_message("Weasyl was missing profile text"))?;

let verifier_found = profile_text.contains(key);
let verifier_found = profile_text.contains(&key);

if verifier_found {
models::LinkedAccount::update_data(&ctx.conn, account.id, None).await?;
models::LinkedAccount::verify(&ctx.conn, account.id).await?;
}

verifier_found
Expand Down
Loading

0 comments on commit ee8fc77

Please sign in to comment.