Compare commits

..
Author SHA1 Message Date
Ginger 82ad7515ce fix: Update doc comment 2026-03-18 12:08:54 -04:00
theS1LV3R cbdcd4a774 chore: Rename option index_page_allow_indexing to allow_web_indexing 2026-03-18 16:50:44 +01:00
Ginger 30199f9d33 chore: Merge branch 'ginger/password-reset' into 1527-prevent-search-engine-indexing 2026-03-18 11:23:12 -04:00
Ginger 2987bed990 fix: Fix password reset page appearance in light mode 2026-03-18 11:01:13 -04:00
Ginger c55ed43e36 feat: Restrict reset token command 2026-03-18 11:01:13 -04:00
Ginger 97224fd4a1 fix: Fix M_NOT_FOUND for users with no origin set 2026-03-18 11:01:13 -04:00
Ginger 331d20b683 fix: Evil CSS hackery 2026-03-18 11:01:13 -04:00
Ginger 5b20118157 fix: Disable text selection on k10y 2026-03-18 11:01:13 -04:00
Ginger 825695c42d fix: Use error page for extractor rejections 2026-03-18 11:01:12 -04:00
Ginger 4332f5856a feat: Implement dedicated 404 page for routes under /_continuwuity/ 2026-03-18 11:01:12 -04:00
Ginger 55832bd1b4 feat: Move index to /_continuwuity/ 2026-03-18 11:01:12 -04:00
Ginger 0e385af73a chore: Remove unnecessary database map left over from refactor 2026-03-18 11:01:12 -04:00
Ginger 05f0a48c2c fix: Use server name in index again 2026-03-18 11:01:12 -04:00
Ginger 23e6afc17f fix: Add CSRF protection 2026-03-18 11:01:12 -04:00
Ginger 1031639546 fix: Disallow issuing password reset tokens for deactivated users 2026-03-18 11:01:12 -04:00
Ginger 04e2c8a561 chore: Change password reset page path 2026-03-18 11:01:12 -04:00
Ginger 61a8d4ec10 chore: News fragment 2026-03-18 11:01:12 -04:00
Ginger b3adbb055d chore: Cleanup 2026-03-18 11:01:12 -04:00
Ginger a252e8ef4d feat: Implement a webpage for self-service password resets 2026-03-18 11:01:12 -04:00
Ginger 42c3aaba60 feat: Implement a command for issuing password reset links 2026-03-18 11:01:12 -04:00
Ginger bc0c4d8f4c feat: Add a new service for handling password resets 2026-03-18 11:01:12 -04:00
Ginger da07a8aae4 refactor: Split web code into multiple files, improve static resource loading 2026-03-18 11:01:12 -04:00
Ginger 6134917e65 chore: Update news fragment 2026-03-18 10:28:08 -04:00
Ginger 9a65e558e3 feat: Use a context struct to store global template context 2026-03-18 10:26:43 -04:00
theS1LV3R 86699add33 fix: Fix logic error 2026-03-11 16:54:34 +01:00
theS1LV3R ded23b56ac chore: Add news fragment for !1527 2026-03-11 16:51:49 +01:00
theS1LV3R 2f71860db5 feat: Add option for a noindex meta tag on the HTML index page
Adds a new config option `index_page_allow_indexing` which defaults to false.

Fixes: !1527
2026-03-11 16:51:49 +01:00
Ginger 75f6edb65a fix: Fix password reset page appearance in light mode 2026-03-09 16:13:55 +00:00
Ginger 23e2289d0a feat: Restrict reset token command 2026-03-09 16:13:55 +00:00
Ginger c8d084fb6d fix: Fix M_NOT_FOUND for users with no origin set 2026-03-09 16:13:55 +00:00
Ginger 73a5e1232f fix: Evil CSS hackery 2026-03-09 16:13:55 +00:00
Ginger a2f42e81cf fix: Disable text selection on k10y 2026-03-09 16:13:55 +00:00
Ginger 53ce430c7d fix: Use error page for extractor rejections 2026-03-09 16:13:55 +00:00
Ginger 920d21277a feat: Implement dedicated 404 page for routes under /_continuwuity/ 2026-03-09 16:13:55 +00:00
Ginger 77eef3c859 feat: Move index to /_continuwuity/ 2026-03-09 16:13:55 +00:00
Ginger 6f0706029f chore: Remove unnecessary database map left over from refactor 2026-03-09 16:13:55 +00:00
Ginger 2da2c6a187 fix: Use server name in index again 2026-03-09 16:13:55 +00:00
Ginger 8ad80cee64 fix: Add CSRF protection 2026-03-09 16:13:55 +00:00
Ginger 880108b9c5 fix: Disallow issuing password reset tokens for deactivated users 2026-03-09 16:13:55 +00:00
Ginger cd19322862 chore: Change password reset page path 2026-03-09 16:13:55 +00:00
Ginger c041e790ad chore: News fragment 2026-03-09 16:13:55 +00:00
Ginger 911a58c062 chore: Cleanup 2026-03-09 16:13:55 +00:00
Ginger fba79d4eb1 feat: Implement a webpage for self-service password resets 2026-03-09 16:13:55 +00:00
Ginger 78242282c9 feat: Implement a command for issuing password reset links 2026-03-09 16:13:55 +00:00
Ginger 5fc18bf1d8 feat: Add a new service for handling password resets 2026-03-09 16:13:55 +00:00
Ginger e3010b8ca0 refactor: Split web code into multiple files, improve static resource loading 2026-03-09 16:13:55 +00:00
8 changed files with 26 additions and 78 deletions

No files matched your search

-3
View File
@@ -969,6 +969,3 @@ needless_raw_string_hashes = "allow"
# TODO: Enable this lint & fix all instances
collapsible_if = "allow"
# TODO: break these apart
cognitive_complexity = "allow"
+8 -3
View File
@@ -1,6 +1,10 @@
use std::sync::Arc;
use axum::{Router, response::IntoResponse};
use axum::{
Router,
response::{IntoResponse, Redirect},
routing::get,
};
use conduwuit::Error;
use conduwuit_service::{Services, state, state::Guard};
use http::{StatusCode, Uri};
@@ -10,7 +14,8 @@ pub(crate) fn build(services: &Arc<Services>) -> (Router, Guard) {
let router = Router::<state::State>::new();
let (state, guard) = state::create(services.clone());
let router = conduwuit_api::router::build(router, &services.server)
.merge(conduwuit_web::build())
.nest("/_continuwuity/", conduwuit_web::build())
.route("/", get(async || Redirect::permanent("/_continuwuity/")))
.fallback(not_found)
.with_state(state);
@@ -18,5 +23,5 @@ pub(crate) fn build(services: &Arc<Services>) -> (Router, Guard) {
}
async fn not_found(_uri: Uri) -> impl IntoResponse {
Error::Request(ErrorKind::Unrecognized, "not found :(".into(), StatusCode::NOT_FOUND)
Error::Request(ErrorKind::Unrecognized, "Not Found".into(), StatusCode::NOT_FOUND)
}
+13 -35
View File
@@ -1,5 +1,3 @@
use std::any::Any;
use askama::Template;
use axum::{
Router,
@@ -8,7 +6,7 @@ use axum::{
response::{Html, IntoResponse, Response},
};
use conduwuit_service::state;
use tower_http::{catch_panic::CatchPanicLayer, set_header::SetResponseHeaderLayer};
use tower_http::set_header::SetResponseHeaderLayer;
use tower_sec_fetch::SecFetchLayer;
use crate::pages::TemplateContext;
@@ -17,29 +15,24 @@ mod pages;
type State = state::State;
const CATASTROPHIC_FAILURE: &str = "cat-astrophic failure! we couldn't even render the error template. \
please contact the team @ https://continuwuity.org";
#[derive(Debug, thiserror::Error)]
enum WebError {
#[error("Failed to render template: {0}")]
Render(#[from] askama::Error),
#[error("Failed to validate form body: {0}")]
ValidationError(#[from] validator::ValidationErrors),
#[error("{0}")]
QueryRejection(#[from] QueryRejection),
#[error("{0}")]
FormRejection(#[from] FormRejection),
#[error("{0}")]
BadRequest(String),
#[error("Bad request: {0}")]
BadRequest(String),
#[error("This page does not exist.")]
NotFound,
#[error("Failed to render template: {0}")]
Render(#[from] askama::Error),
#[error("{0}")]
#[error("Internal server error: {0}")]
InternalError(#[from] conduwuit_core::Error),
#[error("Request handler panicked! {0}")]
Panic(String),
}
impl IntoResponse for WebError {
@@ -65,7 +58,8 @@ impl IntoResponse for WebError {
error: self,
status,
context: TemplateContext {
// Statically set false to prevent error pages from being indexed.
// Statically set false to prevent error pages from being indexed and to prevent
// further errors if services.config is having issues.
allow_indexing: false,
},
};
@@ -73,7 +67,7 @@ impl IntoResponse for WebError {
if let Ok(body) = template.render() {
(status, Html(body)).into_response()
} else {
(status, CATASTROPHIC_FAILURE).into_response()
(status, "Something went wrong").into_response()
}
}
}
@@ -84,25 +78,9 @@ pub fn build() -> Router<state::State> {
Router::new()
.merge(index::build())
.nest(
"/_continuwuity/",
Router::new()
.merge(resources::build())
.merge(password_reset::build())
.merge(debug::build())
.fallback(async || WebError::NotFound),
)
.layer(CatchPanicLayer::custom(|panic: Box<dyn Any + Send + 'static>| {
let details = if let Some(s) = panic.downcast_ref::<String>() {
s.clone()
} else if let Some(s) = panic.downcast_ref::<&str>() {
(*s).to_owned()
} else {
"(opaque panic payload)".to_owned()
};
WebError::Panic(details).into_response()
}))
.merge(resources::build())
.merge(password_reset::build())
.fallback(async || WebError::NotFound)
.layer(SetResponseHeaderLayer::if_not_present(
header::CONTENT_SECURITY_POLICY,
HeaderValue::from_static("default-src 'self'; img-src 'self' data:;"),
-17
View File
@@ -1,17 +0,0 @@
use std::convert::Infallible;
use axum::{Router, routing::get};
use conduwuit_core::Error;
use crate::WebError;
pub(crate) fn build() -> Router<crate::State> {
Router::new()
.route("/_debug/panic", get(async || -> Infallible { panic!("Guru meditation error") }))
.route(
"/_debug/error",
get(async || -> WebError {
Error::Err(std::borrow::Cow::Borrowed("Guru meditation error")).into()
}),
)
}
+1 -5
View File
@@ -3,11 +3,7 @@ use axum::{Router, extract::State, response::IntoResponse, routing::get};
use crate::{WebError, template};
pub(crate) fn build() -> Router<crate::State> {
Router::new()
.route("/", get(index_handler))
.route("/_continuwuity/", get(index_handler))
}
pub(crate) fn build() -> Router<crate::State> { Router::new().route("/", get(index_handler)) }
async fn index_handler(
State(services): State<crate::State>,
-4
View File
@@ -1,14 +1,11 @@
mod components;
pub(super) mod debug;
pub(super) mod index;
pub(super) mod password_reset;
pub(super) mod resources;
#[derive(Debug)]
pub(crate) struct TemplateContext {
pub allow_indexing: bool,
}
impl From<&crate::State> for TemplateContext {
fn from(state: &crate::State) -> Self {
Self {
@@ -16,7 +13,6 @@ impl From<&crate::State> for TemplateContext {
}
}
}
#[macro_export]
macro_rules! template {
(
+2 -4
View File
@@ -18,8 +18,6 @@ use crate::{
template,
};
const INVALID_TOKEN_ERROR: &str = "Invalid reset token. Your reset link may have expired.";
#[derive(Deserialize)]
struct PasswordResetQuery {
token: String,
@@ -69,7 +67,7 @@ async fn password_reset_form(
reset_form: Form<'static>,
) -> Result<impl IntoResponse, WebError> {
let Some(token) = services.password_reset.check_token(&query.token).await else {
return Err(WebError::BadRequest(INVALID_TOKEN_ERROR.to_owned()));
return Err(WebError::BadRequest("Invalid reset token".to_owned()));
};
let user_card = UserCard::for_local_user(&services, &token.info.user).await;
@@ -98,7 +96,7 @@ async fn post_password_reset(
match form.validate() {
| Ok(()) => {
let Some(token) = services.password_reset.check_token(&query.token).await else {
return Err(WebError::BadRequest(INVALID_TOKEN_ERROR.to_owned()));
return Err(WebError::BadRequest("Invalid reset token".to_owned()));
};
let user_id = token.info.user.clone();
+2 -7
View File
@@ -24,17 +24,12 @@
<h1>
{% if status == StatusCode::NOT_FOUND %}
Not found
{% else if status == StatusCode::INTERNAL_SERVER_ERROR %}
Internal server error
{% else %}
Bad request
Request error
{% endif %}
<small aria-hidden>(︶^︶)</small>
</h1>
{% if status == StatusCode::INTERNAL_SERVER_ERROR %}
<p>Please <a href="https://forgejo.ellis.link/continuwuation/continuwuity/issues/new">submit a bug report</a> 🥺</p>
{% endif %}
<pre><code>{{ error }}</code></pre>
</div>