mirror of
https://github.com/modrinth/code.git
synced 2026-08-27 18:14:49 +00:00
feat: require verified email to publish, to prevent spam (#6777)
* feat: require verified email to create projects, collections and organizations * fix(labrinth): fix tests * chore: fmt * chore: intl
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use crate::database::Executor;
|
||||
use eyre::{Context, Result};
|
||||
|
||||
use crate::database::PgPool;
|
||||
use crate::database::{PgPool, models::DBUserId};
|
||||
|
||||
/// Static personal access token for use in [`AppendPat`].
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -33,6 +33,25 @@ impl AppendPat for actix_web::test::TestRequest {
|
||||
}
|
||||
}
|
||||
|
||||
/// Mark a user's email as verified without using the email verification flow.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Errors if the user does not exist or could not be updated.
|
||||
pub async fn mark_email_verified(db: &PgPool, user_id: DBUserId) -> Result<()> {
|
||||
let result = sqlx::query!(
|
||||
"UPDATE users SET email_verified = TRUE WHERE id = $1",
|
||||
user_id.0,
|
||||
)
|
||||
.execute(db)
|
||||
.await
|
||||
.wrap_err("failed to mark user email as verified")?;
|
||||
|
||||
eyre::ensure!(result.rows_affected() == 1, "user does not exist");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Dummy [`DBUserId`]s.
|
||||
///
|
||||
/// [`DBUserId`]: crate::database::models::DBUserId
|
||||
@@ -79,5 +98,15 @@ pub async fn add_dummy_data(db: &PgPool) -> Result<()> {
|
||||
.await
|
||||
.wrap_err("failed to add dummy data")?;
|
||||
|
||||
for user_id in [
|
||||
user_id::ADMIN,
|
||||
user_id::MODERATOR,
|
||||
user_id::USER,
|
||||
user_id::FRIEND,
|
||||
user_id::ENEMY,
|
||||
] {
|
||||
mark_email_verified(db, user_id).await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ use super::{
|
||||
|
||||
use super::{database::USER_USER_ID, get_json_val_str};
|
||||
|
||||
pub const DUMMY_DATA_UPDATE: i64 = 7;
|
||||
pub const DUMMY_DATA_UPDATE: i64 = 8;
|
||||
|
||||
pub const DUMMY_CATEGORIES: &[&str] = &[
|
||||
"combat",
|
||||
|
||||
Reference in New Issue
Block a user