filling out templates for account creation

This commit is contained in:
Joe Ardent 2023-05-17 10:09:00 -07:00
parent d9c56aaf1e
commit f12b524457
3 changed files with 11 additions and 35 deletions

View file

@ -3,4 +3,5 @@ extern crate justerror;
pub mod db; pub mod db;
pub mod handlers; pub mod handlers;
pub(crate) mod templates;
pub mod users; pub mod users;

View file

@ -1,35 +0,0 @@
use askama::Template;
use axum::{
extract,
http::StatusCode,
response::{Html, IntoResponse, Response},
};
pub(crate) async fn greet(extract::Path(name): extract::Path<String>) -> impl IntoResponse {
let template = HelloTemplate { name };
HtmlTemplate(template)
}
#[derive(Template)]
#[template(path = "hello.html")]
struct HelloTemplate {
name: String,
}
struct HtmlTemplate<T>(T);
impl<T> IntoResponse for HtmlTemplate<T>
where
T: Template,
{
fn into_response(self) -> Response {
match self.0.render() {
Ok(html) => Html(html).into_response(),
Err(err) => (
StatusCode::INTERNAL_SERVER_ERROR,
format!("Failed to render template. Error: {}", err),
)
.into_response(),
}
}
}

10
src/templates.rs Normal file
View file

@ -0,0 +1,10 @@
use askama::Template;
#[derive(Template)]
pub struct CreateUser {
pub username: String,
pub displayname: Option<String>,
pub email: Option<String>,
pub password: String,
pub pw_verify: String,
}