From 9706cf0a6287a896e0ec2071c54e3da5680bf563 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Sun, 7 Feb 2021 17:52:10 +0100 Subject: [PATCH] flash messages etc --- Cargo.lock | 194 +++++++++++++++- yopa-web/Cargo.toml | 2 + yopa-web/resources/static/style.css | 15 ++ .../resources/templates/_layout.html.tera | 19 +- .../resources/templates/_macros.html.tera | 8 + yopa-web/resources/templates/index.html.tera | 20 +- .../templates/model_create.html.tera | 8 - yopa-web/src/main.rs | 207 ++++++++++-------- yopa-web/src/routes.rs | 59 ++++- yopa-web/src/session_ext.rs | 39 ++++ yopa/src/lib.rs | 24 +- yopa/src/model.rs | 2 - yopa/src/tests.rs | 1 - 13 files changed, 472 insertions(+), 126 deletions(-) create mode 100644 yopa-web/resources/templates/_macros.html.tera create mode 100644 yopa-web/src/session_ext.rs diff --git a/Cargo.lock b/Cargo.lock index 81f4c05..9103e30 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -47,7 +47,7 @@ dependencies = [ "actix-service", "actix-threadpool", "actix-utils", - "base64", + "base64 0.13.0", "bitflags", "brotli2", "bytes 0.5.6", @@ -150,6 +150,22 @@ dependencies = [ "pin-project 0.4.27", ] +[[package]] +name = "actix-session" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfe0c795741b7a1a6f8eb46680c5a0f6f53484d054226a7af9a86195dfc2c14d" +dependencies = [ + "actix-service", + "actix-web", + "bytes 0.5.6", + "derive_more", + "futures-util", + "serde", + "serde_json", + "time 0.2.25", +] + [[package]] name = "actix-testing" version = "1.0.1" @@ -290,6 +306,60 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e" +[[package]] +name = "aead" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fc95d1bdb8e6666b2b217308eeeb09f2d6728d104be3e31916cc74d15420331" +dependencies = [ + "generic-array 0.14.4", +] + +[[package]] +name = "aes" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "884391ef1066acaa41e766ba8f596341b96e93ce34f9a43e7d24bf0a0eaf0561" +dependencies = [ + "aes-soft", + "aesni", + "cipher", +] + +[[package]] +name = "aes-gcm" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5278b5fabbb9bd46e24aa69b2fdea62c99088e0a950a9be40e3e0101298f88da" +dependencies = [ + "aead", + "aes", + "cipher", + "ctr", + "ghash", + "subtle", +] + +[[package]] +name = "aes-soft" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be14c7498ea50828a38d0e24a765ed2effe92a705885b57d029cd67d45744072" +dependencies = [ + "cipher", + "opaque-debug 0.3.0", +] + +[[package]] +name = "aesni" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea2e11f5e94c2f7d386164cc2aa1f97823fed6f259e486940a71c174dd01b0ce" +dependencies = [ + "cipher", + "opaque-debug 0.3.0", +] + [[package]] name = "aho-corasick" version = "0.7.15" @@ -332,7 +402,7 @@ dependencies = [ "actix-http", "actix-rt", "actix-service", - "base64", + "base64 0.13.0", "bytes 0.5.6", "cfg-if 1.0.0", "derive_more", @@ -366,6 +436,12 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4521f3e3d031370679b3b140beb36dfe4801b09ac77e30c61941f97df3ef28b" +[[package]] +name = "base64" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" + [[package]] name = "base64" version = "0.13.0" @@ -517,6 +593,15 @@ dependencies = [ "parse-zoneinfo", ] +[[package]] +name = "cipher" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12f8e7987cbd042a63249497f41aed09f8e65add917ea6566effbc56578d6801" +dependencies = [ + "generic-array 0.14.4", +] + [[package]] name = "const_fn" version = "0.4.5" @@ -529,7 +614,13 @@ version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "784ad0fbab4f3e9cef09f20e0aea6000ae08d2cb98ac4c0abc53df18803d702f" dependencies = [ + "aes-gcm", + "base64 0.12.3", + "hkdf", + "hmac", "percent-encoding", + "rand 0.7.3", + "sha2", "time 0.2.25", "version_check", ] @@ -546,6 +637,12 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634" +[[package]] +name = "cpuid-bool" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcb25d077389e53838a8158c8e99174c5a9d902dee4904320db714f3c653ffba" + [[package]] name = "crc32fast" version = "1.2.1" @@ -566,6 +663,25 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "crypto-mac" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4857fd85a0c34b3c3297875b747c1e02e06b6a0ea32dd892d8192b9ce0813ea6" +dependencies = [ + "generic-array 0.14.4", + "subtle", +] + +[[package]] +name = "ctr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb4a30d54f7443bf3d6191dcd486aca19e67cb3c49fa7a06a319966346707e7f" +dependencies = [ + "cipher", +] + [[package]] name = "derive_more" version = "0.99.11" @@ -817,6 +933,16 @@ dependencies = [ "wasi 0.10.2+wasi-snapshot-preview1", ] +[[package]] +name = "ghash" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97304e4cd182c3846f7575ced3890c53012ce534ad9114046b0a9e00bb30a375" +dependencies = [ + "opaque-debug 0.3.0", + "polyval", +] + [[package]] name = "gimli" version = "0.23.0" @@ -897,6 +1023,26 @@ dependencies = [ "libc", ] +[[package]] +name = "hkdf" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51ab2f639c231793c5f6114bdb9bbe50a7dbbfcd7c7c6bd8475dec2d991e964f" +dependencies = [ + "digest 0.9.0", + "hmac", +] + +[[package]] +name = "hmac" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1441c6b1e930e2817404b5046f1f989899143a12bf92de603b69f4e0aee1e15" +dependencies = [ + "crypto-mac", + "digest 0.9.0", +] + [[package]] name = "hostname" version = "0.3.1" @@ -1425,6 +1571,17 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "polyval" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eebcc4aa140b9abd2bc40d9c3f7ccec842679cd79045ac3a7ac698c1a064b7cd" +dependencies = [ + "cpuid-bool 0.2.0", + "opaque-debug 0.3.0", + "universal-hash", +] + [[package]] name = "ppv-lite86" version = "0.2.10" @@ -1696,7 +1853,7 @@ checksum = "f4b312c3731e3fe78a185e6b9b911a7aa715b8e31cce117975219aab2acf285d" dependencies = [ "block-buffer 0.9.0", "cfg-if 1.0.0", - "cpuid-bool", + "cpuid-bool 0.1.2", "digest 0.9.0", "opaque-debug 0.3.0", ] @@ -1707,6 +1864,19 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d" +[[package]] +name = "sha2" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa827a14b29ab7f44778d14a88d3cb76e949c45083f7dbfa507d0cb699dc12de" +dependencies = [ + "block-buffer 0.9.0", + "cfg-if 1.0.0", + "cpuid-bool 0.1.2", + "digest 0.9.0", + "opaque-debug 0.3.0", +] + [[package]] name = "signal-hook-registry" version = "1.3.0" @@ -1817,6 +1987,12 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" +[[package]] +name = "subtle" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2" + [[package]] name = "syn" version = "1.0.60" @@ -2183,6 +2359,16 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" +[[package]] +name = "universal-hash" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8326b2c654932e3e4f9196e69d08fdf7cfd718e1dc6f66b347e6024a0c961402" +dependencies = [ + "generic-array 0.14.4", + "subtle", +] + [[package]] name = "url" version = "2.2.0" @@ -2375,12 +2561,14 @@ dependencies = [ name = "yopa-web" version = "0.1.0" dependencies = [ + "actix-session", "actix-web", "actix-web-static-files", "include_dir", "log", "once_cell", "parking_lot", + "rand 0.8.3", "serde", "serde_json", "simple-logging", diff --git a/yopa-web/Cargo.toml b/yopa-web/Cargo.toml index 1d27787..e7b3e23 100644 --- a/yopa-web/Cargo.toml +++ b/yopa-web/Cargo.toml @@ -15,11 +15,13 @@ serde_json = "1" log = "0.4.14" simple-logging = "2.0.2" actix-web = "3" +actix-session = "0.4.0" parking_lot = "0.11.1" include_dir = "0.6.0" tera = "1.6.1" actix-web-static-files = "3.0" once_cell = "1.5.2" +rand = "0.8.3" tokio = { version="0.2.6", features=["full"] } diff --git a/yopa-web/resources/static/style.css b/yopa-web/resources/static/style.css index 0d3d425..b44166a 100644 --- a/yopa-web/resources/static/style.css +++ b/yopa-web/resources/static/style.css @@ -205,3 +205,18 @@ textarea:focus, li { padding-bottom: .5rem; } + +.toast { + border: 1px solid black; + border-radius: 5px; + padding: .5rem; + margin: .5rem 0; +} + +.toast.error { + border-color: #dc143c; +} + +.toast.success { + border-color: #32cd32; +} diff --git a/yopa-web/resources/templates/_layout.html.tera b/yopa-web/resources/templates/_layout.html.tera index 190b7da..39c6f7f 100644 --- a/yopa-web/resources/templates/_layout.html.tera +++ b/yopa-web/resources/templates/_layout.html.tera @@ -2,17 +2,30 @@ - {% block title %}{% endblock title %} • YOPA + {% block title -%}{%- endblock title %} • YOPA
-{% block content %}{% endblock %} + +{%- if flash_error -%} +
+ {{ flash_error }} +
+{%- endif -%} + +{%- if flash_success -%} +
+ {{ flash_success }} +
+{%- endif -%} + +{%- block content -%}{%- endblock -%}
diff --git a/yopa-web/resources/templates/_macros.html.tera b/yopa-web/resources/templates/_macros.html.tera new file mode 100644 index 0000000..1860451 --- /dev/null +++ b/yopa-web/resources/templates/_macros.html.tera @@ -0,0 +1,8 @@ +{% macro describe_property(prop) %} + {{prop.name}}, {{prop.data_type}} + {%- if prop.default -%} + , default: "{{prop.default | print_typed_value}}" + {%- endif -%} + {%- if prop.optional %}, OPTIONAL{% endif %} + {%- if prop.multiple %}, MULTIPLE{% endif %} +{% endmacro input %} diff --git a/yopa-web/resources/templates/index.html.tera b/yopa-web/resources/templates/index.html.tera index 999ffb0..513ce8c 100644 --- a/yopa-web/resources/templates/index.html.tera +++ b/yopa-web/resources/templates/index.html.tera @@ -1,4 +1,5 @@ {% extends "_layout" %} +{% import "_macros" as macros %} {% block title -%} Index @@ -26,12 +27,7 @@ @@ -44,19 +40,17 @@