49 lines
943 B
Rust
49 lines
943 B
Rust
#![feature(decl_macro)]
|
|
|
|
use rocket::{*, response::Redirect, form::Form};
|
|
use rocket_dyn_templates::{Template, context};
|
|
|
|
#[get("/create")]
|
|
fn begin_create() -> Template
|
|
{
|
|
Template::render("begin_create", context!{})
|
|
}
|
|
|
|
#[get("/create/<name>")]
|
|
fn create(name: &str) -> Template
|
|
{
|
|
Template::render("create", context!{
|
|
username: name
|
|
})
|
|
}
|
|
|
|
#[derive(FromForm)]
|
|
struct UserNameData<'r> {
|
|
pub username: &'r str,
|
|
}
|
|
|
|
#[post("/create", data = "<name>")]
|
|
fn create_post(name: Form<UserNameData<'_>>) -> Redirect
|
|
{
|
|
Redirect::to(uri!(create(name.username)))
|
|
}
|
|
|
|
#[get("/about")]
|
|
fn about() -> Template
|
|
{
|
|
Template::render("about", context!{})
|
|
}
|
|
|
|
#[get("/")]
|
|
fn index() -> Template
|
|
{
|
|
Template::render("index", context! {
|
|
create_uri: uri!(begin_create())
|
|
})
|
|
}
|
|
|
|
#[launch]
|
|
fn rocket() -> _ {
|
|
rocket::build().mount("/", routes![begin_create, create, create_post, index, about]).attach(Template::fairing())
|
|
}
|