Adding Tera for templates

This commit is contained in:
Alex Wright 2020-02-29 19:45:32 +01:00
parent 39d12d7765
commit 5e2975ab3b
4 changed files with 27 additions and 4 deletions

View File

@ -6,7 +6,7 @@ edition = "2018"
[dependencies] [dependencies]
rocket = { git = "https://github.com/SergioBenitez/Rocket.git", branch="master" } rocket = { git = "https://github.com/SergioBenitez/Rocket.git", branch="master" }
rocket_contrib = { git = "https://github.com/SergioBenitez/Rocket.git", branch="master" } rocket_contrib = { git = "https://github.com/SergioBenitez/Rocket.git", branch="master", features = ["tera_templates"] }
futures = "0.1.21" futures = "0.1.21"
ldap3 = "0.6" ldap3 = "0.6"
tokio = "0.1.0" tokio = "0.1.0"

View File

@ -28,6 +28,7 @@ use openssl::rsa::Rsa;
use ldap3::{ LdapConn, Scope, SearchEntry }; use ldap3::{ LdapConn, Scope, SearchEntry };
use rocket::request::Form; use rocket::request::Form;
use rocket_contrib::json::Json; use rocket_contrib::json::Json;
use rocket_contrib::templates::Template;
#[derive(Debug)] #[derive(Debug)]
struct BasicAuthentication { struct BasicAuthentication {
@ -174,8 +175,11 @@ fn oidc_config() -> Json<OidcConfig> {
} }
#[get("/")] #[get("/")]
fn hello() -> &'static str { fn hello() -> Template {
"Hello!" let config = OidcConfig {
jwks_uri: "https://auth.xeen.dev/oauth2/keys".to_string(),
};
Template::render("hello", &config)
} }
fn routes() -> Vec<rocket::Route> { fn routes() -> Vec<rocket::Route> {
@ -190,5 +194,8 @@ fn routes() -> Vec<rocket::Route> {
fn main() { fn main() {
env_logger::init(); env_logger::init();
rocket::ignite().mount("/", routes()).launch(); rocket::ignite()
.attach(Template::fairing())
.mount("/", routes())
.launch();
} }

11
templates/base.html.tera Normal file
View File

@ -0,0 +1,11 @@
<!doctype html>
<html>
<head>
<title>Auth</title>
</head>
<body>
{% block content %}
<h1>Hi!</h1>
{% endblock content %}
</body>
</html>

View File

@ -0,0 +1,5 @@
{% extends "base" %}
{% block content %}
<h1>Hello!</h1>
{% endblock content %}