diff options
| -rw-r--r-- | Cargo.lock | 136 | ||||
| -rw-r--r-- | Cargo.toml | 1 | ||||
| -rw-r--r-- | src/handlers.rs | 19 | ||||
| -rw-r--r-- | src/routes.rs | 6 | ||||
| -rw-r--r-- | templates/css.html | 8 | ||||
| -rw-r--r-- | templates/footer.html | 2 | ||||
| -rw-r--r-- | templates/header.html | 11 | ||||
| -rw-r--r-- | templates/menu.html | 5 | ||||
| -rw-r--r-- | templates/welcome.html | 8 | 
9 files changed, 193 insertions, 3 deletions
| @@ -41,6 +41,58 @@ dependencies = [ | |||
| 41 | ] | 41 | ] | 
| 42 | 42 | ||
| 43 | [[package]] | 43 | [[package]] | 
| 44 | name = "arrayvec" | ||
| 45 | version = "0.5.2" | ||
| 46 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 47 | checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" | ||
| 48 | |||
| 49 | [[package]] | ||
| 50 | name = "askama" | ||
| 51 | version = "0.10.5" | ||
| 52 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 53 | checksum = "d298738b6e47e1034e560e5afe63aa488fea34e25ec11b855a76f0d7b8e73134" | ||
| 54 | dependencies = [ | ||
| 55 | "askama_derive", | ||
| 56 | "askama_escape", | ||
| 57 | "askama_shared", | ||
| 58 | ] | ||
| 59 | |||
| 60 | [[package]] | ||
| 61 | name = "askama_derive" | ||
| 62 | version = "0.10.5" | ||
| 63 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 64 | checksum = "ca2925c4c290382f9d2fa3d1c1b6a63fa1427099721ecca4749b154cc9c25522" | ||
| 65 | dependencies = [ | ||
| 66 | "askama_shared", | ||
| 67 | "proc-macro2", | ||
| 68 | "syn", | ||
| 69 | ] | ||
| 70 | |||
| 71 | [[package]] | ||
| 72 | name = "askama_escape" | ||
| 73 | version = "0.10.1" | ||
| 74 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 75 | checksum = "90c108c1a94380c89d2215d0ac54ce09796823cca0fd91b299cfff3b33e346fb" | ||
| 76 | |||
| 77 | [[package]] | ||
| 78 | name = "askama_shared" | ||
| 79 | version = "0.11.1" | ||
| 80 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 81 | checksum = "2582b77e0f3c506ec4838a25fa8a5f97b9bed72bb6d3d272ea1c031d8bd373bc" | ||
| 82 | dependencies = [ | ||
| 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]] | ||
| 44 | name = "atty" | 96 | name = "atty" | 
| 45 | version = "0.2.14" | 97 | version = "0.2.14" | 
| 46 | source = "registry+https://github.com/rust-lang/crates.io-index" | 98 | source = "registry+https://github.com/rust-lang/crates.io-index" | 
| @@ -82,6 +134,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
| 82 | checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" | 134 | checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" | 
| 83 | 135 | ||
| 84 | [[package]] | 136 | [[package]] | 
| 137 | name = "bitvec" | ||
| 138 | version = "0.19.5" | ||
| 139 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 140 | checksum = "8942c8d352ae1838c9dda0b0ca2ab657696ef2232a20147cf1b30ae1a9cb4321" | ||
| 141 | dependencies = [ | ||
| 142 | "funty", | ||
| 143 | "radium", | ||
| 144 | "tap", | ||
| 145 | "wyz", | ||
| 146 | ] | ||
| 147 | |||
| 148 | [[package]] | ||
| 85 | name = "blake2" | 149 | name = "blake2" | 
| 86 | version = "0.9.1" | 150 | version = "0.9.1" | 
| 87 | source = "registry+https://github.com/rust-lang/crates.io-index" | 151 | source = "registry+https://github.com/rust-lang/crates.io-index" | 
| @@ -278,6 +342,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
| 278 | checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" | 342 | checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" | 
| 279 | 343 | ||
| 280 | [[package]] | 344 | [[package]] | 
| 345 | name = "funty" | ||
| 346 | version = "1.1.0" | ||
| 347 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 348 | checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7" | ||
| 349 | |||
| 350 | [[package]] | ||
| 281 | name = "futures" | 351 | name = "futures" | 
| 282 | version = "0.3.14" | 352 | version = "0.3.14" | 
| 283 | source = "registry+https://github.com/rust-lang/crates.io-index" | 353 | source = "registry+https://github.com/rust-lang/crates.io-index" | 
| @@ -376,6 +446,7 @@ name = "gradecoin" | |||
| 376 | version = "0.1.0" | 446 | version = "0.1.0" | 
| 377 | dependencies = [ | 447 | dependencies = [ | 
| 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" | |||
| 496 | checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47" | 567 | checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47" | 
| 497 | 568 | ||
| 498 | [[package]] | 569 | [[package]] | 
| 570 | name = "humansize" | ||
| 571 | version = "1.1.0" | ||
| 572 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 573 | checksum = "b6cab2627acfc432780848602f3f558f7e9dd427352224b0d9324025796d2a5e" | ||
| 574 | |||
| 575 | [[package]] | ||
| 499 | name = "humantime" | 576 | name = "humantime" | 
| 500 | version = "1.3.0" | 577 | version = "1.3.0" | 
| 501 | source = "registry+https://github.com/rust-lang/crates.io-index" | 578 | source = "registry+https://github.com/rust-lang/crates.io-index" | 
| @@ -616,6 +693,19 @@ dependencies = [ | |||
| 616 | ] | 693 | ] | 
| 617 | 694 | ||
| 618 | [[package]] | 695 | [[package]] | 
| 696 | name = "lexical-core" | ||
| 697 | version = "0.7.5" | ||
| 698 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 699 | checksum = "21f866863575d0e1d654fbeeabdc927292fdf862873dc3c96c6f753357e13374" | ||
| 700 | dependencies = [ | ||
| 701 | "arrayvec", | ||
| 702 | "bitflags", | ||
| 703 | "cfg-if 1.0.0", | ||
| 704 | "ryu", | ||
| 705 | "static_assertions", | ||
| 706 | ] | ||
| 707 | |||
| 708 | [[package]] | ||
| 619 | name = "libc" | 709 | name = "libc" | 
| 620 | version = "0.2.93" | 710 | version = "0.2.93" | 
| 621 | source = "registry+https://github.com/rust-lang/crates.io-index" | 711 | source = "registry+https://github.com/rust-lang/crates.io-index" | 
| @@ -745,6 +835,19 @@ dependencies = [ | |||
| 745 | ] | 835 | ] | 
| 746 | 836 | ||
| 747 | [[package]] | 837 | [[package]] | 
| 838 | name = "nom" | ||
| 839 | version = "6.1.2" | ||
| 840 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 841 | checksum = "e7413f999671bd4745a7b624bd370a569fb6bc574b23c83a3c5ed2e453f3d5e2" | ||
| 842 | dependencies = [ | ||
| 843 | "bitvec", | ||
| 844 | "funty", | ||
| 845 | "lexical-core", | ||
| 846 | "memchr", | ||
| 847 | "version_check", | ||
| 848 | ] | ||
| 849 | |||
| 850 | [[package]] | ||
| 748 | name = "num-bigint" | 851 | name = "num-bigint" | 
| 749 | version = "0.2.6" | 852 | version = "0.2.6" | 
| 750 | source = "registry+https://github.com/rust-lang/crates.io-index" | 853 | source = "registry+https://github.com/rust-lang/crates.io-index" | 
| @@ -968,6 +1071,12 @@ dependencies = [ | |||
| 968 | ] | 1071 | ] | 
| 969 | 1072 | ||
| 970 | [[package]] | 1073 | [[package]] | 
| 1074 | name = "radium" | ||
| 1075 | version = "0.5.3" | ||
| 1076 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1077 | checksum = "941ba9d78d8e2f7ce474c015eea4d9c6d25b6a3327f9832ee29a4de27f91bbb8" | ||
| 1078 | |||
| 1079 | [[package]] | ||
| 971 | name = "rand" | 1080 | name = "rand" | 
| 972 | version = "0.7.3" | 1081 | version = "0.7.3" | 
| 973 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1082 | source = "registry+https://github.com/rust-lang/crates.io-index" | 
| @@ -1279,6 +1388,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
| 1279 | checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" | 1388 | checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" | 
| 1280 | 1389 | ||
| 1281 | [[package]] | 1390 | [[package]] | 
| 1391 | name = "static_assertions" | ||
| 1392 | version = "1.1.0" | ||
| 1393 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1394 | checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" | ||
| 1395 | |||
| 1396 | [[package]] | ||
| 1282 | name = "subtle" | 1397 | name = "subtle" | 
| 1283 | version = "2.4.0" | 1398 | version = "2.4.0" | 
| 1284 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1399 | source = "registry+https://github.com/rust-lang/crates.io-index" | 
| @@ -1308,6 +1423,12 @@ dependencies = [ | |||
| 1308 | ] | 1423 | ] | 
| 1309 | 1424 | ||
| 1310 | [[package]] | 1425 | [[package]] | 
| 1426 | name = "tap" | ||
| 1427 | version = "1.0.1" | ||
| 1428 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1429 | checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" | ||
| 1430 | |||
| 1431 | [[package]] | ||
| 1311 | name = "tempfile" | 1432 | name = "tempfile" | 
| 1312 | version = "3.2.0" | 1433 | version = "3.2.0" | 
| 1313 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1434 | source = "registry+https://github.com/rust-lang/crates.io-index" | 
| @@ -1432,6 +1553,15 @@ dependencies = [ | |||
| 1432 | ] | 1553 | ] | 
| 1433 | 1554 | ||
| 1434 | [[package]] | 1555 | [[package]] | 
| 1556 | name = "toml" | ||
| 1557 | version = "0.5.8" | ||
| 1558 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1559 | checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" | ||
| 1560 | dependencies = [ | ||
| 1561 | "serde", | ||
| 1562 | ] | ||
| 1563 | |||
| 1564 | [[package]] | ||
| 1435 | name = "tower-service" | 1565 | name = "tower-service" | 
| 1436 | version = "0.3.1" | 1566 | version = "0.3.1" | 
| 1437 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1567 | source = "registry+https://github.com/rust-lang/crates.io-index" | 
| @@ -1745,6 +1875,12 @@ dependencies = [ | |||
| 1745 | ] | 1875 | ] | 
| 1746 | 1876 | ||
| 1747 | [[package]] | 1877 | [[package]] | 
| 1878 | name = "wyz" | ||
| 1879 | version = "0.2.0" | ||
| 1880 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1881 | checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214" | ||
| 1882 | |||
| 1883 | [[package]] | ||
| 1748 | name = "zeroize" | 1884 | name = "zeroize" | 
| 1749 | version = "1.2.0" | 1885 | version = "1.2.0" | 
| 1750 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1886 | source = "registry+https://github.com/rust-lang/crates.io-index" | 
| @@ -25,6 +25,7 @@ base64 = "0.13.0" | |||
| 25 | sha2 = "0.9.3" | 25 | sha2 = "0.9.3" | 
| 26 | block-modes = "0.7.0" | 26 | block-modes = "0.7.0" | 
| 27 | aes = "0.6.0" | 27 | aes = "0.6.0" | 
| 28 | askama = "0.10.5" | ||
| 28 | 29 | ||
| 29 | [dev-dependencies] | 30 | [dev-dependencies] | 
| 30 | serde_test = "1.0.117" | 31 | serde_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 | ||
| 2 | use aes::Aes128; | 1 | use aes::Aes128; | 
| 2 | /// API handlers, the ends of each filter chain | ||
| 3 | use askama::Template; | ||
| 3 | use base64; | 4 | use base64; | 
| 4 | use blake2::{Blake2s, Digest}; | 5 | use blake2::{Blake2s, Digest}; | 
| 5 | use block_modes::block_padding::Pkcs7; | 6 | use 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")] | ||
| 606 | struct WelcomeTemplate<'a> { | ||
| 607 | title: &'a str, | ||
| 608 | body: &'a str, | ||
| 609 | } | ||
| 610 | |||
| 611 | pub 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 | 
| 9 | pub fn consensus_routes(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { | 9 | pub 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" %} | ||
