summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock136
-rw-r--r--Cargo.toml1
-rw-r--r--src/handlers.rs19
-rw-r--r--src/routes.rs6
-rw-r--r--templates/css.html8
-rw-r--r--templates/footer.html2
-rw-r--r--templates/header.html11
-rw-r--r--templates/menu.html5
-rw-r--r--templates/welcome.html8
9 files changed, 193 insertions, 3 deletions
diff --git a/Cargo.lock b/Cargo.lock
index b548774..649c923 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -41,6 +41,58 @@ dependencies = [
41] 41]
42 42
43[[package]] 43[[package]]
44name = "arrayvec"
45version = "0.5.2"
46source = "registry+https://github.com/rust-lang/crates.io-index"
47checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
48
49[[package]]
50name = "askama"
51version = "0.10.5"
52source = "registry+https://github.com/rust-lang/crates.io-index"
53checksum = "d298738b6e47e1034e560e5afe63aa488fea34e25ec11b855a76f0d7b8e73134"
54dependencies = [
55 "askama_derive",
56 "askama_escape",
57 "askama_shared",
58]
59
60[[package]]
61name = "askama_derive"
62version = "0.10.5"
63source = "registry+https://github.com/rust-lang/crates.io-index"
64checksum = "ca2925c4c290382f9d2fa3d1c1b6a63fa1427099721ecca4749b154cc9c25522"
65dependencies = [
66 "askama_shared",
67 "proc-macro2",
68 "syn",
69]
70
71[[package]]
72name = "askama_escape"
73version = "0.10.1"
74source = "registry+https://github.com/rust-lang/crates.io-index"
75checksum = "90c108c1a94380c89d2215d0ac54ce09796823cca0fd91b299cfff3b33e346fb"
76
77[[package]]
78name = "askama_shared"
79version = "0.11.1"
80source = "registry+https://github.com/rust-lang/crates.io-index"
81checksum = "2582b77e0f3c506ec4838a25fa8a5f97b9bed72bb6d3d272ea1c031d8bd373bc"
82dependencies = [
83 "askama_escape",
84 "humansize",
85 "nom",
86 "num-traits",
87 "percent-encoding",
88 "proc-macro2",
89 "quote",
90 "serde",
91 "syn",
92 "toml",
93]
94
95[[package]]
44name = "atty" 96name = "atty"
45version = "0.2.14" 97version = "0.2.14"
46source = "registry+https://github.com/rust-lang/crates.io-index" 98source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -82,6 +134,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
82checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" 134checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
83 135
84[[package]] 136[[package]]
137name = "bitvec"
138version = "0.19.5"
139source = "registry+https://github.com/rust-lang/crates.io-index"
140checksum = "8942c8d352ae1838c9dda0b0ca2ab657696ef2232a20147cf1b30ae1a9cb4321"
141dependencies = [
142 "funty",
143 "radium",
144 "tap",
145 "wyz",
146]
147
148[[package]]
85name = "blake2" 149name = "blake2"
86version = "0.9.1" 150version = "0.9.1"
87source = "registry+https://github.com/rust-lang/crates.io-index" 151source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -278,6 +342,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
278checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" 342checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
279 343
280[[package]] 344[[package]]
345name = "funty"
346version = "1.1.0"
347source = "registry+https://github.com/rust-lang/crates.io-index"
348checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7"
349
350[[package]]
281name = "futures" 351name = "futures"
282version = "0.3.14" 352version = "0.3.14"
283source = "registry+https://github.com/rust-lang/crates.io-index" 353source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -376,6 +446,7 @@ name = "gradecoin"
376version = "0.1.0" 446version = "0.1.0"
377dependencies = [ 447dependencies = [
378 "aes", 448 "aes",
449 "askama",
379 "base64 0.13.0", 450 "base64 0.13.0",
380 "blake2", 451 "blake2",
381 "block-modes", 452 "block-modes",
@@ -496,6 +567,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
496checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47" 567checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47"
497 568
498[[package]] 569[[package]]
570name = "humansize"
571version = "1.1.0"
572source = "registry+https://github.com/rust-lang/crates.io-index"
573checksum = "b6cab2627acfc432780848602f3f558f7e9dd427352224b0d9324025796d2a5e"
574
575[[package]]
499name = "humantime" 576name = "humantime"
500version = "1.3.0" 577version = "1.3.0"
501source = "registry+https://github.com/rust-lang/crates.io-index" 578source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -616,6 +693,19 @@ dependencies = [
616] 693]
617 694
618[[package]] 695[[package]]
696name = "lexical-core"
697version = "0.7.5"
698source = "registry+https://github.com/rust-lang/crates.io-index"
699checksum = "21f866863575d0e1d654fbeeabdc927292fdf862873dc3c96c6f753357e13374"
700dependencies = [
701 "arrayvec",
702 "bitflags",
703 "cfg-if 1.0.0",
704 "ryu",
705 "static_assertions",
706]
707
708[[package]]
619name = "libc" 709name = "libc"
620version = "0.2.93" 710version = "0.2.93"
621source = "registry+https://github.com/rust-lang/crates.io-index" 711source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -745,6 +835,19 @@ dependencies = [
745] 835]
746 836
747[[package]] 837[[package]]
838name = "nom"
839version = "6.1.2"
840source = "registry+https://github.com/rust-lang/crates.io-index"
841checksum = "e7413f999671bd4745a7b624bd370a569fb6bc574b23c83a3c5ed2e453f3d5e2"
842dependencies = [
843 "bitvec",
844 "funty",
845 "lexical-core",
846 "memchr",
847 "version_check",
848]
849
850[[package]]
748name = "num-bigint" 851name = "num-bigint"
749version = "0.2.6" 852version = "0.2.6"
750source = "registry+https://github.com/rust-lang/crates.io-index" 853source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -968,6 +1071,12 @@ dependencies = [
968] 1071]
969 1072
970[[package]] 1073[[package]]
1074name = "radium"
1075version = "0.5.3"
1076source = "registry+https://github.com/rust-lang/crates.io-index"
1077checksum = "941ba9d78d8e2f7ce474c015eea4d9c6d25b6a3327f9832ee29a4de27f91bbb8"
1078
1079[[package]]
971name = "rand" 1080name = "rand"
972version = "0.7.3" 1081version = "0.7.3"
973source = "registry+https://github.com/rust-lang/crates.io-index" 1082source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1279,6 +1388,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1279checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" 1388checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
1280 1389
1281[[package]] 1390[[package]]
1391name = "static_assertions"
1392version = "1.1.0"
1393source = "registry+https://github.com/rust-lang/crates.io-index"
1394checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
1395
1396[[package]]
1282name = "subtle" 1397name = "subtle"
1283version = "2.4.0" 1398version = "2.4.0"
1284source = "registry+https://github.com/rust-lang/crates.io-index" 1399source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1308,6 +1423,12 @@ dependencies = [
1308] 1423]
1309 1424
1310[[package]] 1425[[package]]
1426name = "tap"
1427version = "1.0.1"
1428source = "registry+https://github.com/rust-lang/crates.io-index"
1429checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
1430
1431[[package]]
1311name = "tempfile" 1432name = "tempfile"
1312version = "3.2.0" 1433version = "3.2.0"
1313source = "registry+https://github.com/rust-lang/crates.io-index" 1434source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1432,6 +1553,15 @@ dependencies = [
1432] 1553]
1433 1554
1434[[package]] 1555[[package]]
1556name = "toml"
1557version = "0.5.8"
1558source = "registry+https://github.com/rust-lang/crates.io-index"
1559checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa"
1560dependencies = [
1561 "serde",
1562]
1563
1564[[package]]
1435name = "tower-service" 1565name = "tower-service"
1436version = "0.3.1" 1566version = "0.3.1"
1437source = "registry+https://github.com/rust-lang/crates.io-index" 1567source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1745,6 +1875,12 @@ dependencies = [
1745] 1875]
1746 1876
1747[[package]] 1877[[package]]
1878name = "wyz"
1879version = "0.2.0"
1880source = "registry+https://github.com/rust-lang/crates.io-index"
1881checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214"
1882
1883[[package]]
1748name = "zeroize" 1884name = "zeroize"
1749version = "1.2.0" 1885version = "1.2.0"
1750source = "registry+https://github.com/rust-lang/crates.io-index" 1886source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index b5733b2..b505ba4 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -25,6 +25,7 @@ base64 = "0.13.0"
25sha2 = "0.9.3" 25sha2 = "0.9.3"
26block-modes = "0.7.0" 26block-modes = "0.7.0"
27aes = "0.6.0" 27aes = "0.6.0"
28askama = "0.10.5"
28 29
29[dev-dependencies] 30[dev-dependencies]
30serde_test = "1.0.117" 31serde_test = "1.0.117"
diff --git a/src/handlers.rs b/src/handlers.rs
index a8c9947..b3a6fa8 100644
--- a/src/handlers.rs
+++ b/src/handlers.rs
@@ -1,5 +1,6 @@
1/// API handlers, the ends of each filter chain
2use aes::Aes128; 1use aes::Aes128;
2/// API handlers, the ends of each filter chain
3use askama::Template;
3use base64; 4use base64;
4use blake2::{Blake2s, Digest}; 5use blake2::{Blake2s, Digest};
5use block_modes::block_padding::Pkcs7; 6use block_modes::block_padding::Pkcs7;
@@ -599,3 +600,19 @@ fn authorize_proposer(jwt_token: String, user_pem: &String) -> Result<TokenData<
599 600
600 Ok(token_payload) 601 Ok(token_payload)
601} 602}
603
604#[derive(Template)]
605#[template(path = "welcome.html")]
606struct WelcomeTemplate<'a> {
607 title: &'a str,
608 body: &'a str,
609}
610
611pub async fn welcome_handler() -> Result<impl warp::Reply, warp::Rejection> {
612 let template = WelcomeTemplate {
613 title: "Welcome",
614 body: "To The Bookstore!",
615 };
616 let res = template.render().unwrap();
617 Ok(warp::reply::html(res))
618}
diff --git a/src/routes.rs b/src/routes.rs
index 280de35..f8d9605 100644
--- a/src/routes.rs
+++ b/src/routes.rs
@@ -7,7 +7,10 @@ use crate::schema::Db;
7 7
8/// Every route combined 8/// Every route combined
9pub fn consensus_routes(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { 9pub fn consensus_routes(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
10 transaction_list(db.clone()) 10 let welcome_route = warp::path::end().and_then(handlers::welcome_handler);
11
12 welcome_route
13 .or(transaction_list(db.clone()))
11 .or(register_user(db.clone())) 14 .or(register_user(db.clone()))
12 .or(auth_transaction_propose(db.clone())) 15 .or(auth_transaction_propose(db.clone()))
13 .or(auth_block_propose(db.clone())) 16 .or(auth_block_propose(db.clone()))
@@ -60,4 +63,3 @@ pub fn auth_block_propose(db: Db) -> impl Filter<Extract = impl Reply, Error = R
60 .and(custom_filters::with_db(db)) 63 .and(custom_filters::with_db(db))
61 .and_then(handlers::authorized_propose_block) 64 .and_then(handlers::authorized_propose_block)
62} 65}
63
diff --git a/templates/css.html b/templates/css.html
new file mode 100644
index 0000000..c9d54e3
--- /dev/null
+++ b/templates/css.html
@@ -0,0 +1,8 @@
1<style>
2 td, th {
3 padding: 8px;
4 }
5 th {
6 text-align: left;
7 }
8</style>
diff --git a/templates/footer.html b/templates/footer.html
new file mode 100644
index 0000000..2ab5c0d
--- /dev/null
+++ b/templates/footer.html
@@ -0,0 +1,2 @@
1 </body>
2</html>
diff --git a/templates/header.html b/templates/header.html
new file mode 100644
index 0000000..fffbefe
--- /dev/null
+++ b/templates/header.html
@@ -0,0 +1,11 @@
1<html>
2 <head>
3 <title>Bookstore</title>
4 {% include "css.html" %}
5 </head>
6 <body>
7 <div>
8 <h1>Bookstore</h1>
9 </div>
10 {% include "menu.html" %}
11 <hr />
diff --git a/templates/menu.html b/templates/menu.html
new file mode 100644
index 0000000..0f4e85f
--- /dev/null
+++ b/templates/menu.html
@@ -0,0 +1,5 @@
1<div class="menu">
2 <span class="menuitem">
3 <a href = "/books/list">Books</a>
4 </span>
5</div>
diff --git a/templates/welcome.html b/templates/welcome.html
new file mode 100644
index 0000000..ca60f33
--- /dev/null
+++ b/templates/welcome.html
@@ -0,0 +1,8 @@
1{% include "header.html" %}
2<div class="entry">
3 <h1>{{title}}</h1>
4 <div class="body">
5 {{body}}
6 </div>
7</div>
8{% include "footer.html" %}