Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions alexandrie.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ links = [
{ name = "Github repository", href = "https://github.com/Hirevo/alexandrie" },
{ name = "User documentation", href = "https://hirevo.github.io/alexandrie" },
]
login_required = false

[frontend.sessions]
cookie_name = "alexandrie.sid"
Expand Down
2 changes: 2 additions & 0 deletions crates/alexandrie/src/config/frontend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ pub struct FrontendConfig {
pub favicon: Option<String>,
/// Some related links.
pub links: Option<Vec<Link>>,
/// Whether to disallow anonymous browsing of the registry.
pub login_required: bool,
/// Assets configuration options.
pub assets: AssetsConfig,
/// Templates configuration options.
Expand Down
8 changes: 8 additions & 0 deletions crates/alexandrie/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,11 @@ impl From<Config> for State {
}
}
}

impl State {
/// Returns whether we require users to log in to browse crates.
#[cfg(feature = "frontend")]
pub fn is_login_required(&self) -> bool {
self.frontend.config.login_required
}
}
4 changes: 4 additions & 0 deletions crates/alexandrie/src/frontend/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ use crate::State;

pub(crate) async fn get(req: Request<State>) -> tide::Result {
let user = req.get_author();
if req.state().is_login_required() && user.is_none() {
return Ok(utils::response::redirect("/account/login"));
}

let state = req.state().clone();
let db = &state.db;

Expand Down
4 changes: 4 additions & 0 deletions crates/alexandrie/src/frontend/krate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ pub(crate) async fn get(req: Request<State>) -> tide::Result {
let canon_name = utils::canonical_name(name);

let user = req.get_author();
if req.state().is_login_required() && user.is_none() {
return Ok(utils::response::redirect("/account/login"));
}

let state = req.state().clone();
let db = &state.db;

Expand Down
4 changes: 4 additions & 0 deletions crates/alexandrie/src/frontend/last_updated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ pub(crate) async fn get(req: Request<State>) -> tide::Result {
let page_number = params.page.map_or_else(|| 1, |page| page.get());

let user = req.get_author();
if req.state().is_login_required() && user.is_none() {
return Ok(utils::response::redirect("/account/login"));
}

let state = req.state().clone();
let db = &state.db;

Expand Down
4 changes: 4 additions & 0 deletions crates/alexandrie/src/frontend/most_downloaded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ pub(crate) async fn get(req: Request<State>) -> tide::Result {
let page_number = params.page.map_or_else(|| 1, |page| page.get());

let user = req.get_author();
if req.state().is_login_required() && user.is_none() {
return Ok(utils::response::redirect("/account/login"));
}

let state = req.state().clone();
let db = &state.db;

Expand Down
4 changes: 4 additions & 0 deletions crates/alexandrie/src/frontend/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ pub(crate) async fn get(req: Request<State>) -> tide::Result {
let page_number = params.page.map_or_else(|| 1, |page| page.get());

let user = req.get_author();
if req.state().is_login_required() && user.is_none() {
return Ok(utils::response::redirect("/account/login"));
}

let state = req.state().clone();
let db = &state.db;

Expand Down
1 change: 1 addition & 0 deletions docker/mysql/alexandrie.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ max_crate_size = "50 MB"
enabled = true
title = "Alexandrie"
description = "An alternative crate registry for Cargo, the Rust package manager."
login_required = false

[frontend.sessions]
cookie_name = "alexandrie.sid"
Expand Down
1 change: 1 addition & 0 deletions docker/postgres/alexandrie.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ max_crate_size = "50 MB"
enabled = true
title = "Alexandrie"
description = "An alternative crate registry for Cargo, the Rust package manager."
login_required = false

[frontend.sessions]
cookie_name = "alexandrie.sid"
Expand Down
1 change: 1 addition & 0 deletions docker/sqlite/alexandrie.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ max_crate_size = "50 MB"
enabled = true
title = "Alexandrie"
description = "An alternative crate registry for Cargo, the Rust package manager."
login_required = false

[frontend.sessions]
cookie_name = "alexandrie.sid"
Expand Down