ezidam: mount all routes in "/", and use functions directly when redirecting
This commit is contained in:
parent
36fb1cff52
commit
3d065bbc22
5 changed files with 20 additions and 22 deletions
|
|
@ -33,7 +33,9 @@ pub fn routes(rocket_builder: Rocket<Build>) -> Rocket<Build> {
|
|||
// Root
|
||||
.mount("/", root::routes())
|
||||
// Setup
|
||||
.mount("/setup", setup::routes())
|
||||
.mount("/auth", auth::routes())
|
||||
.mount("/.well-known", well_known::routes())
|
||||
.mount("/", setup::routes())
|
||||
// Oauth
|
||||
.mount("/", oauth::routes())
|
||||
// Well known
|
||||
.mount("/", well_known::routes())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ pub mod content {
|
|||
|
||||
#[get("/")]
|
||||
async fn redirect_to_setup(_setup: NeedSetup) -> Redirect {
|
||||
Redirect::to(uri!("/setup"))
|
||||
Redirect::to(uri!(super::setup::setup))
|
||||
}
|
||||
|
||||
#[get("/", rank = 2)]
|
||||
|
|
|
|||
|
|
@ -8,12 +8,12 @@ pub fn routes() -> Vec<Route> {
|
|||
routes![setup_completed, setup, create_first_account]
|
||||
}
|
||||
|
||||
#[get("/")]
|
||||
#[get("/setup")]
|
||||
async fn setup_completed(_setup: CompletedSetup) -> Redirect {
|
||||
Redirect::to(uri!("/"))
|
||||
Redirect::to(uri!(super::root::homepage))
|
||||
}
|
||||
|
||||
#[get("/", rank = 2)]
|
||||
#[get("/setup", rank = 2)]
|
||||
async fn setup(flash: Option<FlashMessage<'_>>) -> Template {
|
||||
flash
|
||||
.map(|flash| Page::with_flash(Page::Setup, flash))
|
||||
|
|
@ -27,7 +27,7 @@ struct CreateFirstAccount<'r> {
|
|||
pub url: &'r str,
|
||||
}
|
||||
|
||||
#[post("/", data = "<form>")]
|
||||
#[post("/setup", data = "<form>")]
|
||||
async fn create_first_account(
|
||||
form: Form<CreateFirstAccount<'_>>,
|
||||
_setup: NeedSetup,
|
||||
|
|
@ -40,7 +40,7 @@ async fn create_first_account(
|
|||
Ok(url) => url,
|
||||
Err(e) => {
|
||||
return Ok(Either::Right(Flash::new(
|
||||
Redirect::to(uri!("/setup")),
|
||||
Redirect::to(uri!(setup)),
|
||||
FlashKind::Danger,
|
||||
e.to_string(),
|
||||
)));
|
||||
|
|
@ -76,7 +76,7 @@ async fn create_first_account(
|
|||
|
||||
// TODO: login with openid/oauth
|
||||
|
||||
Ok(Either::Left(Redirect::to(uri!("/"))))
|
||||
Ok(Either::Left(Redirect::to(uri!(super::root::homepage))))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
@ -89,7 +89,7 @@ mod test {
|
|||
let client = setup_rocket_testing();
|
||||
|
||||
// Make request
|
||||
let setup_page = client.get(uri!("/setup")).dispatch();
|
||||
let setup_page = client.get(uri!(super::setup)).dispatch();
|
||||
assert_eq!(setup_page.status(), Status::Ok);
|
||||
|
||||
// Create account
|
||||
|
|
@ -97,7 +97,7 @@ mod test {
|
|||
assert_eq!(create_account.status(), Status::SeeOther);
|
||||
|
||||
// Make request again, make sure its not OK
|
||||
let setup_page_after_creation = client.get(uri!("/setup")).dispatch();
|
||||
let setup_page_after_creation = client.get(uri!(super::setup)).dispatch();
|
||||
assert_ne!(setup_page_after_creation.status(), Status::Ok);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ pub fn routes() -> Vec<Route> {
|
|||
routes![openid_configuration, json_web_keys]
|
||||
}
|
||||
|
||||
#[get("/openid-configuration")]
|
||||
#[get("/.well-known/openid-configuration")]
|
||||
async fn openid_configuration(mut db: Connection<Database>) -> Result<Json<Value>> {
|
||||
// Get settings
|
||||
let settings = Settings::get(&mut *db).await?;
|
||||
|
|
@ -27,7 +27,7 @@ async fn openid_configuration(mut db: Connection<Database>) -> Result<Json<Value
|
|||
Ok(Json(openid_configuration))
|
||||
}
|
||||
|
||||
#[get("/jwks.json")]
|
||||
#[get("/.well-known/jwks.json")]
|
||||
async fn json_web_keys(mut db: Connection<Database>) -> Result<Json<Vec<Value>>> {
|
||||
// Get keys
|
||||
let keys = Key::get_all(&mut *db, Some(false)).await?;
|
||||
|
|
@ -70,9 +70,7 @@ mod test {
|
|||
run_setup(&client);
|
||||
|
||||
// Make request
|
||||
let response = client
|
||||
.get(uri!("/.well-known/openid-configuration"))
|
||||
.dispatch();
|
||||
let response = client.get(uri!(super::openid_configuration)).dispatch();
|
||||
assert_eq!(response.status(), Status::Ok);
|
||||
|
||||
// Make sure it is valid json
|
||||
|
|
@ -85,9 +83,7 @@ mod test {
|
|||
let client = setup_rocket_testing();
|
||||
|
||||
// Make request
|
||||
let response = client
|
||||
.get(uri!("/.well-known/openid-configuration"))
|
||||
.dispatch();
|
||||
let response = client.get(uri!(super::openid_configuration)).dispatch();
|
||||
assert_ne!(response.status(), Status::Ok);
|
||||
}
|
||||
|
||||
|
|
@ -97,7 +93,7 @@ mod test {
|
|||
let client = setup_rocket_testing();
|
||||
|
||||
// Make request
|
||||
let response = client.get(uri!("/.well-known/jwks.json")).dispatch();
|
||||
let response = client.get(uri!(super::json_web_keys)).dispatch();
|
||||
assert_eq!(response.status(), Status::Ok);
|
||||
|
||||
// Make sure it is valid json
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ pub fn setup_rocket_testing() -> Client {
|
|||
|
||||
pub fn run_setup(client: &Client) -> LocalResponse {
|
||||
client
|
||||
.post(uri!("/setup"))
|
||||
.post(uri!(crate::routes::setup::setup))
|
||||
.header(ContentType::Form)
|
||||
.body(r#"username=phil&password=password&url=https://example.com"#)
|
||||
.dispatch()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue