use crate::{ mail::{build_mail, Mailer}, routes::{errors::ErrorPage, RespondOrRedirect}, template_utils::{IntoContext, Ructe}, }; use plume_models::{ db_conn::DbConn, email_signups::EmailSignup, instance::Instance, lettre::Transport, signups::{self, Strategy as SignupStrategy}, Error, PlumeRocket, CONFIG, }; use rocket::{ http::Status, request::LenientForm, response::{Flash, Redirect}, State, }; use std::sync::{Arc, Mutex}; use tracing::warn; use validator::{Validate, ValidationError, ValidationErrors}; #[derive(Default, FromForm, Validate)] #[validate(schema( function = "emails_match", skip_on_field_errors = false, message = "Emails are not matching" ))] pub struct EmailSignupForm { #[validate(email(message = "Invalid email"))] pub email: String, #[validate(email(message = "Invalid email"))] pub email_confirmation: String, } fn emails_match(form: &EmailSignupForm) -> Result<(), ValidationError> { if form.email_confirmation == form.email { Ok(()) } else { Err(ValidationError::new("emails_match")) } } #[derive(Default, FromForm, Validate)] #[validate(schema( function = "passwords_match", skip_on_field_errors = false, message = "Passwords are not matching" ))] pub struct NewUserForm { #[validate(length(min = 1, message = "Username should be at least 1 characters long"))] pub username: String, #[validate(length(min = 8, message = "Password should be at least 8 characters long"))] pub password: String, #[validate(length(min = 8, message = "Password should be at least 8 characters long"))] pub password_confirmation: String, pub email: String, pub token: String, } pub fn passwords_match(form: &NewUserForm) -> Result<(), ValidationError> { if form.password != form.password_confirmation { Err(ValidationError::new("password_match")) } else { Ok(()) } } #[post("/email_signups/new", data = "