2023-07-07 12:20:16 -07:00
|
|
|
pub mod checks;
|
2023-10-30 11:14:38 -05:00
|
|
|
pub mod oauth;
|
2023-12-01 10:02:11 -08:00
|
|
|
pub mod templates;
|
2023-07-07 12:20:16 -07:00
|
|
|
pub mod validate;
|
|
|
|
|
pub use checks::{
|
2024-10-18 16:07:35 -07:00
|
|
|
filter_enlisted_projects_ids, filter_enlisted_version_ids,
|
|
|
|
|
filter_visible_collections, filter_visible_project_ids,
|
|
|
|
|
filter_visible_projects,
|
2023-07-07 12:20:16 -07:00
|
|
|
};
|
2023-12-01 10:02:11 -08:00
|
|
|
use serde::{Deserialize, Serialize};
|
2023-07-07 12:20:16 -07:00
|
|
|
pub use validate::{check_is_moderator_from_headers, get_user_from_headers};
|
|
|
|
|
|
|
|
|
|
use crate::file_hosting::FileHostingError;
|
|
|
|
|
use crate::models::error::ApiError;
|
|
|
|
|
use actix_web::HttpResponse;
|
2025-05-09 07:27:55 -05:00
|
|
|
use actix_web::http::StatusCode;
|
2023-07-07 12:20:16 -07:00
|
|
|
use thiserror::Error;
|
|
|
|
|
|
|
|
|
|
#[derive(Error, Debug)]
|
|
|
|
|
pub enum AuthenticationError {
|
|
|
|
|
#[error("Environment Error")]
|
|
|
|
|
Env(#[from] dotenvy::Error),
|
|
|
|
|
#[error("An unknown database error occurred: {0}")]
|
|
|
|
|
Sqlx(#[from] sqlx::Error),
|
|
|
|
|
#[error("Database Error: {0}")]
|
|
|
|
|
Database(#[from] crate::database::models::DatabaseError),
|
|
|
|
|
#[error("Error while parsing JSON: {0}")]
|
|
|
|
|
SerDe(#[from] serde_json::Error),
|
2023-07-18 15:02:54 -07:00
|
|
|
#[error("Error while communicating to external provider")]
|
2023-07-07 12:20:16 -07:00
|
|
|
Reqwest(#[from] reqwest::Error),
|
2023-07-08 14:29:17 -07:00
|
|
|
#[error("Error uploading user profile picture")]
|
|
|
|
|
FileHosting(#[from] FileHostingError),
|
2023-07-07 12:20:16 -07:00
|
|
|
#[error("Error while decoding PAT: {0}")]
|
2025-03-01 20:53:43 -08:00
|
|
|
Decoding(#[from] ariadne::ids::DecodingError),
|
2023-07-12 20:40:24 -07:00
|
|
|
#[error("{0}")]
|
[DO NOT MERGE] Email notification system (#4338)
* Migration
* Fixup db models
* Redis
* Stuff
* Switch PKs to BIGSERIALs, insert to notifications_deliveries when inserting notifications
* Queue, templates
* Query cache
* Fixes, fixtures
* Perf, cache template data & HTML bodies
* Notification type configuration, ResetPassword notification type
* Reset password
* Query cache
* Clippy + fmt
* Traces, fix typo, fix user email in ResetPassword
* send_email
* Models, db
* Remove dead code, adjust notification settings in migration
* Clippy fmt
* Delete dead code, fixes
* Fmt
* Update apps/labrinth/src/queue/email.rs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Remove old fixtures
* Unify email retry delay
* Fix type
* External notifications
* Remove `notifications_types_preference_restrictions`, as user notification preferences is out of scope for this PR
* Query cache, fmt, clippy
* Fix join in get_many_user_exposed_on_site
* Remove migration comment
* Query cache
* Update html body urls
* Remove comment
* Add paymentfailed.service variable to PaymentFailed notification variant
* Fix compile error
* Fix deleting notifications
* Update apps/labrinth/src/database/models/user_item.rs
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Update apps/labrinth/src/database/models/user_item.rs
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Update Cargo.toml
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Update apps/labrinth/migrations/20250902133943_notification-extension.sql
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Address review comments
* Fix compliation
* Update apps/labrinth/src/database/models/users_notifications_preferences_item.rs
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
* Use strfmt to format emails
* Configurable Reply-To
* Configurable Reply-To
* Refactor for email background task
* Send some emails inline
* Fix account creation email check
* Revert "Use strfmt to format emails"
This reverts commit e0d6614afe51fa6349918377e953ba294c34ae0b.
* Reintroduce fill_template
* Set password reset email inline
* Process more emails per index
* clippy fmt
* Query cache
---------
Signed-off-by: François-Xavier Talbot <108630700+fetchfern@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Josiah Glosson <soujournme@gmail.com>
2025-09-15 15:02:29 -04:00
|
|
|
Mail(#[from] crate::queue::email::MailError),
|
2023-07-07 12:20:16 -07:00
|
|
|
#[error("Invalid Authentication Credentials")]
|
|
|
|
|
InvalidCredentials,
|
|
|
|
|
#[error("Authentication method was not valid")]
|
|
|
|
|
InvalidAuthMethod,
|
|
|
|
|
#[error("GitHub Token from incorrect Client ID")]
|
|
|
|
|
InvalidClientId,
|
2025-07-17 21:59:48 -04:00
|
|
|
#[error(
|
|
|
|
|
"User email is already registered on Modrinth. Try 'Forgot password' to access your account."
|
|
|
|
|
)]
|
2023-07-11 19:13:07 -07:00
|
|
|
DuplicateUser,
|
2023-08-02 14:43:04 -07:00
|
|
|
#[error("Invalid state sent, you probably need to get a new websocket")]
|
|
|
|
|
SocketError,
|
2023-07-07 12:20:16 -07:00
|
|
|
#[error("Invalid callback URL specified")]
|
2023-08-21 11:21:05 -07:00
|
|
|
Url,
|
2023-07-07 12:20:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl actix_web::ResponseError for AuthenticationError {
|
|
|
|
|
fn status_code(&self) -> StatusCode {
|
|
|
|
|
match self {
|
|
|
|
|
AuthenticationError::Env(..) => StatusCode::INTERNAL_SERVER_ERROR,
|
|
|
|
|
AuthenticationError::Sqlx(..) => StatusCode::INTERNAL_SERVER_ERROR,
|
2024-10-18 16:07:35 -07:00
|
|
|
AuthenticationError::Database(..) => {
|
|
|
|
|
StatusCode::INTERNAL_SERVER_ERROR
|
|
|
|
|
}
|
2023-07-07 12:20:16 -07:00
|
|
|
AuthenticationError::SerDe(..) => StatusCode::BAD_REQUEST,
|
2024-10-18 16:07:35 -07:00
|
|
|
AuthenticationError::Reqwest(..) => {
|
|
|
|
|
StatusCode::INTERNAL_SERVER_ERROR
|
|
|
|
|
}
|
2023-07-07 12:20:16 -07:00
|
|
|
AuthenticationError::InvalidCredentials => StatusCode::UNAUTHORIZED,
|
|
|
|
|
AuthenticationError::Decoding(..) => StatusCode::BAD_REQUEST,
|
2023-07-12 20:40:24 -07:00
|
|
|
AuthenticationError::Mail(..) => StatusCode::INTERNAL_SERVER_ERROR,
|
2023-07-07 12:20:16 -07:00
|
|
|
AuthenticationError::InvalidAuthMethod => StatusCode::UNAUTHORIZED,
|
|
|
|
|
AuthenticationError::InvalidClientId => StatusCode::UNAUTHORIZED,
|
|
|
|
|
AuthenticationError::Url => StatusCode::BAD_REQUEST,
|
2024-10-18 16:07:35 -07:00
|
|
|
AuthenticationError::FileHosting(..) => {
|
|
|
|
|
StatusCode::INTERNAL_SERVER_ERROR
|
|
|
|
|
}
|
2023-07-11 19:13:07 -07:00
|
|
|
AuthenticationError::DuplicateUser => StatusCode::BAD_REQUEST,
|
2023-08-02 14:43:04 -07:00
|
|
|
AuthenticationError::SocketError => StatusCode::BAD_REQUEST,
|
2023-07-07 12:20:16 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn error_response(&self) -> HttpResponse {
|
|
|
|
|
HttpResponse::build(self.status_code()).json(ApiError {
|
2023-08-21 11:21:05 -07:00
|
|
|
error: self.error_name(),
|
2024-02-21 16:24:21 -07:00
|
|
|
description: self.to_string(),
|
2023-07-07 12:20:16 -07:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-21 11:21:05 -07:00
|
|
|
|
|
|
|
|
impl AuthenticationError {
|
|
|
|
|
pub fn error_name(&self) -> &'static str {
|
|
|
|
|
match self {
|
|
|
|
|
AuthenticationError::Env(..) => "environment_error",
|
|
|
|
|
AuthenticationError::Sqlx(..) => "database_error",
|
|
|
|
|
AuthenticationError::Database(..) => "database_error",
|
|
|
|
|
AuthenticationError::SerDe(..) => "invalid_input",
|
|
|
|
|
AuthenticationError::Reqwest(..) => "network_error",
|
|
|
|
|
AuthenticationError::InvalidCredentials => "invalid_credentials",
|
|
|
|
|
AuthenticationError::Decoding(..) => "decoding_error",
|
|
|
|
|
AuthenticationError::Mail(..) => "mail_error",
|
|
|
|
|
AuthenticationError::InvalidAuthMethod => "invalid_auth_method",
|
|
|
|
|
AuthenticationError::InvalidClientId => "invalid_client_id",
|
|
|
|
|
AuthenticationError::Url => "url_error",
|
|
|
|
|
AuthenticationError::FileHosting(..) => "file_hosting",
|
|
|
|
|
AuthenticationError::DuplicateUser => "duplicate_user",
|
|
|
|
|
AuthenticationError::SocketError => "socket",
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-01 10:02:11 -08:00
|
|
|
|
2024-10-18 16:07:35 -07:00
|
|
|
#[derive(
|
|
|
|
|
Serialize, Deserialize, Default, Eq, PartialEq, Clone, Copy, Debug,
|
|
|
|
|
)]
|
2023-12-01 10:02:11 -08:00
|
|
|
#[serde(rename_all = "lowercase")]
|
|
|
|
|
pub enum AuthProvider {
|
|
|
|
|
#[default]
|
|
|
|
|
GitHub,
|
|
|
|
|
Discord,
|
|
|
|
|
Microsoft,
|
|
|
|
|
GitLab,
|
|
|
|
|
Google,
|
|
|
|
|
Steam,
|
|
|
|
|
PayPal,
|
|
|
|
|
}
|