fix up routes and add email resending

This commit is contained in:
red binder 2026-06-06 14:31:19 +02:00
commit cf5dd20132
22 changed files with 622 additions and 101 deletions

View file

@ -100,6 +100,7 @@ async fn launch() -> _ {
nnid::person_exists::person_exists,
nnid::support::validate,
nnid::support::verify_email,
nnid::support::resend_email,
nnid::people::create_account,
nnid::people::get_own_profile,
nnid::people::get_device_owner,
@ -109,8 +110,8 @@ async fn launch() -> _ {
nnid::oauth::generate_token::generate_token,
nnid::provider::get_nex_token,
nnid::provider::get_service_token,
nnid::mapped_ids::mapped_ids,
nnid::mapped_ids::get_time,
nnid::admin::mapped_ids,
nnid::admin::get_time,
json_api::oauth::generate_token::generate_token,
json_api::users::profile::get_own_profile,
json_api::users::mii::get_mii_data_by_pid,

View file

@ -6,6 +6,6 @@ pub mod oauth;
mod pid_distribution;
pub mod people;
pub mod provider;
pub mod mapped_ids;
pub mod admin;
pub mod support;
pub mod miis;

View file

@ -3,7 +3,9 @@ use crate::error::{Error, Errors};
use chrono::Utc;
use hickory_resolver::TokioAsyncResolver;
use rocket::form::Form;
use rocket::{FromForm, State, post, put};
use rocket::{FromForm, State, post, put, get, Request};
use rocket::request::{self, FromRequest};
use rocket::http::Status;
const BAD_CODE_ERROR: Errors = Errors {
error: &[Error {
@ -17,6 +19,25 @@ pub struct ValidateEmailInput {
email: String,
}
// sorry maple i really tried and couldn't find a better way
pub struct EmailPid(pub i32);
#[rocket::async_trait]
impl<'r> FromRequest<'r> for EmailPid {
type Error = Errors<'static>;
async fn from_request(req: &'r Request<'_>) -> request::Outcome<Self, Self::Error> {
match req.headers().get_one("x-nintendo-pid") {
Some(val) => match val.parse::<i32>() {
Ok(parsed_id) => request::Outcome::Success(EmailPid(parsed_id)),
Err(_) => request::Outcome::Error((Status::BadRequest, BAD_CODE_ERROR)),
},
None => request::Outcome::Error((Status::BadRequest, BAD_CODE_ERROR)),
}
}
}
// i was tired at 1 am ok have mercy
#[post("/v1/api/support/validate/email", data = "<data>")]
pub async fn validate(
data: Form<ValidateEmailInput>,
@ -106,3 +127,37 @@ pub async fn verify_email(
Err(BAD_CODE_ERROR)
}
#[get("/v1/api/support/resend_confirmation")]
pub async fn resend_email(
database: &State<Pool>,
pid: EmailPid,
) -> Result<(), Errors<'static>> {
let pid = pid.0;
let user_data = sqlx::query!(
"SELECT username, verification_code, email FROM users WHERE pid = $1",
pid
)
.fetch_optional(&**database)
.await
.map_err(|e| {
eprintln!("{}", e);
BAD_CODE_ERROR
})?;
let user = match user_data {
Some(row) => row,
None => return Err(BAD_CODE_ERROR),
};
crate::email::send_verification_email(&user.email, user.verification_code, &user.username)
.await
.map_err(|e| {
eprintln!("Failed to send email: {}", e);
BAD_CODE_ERROR
})?;
Ok(())
}