Skip to content
Clone
9362a10
117 lines 4.3 KB Rust
use export::http::Router;
use export::http::routing::{delete, get, post, put};
use crate::auth::handlers::accept_agreement::accept_agreement;
use crate::auth::handlers::account_deletion::{
account_deletion_status, cancel_account_deletion, request_account_deletion,
};
use crate::auth::handlers::agreement_page::agreement_page;
use crate::auth::handlers::create_report::create_report;
use crate::auth::handlers::delete_notification::delete_notification;
use crate::auth::handlers::get_preferences::get_preferences;
use crate::auth::handlers::get_user::get_user;
use crate::auth::handlers::list_agreements::list_agreements;
use crate::auth::handlers::list_notifications::list_notifications;
use crate::auth::handlers::me::me;
use crate::auth::handlers::unread_notifications_count::unread_notifications_count;
use crate::auth::handlers::update_preferences::update_preferences;
use crate::auth::handlers::update_profile::update_profile;
use crate::auth::handlers::users;
use crate::auth::session;
use crate::auth::services::AuthService;
pub fn router(_service: AuthService) -> Router<AuthService> {
let public = Router::<AuthService>::new()
.route("/auth/login", get(session::login::login))
.route("/auth/signup", get(session::login::signup))
.route("/auth/callback", get(session::callback::callback))
.route("/auth/refresh", post(session::refresh::refresh))
.route("/auth/logout", post(session::logout::logout))
.route("/auth/agreements", get(list_agreements));
let authed = Router::<AuthService>::new()
.route("/users", get(users::list_users_batch))
.route(
"/users/by-username/{username}",
get(users::get_user_by_username),
)
.route("/users/{user_id}", get(get_user))
.route("/me", get(me).patch(update_profile))
.route(
"/me/deletion",
get(account_deletion_status)
.post(request_account_deletion)
.delete(cancel_account_deletion),
)
.route(
"/auth/jwt-request",
get(crate::auth::handlers::jwt_request::jwt_request),
)
.route("/me/username", put(users::update_username))
.route(
"/me/preferences",
get(get_preferences).patch(update_preferences),
)
.route("/me/agreements/{key}", put(accept_agreement))
.route("/me/notifications", get(list_notifications))
.route(
"/me/notifications/unread-count",
get(unread_notifications_count),
)
.route(
"/me/notifications/{notification_id}",
delete(delete_notification),
)
.route(
"/me/notifications/read",
put(crate::auth::handlers::mark_notifications_read::mark_notifications_read),
)
.route("/me/reports", post(create_report))
.route(
"/auth/password/change",
post(crate::auth::handlers::password::change_password),
)
.route(
"/auth/2fa/status",
get(crate::auth::handlers::two_factor::totp_status),
)
.route(
"/auth/2fa/setup",
post(crate::auth::handlers::two_factor::totp_setup),
)
.route(
"/auth/2fa/enable",
post(crate::auth::handlers::two_factor::totp_enable),
)
.route(
"/auth/2fa/disable",
post(crate::auth::handlers::two_factor::totp_disable),
)
.route(
"/auth/2fa/recovery-codes",
get(crate::auth::handlers::two_factor::recovery_codes)
.put(crate::auth::handlers::two_factor::regenerate_recovery_codes),
)
.route(
"/me/sessions",
get(crate::auth::handlers::sessions::list_sessions)
.delete(crate::auth::handlers::sessions::revoke_all_sessions),
)
.route(
"/me/sessions/{session_id}",
delete(crate::auth::handlers::sessions::revoke_session),
)
.route(
"/me/devices",
get(crate::auth::handlers::devices::list_devices),
)
.wrap(export::http::Guard::Session);
public.merge(authed)
}
pub fn pages_router(service: AuthService) -> Router {
Router::<()>::new()
.route("/agreements/{key}", get(agreement_page))
.with_state(service)
}