diff --git a/project/Cargo.lock b/project/Cargo.lock index 2fea478..0cff3a7 100644 --- a/project/Cargo.lock +++ b/project/Cargo.lock @@ -32,6 +32,17 @@ dependencies = [ "trust-dns-resolver 0.18.0-alpha.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "actix-cors" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "actix-service 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "actix-web 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "derive_more 0.99.3 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "actix-http" version = "1.0.1" @@ -70,14 +81,28 @@ dependencies = [ "pin-project 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "ring 0.16.12 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)", "serde_urlencoded 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "actix-identity" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "actix-service 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "actix-web 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "actix-macros" version = "0.1.1" @@ -227,7 +252,7 @@ dependencies = [ "pin-project 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)", "serde_urlencoded 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", "url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -304,7 +329,7 @@ dependencies = [ "percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)", "serde_urlencoded 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -431,6 +456,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "num-integer 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -460,6 +486,24 @@ name = "crypto" version = "0.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "csrf" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", + "data-encoding 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)", + "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "data-encoding" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "derive_more" version = "0.99.3" @@ -476,6 +520,7 @@ version = "1.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "diesel_derives 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "mysqlclient-sys 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -498,6 +543,27 @@ name = "dotenv" version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "dotenv_codegen" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "dotenv_codegen_implementation 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "dotenv_codegen_implementation" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "dotenv 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.16 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "dtoa" version = "0.4.5" @@ -575,6 +641,11 @@ name = "fnv" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "fuchsia-zircon" version = "0.3.3" @@ -679,6 +750,11 @@ dependencies = [ "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "gcc" +version = "0.3.55" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "generic-array" version = "0.12.3" @@ -823,7 +899,7 @@ dependencies = [ "pem 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.16.12 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)", "simple_asn1 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -864,6 +940,14 @@ dependencies = [ "scopeguard 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "log" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "log" version = "0.4.8" @@ -1109,12 +1193,17 @@ dependencies = [ name = "project" version = "0.1.0" dependencies = [ + "actix-cors 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "actix-identity 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "actix-rt 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "actix-web 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "bcrypt 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", + "chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "crypto 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "csrf 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "diesel 1.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "dotenv 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", + "dotenv_codegen 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "jsonwebtoken 7.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "r2d2 0.8.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1144,6 +1233,27 @@ dependencies = [ "scheduled-thread-pool 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rand" +version = "0.3.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rand" version = "0.7.3" @@ -1165,6 +1275,19 @@ dependencies = [ "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_core" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "rand_core" version = "0.5.1" @@ -1181,6 +1304,14 @@ dependencies = [ "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "redox_syscall" version = "0.1.56" @@ -1225,11 +1356,28 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rust-crypto" +version = "0.2.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rustc-demangle" version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "rustc-serialize" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "ryu" version = "1.0.3" @@ -1268,7 +1416,7 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.48" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "itoa 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1638,7 +1786,9 @@ dependencies = [ [metadata] "checksum actix-codec 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "09e55f0a5c2ca15795035d90c46bd0e73a5123b72f68f12596d6ba5282051380" "checksum actix-connect 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c95cc9569221e9802bf4c377f6c18b90ef10227d787611decf79fd47d2a8e76c" +"checksum actix-cors 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0a6206917d5c0fdd79d81cec9ef02d3e802df4abf276d96241e1f595d971e002" "checksum actix-http 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c16664cc4fdea8030837ad5a845eb231fb93fc3c5c171edfefb52fad92ce9019" +"checksum actix-identity 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2a379b0639c293292d71defb8cc1f94c87b7705c904adf044338ad392df77c7a" "checksum actix-macros 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "21705adc76bbe4bc98434890e73a89cd00c6015e5704a60bb6eea6c3b72316b6" "checksum actix-router 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "9d7a10ca4d94e8c8e7a87c5173aba1b97ba9a6563ca02b0e1cd23531093d3ec8" "checksum actix-rt 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3f6a0a55507046441a496b2f0d26a84a65e67c8cafffe279072412f624b5fb6d" @@ -1678,10 +1828,14 @@ dependencies = [ "checksum copyless 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6ff9c56c9fb2a49c05ef0e431485a22400af20d33226dc0764d891d09e724127" "checksum crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" "checksum crypto 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "897ed01ef28ee5a50671ea0760e99861c70f5e8b5660cd1a64c8cae9b8908317" +"checksum csrf 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "28232dc11b7c9d116ce6d996ff737d67c6701ef256a8eadc1941d3ab2666b140" +"checksum data-encoding 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "11c0346158a19b3627234e15596f5e465c360fcdb97d817bcb255e0510f5a788" "checksum derive_more 0.99.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a806e96c59a76a5ba6e18735b6cf833344671e61e7863f2edb5c518ea2cac95c" "checksum diesel 1.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "33d7ca63eb2efea87a7f56a283acc49e2ce4b2bd54adf7465dc1d81fef13d8fc" "checksum diesel_derives 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "45f5098f628d02a7a0f68ddba586fb61e80edec3bdc1be3b921f4ceec60858d3" "checksum dotenv 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" +"checksum dotenv_codegen 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "56966279c10e4f8ee8c22123a15ed74e7c8150b658b26c619c53f4a56eb4a8aa" +"checksum dotenv_codegen_implementation 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "53e737a3522cd45f6adc19b644ce43ef53e1e9045f2d2de425c1f468abd4cf33" "checksum dtoa 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "4358a9e11b9a09cf52383b451b49a169e8d797b68aa02301ff586d70d9661ea3" "checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" "checksum encoding_rs 0.8.22 (registry+https://github.com/rust-lang/crates.io-index)" = "cd8d03faa7fe0c1431609dfad7bbe827af30f82e1e2ae6f7ee4fca6bd764bc28" @@ -1691,6 +1845,7 @@ dependencies = [ "checksum failure_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "030a733c8287d6213886dd487564ff5c8f6aae10278b3588ed177f9d18f8d231" "checksum flate2 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6bd6d6f4752952feb71363cffc9ebac9411b75b87c6ab6058c40c8900cf43c0f" "checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" +"checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" "checksum futures 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5c329ae8753502fb44ae4fc2b622fa2a94652c41e795143765ba0927f92ab780" @@ -1703,6 +1858,7 @@ dependencies = [ "checksum futures-task 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7b0a34e53cf6cdcd0178aa573aed466b646eb3db769570841fda0c7ede375a27" "checksum futures-util 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "22766cf25d64306bedf0384da004d05c9974ab104fcc4528f1236181c18004c5" "checksum fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +"checksum gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)" = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" "checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" "checksum getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" "checksum h2 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9d5c295d1c0c68e4e42003d75f908f5e16a1edd1cbe0b0d02e4dc2006a384f47" @@ -1725,6 +1881,7 @@ dependencies = [ "checksum libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)" = "eb147597cdf94ed43ab7a9038716637d2d1bf2bc571da995d0028dec06bd3018" "checksum linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83" "checksum lock_api 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "79b2de95ecb4691949fea4716ca53cdbcfccb2c612e19644a8bad05edcf9f47b" +"checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" "checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" "checksum lru-cache 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "31e24f1ad8321ca0e8a1e0ac13f23cb668e6f5466c2c57319f6a5cf1cc8e3b1c" "checksum match_cfg 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4" @@ -1758,22 +1915,29 @@ dependencies = [ "checksum quick-error 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" "checksum quote 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2bdc6c187c65bca4260c9011c9e3132efe4909da44726bad24cf7572ae338d7f" "checksum r2d2 0.8.8 (registry+https://github.com/rust-lang/crates.io-index)" = "1497e40855348e4a8a40767d8e55174bce1e445a3ac9254ad44ad468ee0485af" +"checksum rand 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)" = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c" +"checksum rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" "checksum rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" "checksum rand_chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +"checksum rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" "checksum rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" "checksum rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +"checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" "checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" "checksum regex 1.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8900ebc1363efa7ea1c399ccc32daed870b4002651e0bed86e72d501ebbe0048" "checksum regex-syntax 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)" = "7fe5bd57d1d7414c6b5ed48563a2c855d995ff777729dcd91c369ec7fea395ae" "checksum resolv-conf 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "11834e137f3b14e309437a8276714eed3a80d1ef894869e510f2c0c0b98b9f4a" "checksum ring 0.16.12 (registry+https://github.com/rust-lang/crates.io-index)" = "1ba5a8ec64ee89a76c98c549af81ff14813df09c3e6dc4766c3856da48597a0c" +"checksum rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)" = "f76d05d3993fd5f4af9434e8e436db163a12a9d40e1a58a726f27a01dfd12a2a" "checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" +"checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" "checksum ryu 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535622e6be132bccd223f4bb2b8ac8d53cda3c7a6394944d3b2b33fb974f9d76" "checksum scheduled-thread-pool 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "0988d7fdf88d5e5fcf5923a0f1e8ab345f3e98ab4bc6bc45a2d5ff7f7458fbf6" "checksum scopeguard 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" "checksum serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449" "checksum serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "128f9e303a5a29922045a830221b8f78ec74a5f544944f3d5984f8ec3895ef64" -"checksum serde_json 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)" = "9371ade75d4c2d6cb154141b9752cf3781ec9c05e0e5cf35060e1e70ee7b9c25" +"checksum serde_json 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)" = "78a7a12c167809363ec3bd7329fc0a3369056996de43c4b37ef3cd54a6ce4867" "checksum serde_urlencoded 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9ec5d77e2d4c73717816afac02670d5c4f534ea95ed430442cad02e7a6e32c97" "checksum sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d" "checksum signal-hook-registry 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94f478ede9f64724c5d173d7bb56099ec3e2d9fc2774aac65d34b8b890405f41" diff --git a/project/Cargo.toml b/project/Cargo.toml index c353335..b1c9ff8 100644 --- a/project/Cargo.toml +++ b/project/Cargo.toml @@ -9,11 +9,16 @@ edition = "2018" [dependencies] actix-web = "2.0.0" actix-rt = "1.0.0" -serde = "1.0.104" -diesel = { version = "1.4.3", features = ["mysql","r2d2"] } +serde = { version = "1.0.104", features = ["derive"] } +diesel = { version = "1.4.3", features = ["mysql", "r2d2", "chrono"] } dotenv = "0.15.0" bcrypt = "0.6.2" env_logger = "0.7.1" r2d2 = "0.8.8" crypto = "0.0.2" jsonwebtoken = "7.1.0" +chrono = { version = "0.4.11", features = ["serde"] } +csrf = "0.3.1" +actix-cors = "0.2.0" +actix-identity = "0.2.1" +dotenv_codegen = "0.15.0" diff --git a/project/migrations/2020-03-24-142210_users/src/schema.rs b/project/migrations/2020-03-24-142210_users/src/schema.rs deleted file mode 100644 index 63126c8..0000000 --- a/project/migrations/2020-03-24-142210_users/src/schema.rs +++ /dev/null @@ -1,8 +0,0 @@ -table! { - users (id) { - id -> Integer, - username -> Varchar, - is_admin -> Bool, - password_hash -> Varchar, - } -} diff --git a/project/migrations/2020-03-24-142210_users/down.sql b/project/migrations/2020-04-04-120638_create_users/down.sql similarity index 100% rename from project/migrations/2020-03-24-142210_users/down.sql rename to project/migrations/2020-04-04-120638_create_users/down.sql diff --git a/project/migrations/2020-03-24-142210_users/up.sql b/project/migrations/2020-04-04-120638_create_users/up.sql similarity index 61% rename from project/migrations/2020-03-24-142210_users/up.sql rename to project/migrations/2020-04-04-120638_create_users/up.sql index 18bb598..9f8a82d 100644 --- a/project/migrations/2020-03-24-142210_users/up.sql +++ b/project/migrations/2020-04-04-120638_create_users/up.sql @@ -1,7 +1,8 @@ CREATE TABLE users ( `id` int NOT NULL AUTO_INCREMENT, `username` varchar(100) UNIQUE NOT NULL, - `is_admin` boolean NOT NULL, - `password_hash` varchar(128) NOT NULL, + `password` varchar(128) NOT NULL, + `admin` boolean NOT NULL, + `created_at` timestamp NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/project/schema.rs b/project/schema.rs deleted file mode 100644 index dabaead..0000000 --- a/project/schema.rs +++ /dev/null @@ -1,8 +0,0 @@ -table! { - users (id) { - id -> Integer, - username -> Varchar, - is_admin -> Nullable, - password_hash -> Nullable, - } -} diff --git a/project/src/actions.rs b/project/src/actions.rs deleted file mode 100644 index 4d478ba..0000000 --- a/project/src/actions.rs +++ /dev/null @@ -1,50 +0,0 @@ -extern crate bcrypt; - -use crate::models; -use bcrypt::{hash, DEFAULT_COST}; -use diesel::prelude::*; - -pub fn insert_new_user( - name: &str, - password: &str, - conn: &MysqlConnection, -) -> Result { - use crate::schema::users::dsl::*; - - let new_user = models::NewUser { - username: name.to_owned(), - password_hash: hash(password, DEFAULT_COST).unwrap(), - is_admin: false, - }; - - diesel::insert_into(users).values(&new_user).execute(conn)?; - Ok(new_user) -} - -pub fn find_user_by_name( - name: &str, - conn: &MysqlConnection, -) -> Result, diesel::result::Error> { - use crate::schema::users::dsl::*; - - let user = users - .filter(username.eq(name)) - .first::(conn) - .optional()?; - - Ok(user) -} - -pub fn find_user_by_id( - id: u16, - conn: &MysqlConnection, -) -> Result, diesel::result::Error> { - use crate::schema::users::dsl::*; - - let user = users - .filter(id.eq(id)) - .first::(conn) - .optional()?; - - Ok(user) -} diff --git a/project/src/auth.rs b/project/src/auth.rs deleted file mode 100644 index 129ced5..0000000 --- a/project/src/auth.rs +++ /dev/null @@ -1,78 +0,0 @@ -extern crate bcrypt; - -use crate::models; -use bcrypt::verify; -use diesel::prelude::*; -use jsonwebtoken::{decode, encode, DecodingKey, EncodingKey, Header, Validation}; -use serde::{Deserialize, Serialize}; -use std::error::Error; -use std::fmt; - -#[derive(Debug, Serialize, Deserialize)] -struct Claims { - issuer: String, - user: String, - is_admin: bool, - exp: usize, -} - -#[derive(Debug)] -struct PasswordMatchError; - -impl fmt::Display for PasswordMatchError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "Passwords do not match") - } -} - -impl Error for PasswordMatchError { - fn source(&self) -> Option<&(dyn Error + 'static)> { - None - } -} - -pub fn new_token( - uname: &str, - password: &str, - conn: &MysqlConnection, -) -> Result> { - use crate::schema::users::dsl::*; - let user = users - .filter(username.eq(uname)) - .first::(conn) - .unwrap(); - - if !verify(password, &user.password_hash).unwrap() { - return Err(Box::new(PasswordMatchError)); - } - - let secret = std::env::var("SECRET").expect("SECRET"); - let key = secret.as_bytes(); - - let my_claims = Claims { - issuer: "example.com".to_owned(), - user: user.username.to_owned(), - is_admin: user.is_admin.to_owned(), - exp: 10000000000, - }; - - match encode( - &Header::default(), - &my_claims, - &EncodingKey::from_secret(key), - ) { - Ok(t) => Ok(t), - Err(err) => Err(Box::new(err)), - } -} - -pub fn validate_token(token: &str) -> Result { - let secret = std::env::var("SECRET").expect("SECRET"); - let key = secret.as_bytes(); - - let validation = Validation::default(); - match decode::(&token, &DecodingKey::from_secret(key), &validation) { - Ok(c) => return Ok(true), - Err(e) => return Err(e), - }; -} diff --git a/project/src/db_connection.rs b/project/src/db_connection.rs new file mode 100644 index 0000000..a97ea3d --- /dev/null +++ b/project/src/db_connection.rs @@ -0,0 +1,15 @@ +use diesel::r2d2::{ConnectionManager, Pool, PoolError, PooledConnection}; +use diesel::MysqlConnection; + +pub type DbPool = r2d2::Pool>; +pub type MyPooledConnection = PooledConnection>; + +fn init_pool(database_url: &str) -> Result { + let manager = ConnectionManager::::new(database_url); + Pool::builder().build(manager) +} + +pub fn get_pool() -> DbPool { + let connspec = std::env::var("DATABASE_URL").expect("DATABASE_URL"); + init_pool(&connspec).expect("Failed to create DB pool") +} diff --git a/project/src/errors.rs b/project/src/errors.rs new file mode 100644 index 0000000..6a2536f --- /dev/null +++ b/project/src/errors.rs @@ -0,0 +1,33 @@ +use bcrypt::BcryptError; +use diesel::result; +use std::fmt; + +pub enum CustomError { + HashError(BcryptError), + DBError(result::Error), + PasswordMatchError(String), + PasswordWrong(String), +} + +impl From for CustomError { + fn from(error: BcryptError) -> Self { + CustomError::HashError(error) + } +} + +impl From for CustomError { + fn from(error: result::Error) -> Self { + CustomError::DBError(error) + } +} + +impl std::fmt::Display for CustomError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + CustomError::HashError(error) => write!(f, "{}", error), + CustomError::DBError(error) => write!(f, "{}", error), + CustomError::PasswordMatchError(error) => write!(f, "{}", error), + CustomError::PasswordWrong(error) => write!(f, "{}", error), + } + } +} diff --git a/project/src/handlers/authentication.rs b/project/src/handlers/authentication.rs new file mode 100644 index 0000000..d0468bc --- /dev/null +++ b/project/src/handlers/authentication.rs @@ -0,0 +1 @@ +pub fn login() {} diff --git a/project/src/handlers/mod.rs b/project/src/handlers/mod.rs new file mode 100644 index 0000000..24edc59 --- /dev/null +++ b/project/src/handlers/mod.rs @@ -0,0 +1,10 @@ +pub mod authentication; +pub mod register; + +use crate::db_connection::{DbPool, MyPooledConnection}; +use actix_web::{web, HttpResponse}; + +pub fn pool_handler(pool: web::Data) -> Result { + pool.get() + .map_err(|e| HttpResponse::InternalServerError().json(e.to_string())) +} diff --git a/project/src/handlers/register.rs b/project/src/handlers/register.rs new file mode 100644 index 0000000..0e89e81 --- /dev/null +++ b/project/src/handlers/register.rs @@ -0,0 +1,19 @@ +use crate::db_connection::DbPool; +use crate::handlers::pool_handler; +use crate::models::user::{RegisterUser, User}; +use actix_web::{web, HttpResponse}; + +pub fn register( + new_user: web::Json, + pool: web::Data, +) -> Result { + let my_pool = pool_handler(pool)?; + let register_user = new_user + .into_inner() + .validation() + .map_err(|e| HttpResponse::InternalServerError().json(e.to_string()))?; + + User::create(register_user, &my_pool) + .map(|user| HttpResponse::Ok().json(user)) + .map_err(|e| HttpResponse::InternalServerError().json(e.to_string())) +} diff --git a/project/src/main.rs b/project/src/main.rs index a73b330..93bae7d 100644 --- a/project/src/main.rs +++ b/project/src/main.rs @@ -1,87 +1,55 @@ #[macro_use] extern crate diesel; +extern crate csrf; +extern crate dotenv; +#[macro_use] +extern crate dotenv_codegen; -use actix_web::{middleware, post, web, App, Error, HttpResponse, HttpServer}; -use diesel::prelude::*; -use diesel::r2d2::{self, ConnectionManager}; +pub mod db_connection; +pub mod errors; +pub mod handlers; +pub mod models; +pub mod schema; -mod actions; -mod auth; -mod models; -mod schema; - -type DbPool = r2d2::Pool>; - -#[post("/auth/get_token")] -async fn get_token( - pool: web::Data, - form: web::Json, -) -> Result { - let conn = pool.get().expect("Pool did not give a connection"); - - let token = web::block(move || auth::new_token(&form.username, &form.password, &conn)) - .await - .map_err(|e| { - eprintln!("{}", &e); - HttpResponse::Unauthorized().json("Failed to create token. Password might be wrong") - })?; - - Ok(HttpResponse::Ok().json(token)) -} - -#[post("/auth/validate_token")] -async fn validate_token(form: web::Json) -> Result { - let token_data = web::block(move || auth::validate_token(&form.token)) - .await - .map_err(|e| { - eprintln!("{}", &e); - HttpResponse::Unauthorized().json("Token is not valid") - })?; - - Ok(HttpResponse::Ok().json(token_data)) -} - -#[post("/users/add")] -async fn add_user( - pool: web::Data, - form: web::Json, -) -> Result { - let conn = pool.get().expect("Pool did not give a connection"); - - // use web::block to offload blocking Diesel code without blocking server thread - let user = - web::block(move || actions::insert_new_user(&form.username, &form.password_hash, &conn)) - .await - .map_err(|e| { - eprint!("{}", e); - HttpResponse::InternalServerError().finish() - })?; - - Ok(HttpResponse::Ok().json(user)) -} +use actix_cors::Cors; +use actix_identity::{CookieIdentityPolicy, IdentityService}; +use actix_web::{http::header, middleware::Logger, web, App, HttpServer}; +use chrono::Duration; +use db_connection::get_pool; #[actix_rt::main] async fn main() -> std::io::Result<()> { - std::env::set_var("RUST_LOG", "actix_web=info,diesel=debug"); - dotenv::dotenv().ok(); + std::env::set_var("RUST_LOG", "actix_web=debug,diesel=debug"); env_logger::init(); - let connspec = std::env::var("DATABASE_URL").expect("DATABASE_URL"); - let manager = ConnectionManager::::new(connspec); - let pool = r2d2::Pool::builder() - .build(manager) - .expect("Failed to create database connection pool"); - - let bind = "127.0.0.1:8080"; + let bind = "localhost:8080"; println!("Starting server at: http://{}", &bind); HttpServer::new(move || { App::new() - .data(pool.clone()) - .wrap(middleware::Logger::default()) - .service(add_user) - .service(get_token) - .service(validate_token) + .wrap(Logger::default()) + .wrap( + Cors::new() + .allowed_origin(dotenv!("ALLOWED_ORIGIN")) + .allowed_methods(vec!["GET", "POST", "PUT", "DELETE"]) + .allowed_headers(vec![ + header::AUTHORIZATION, + header::CONTENT_TYPE, + header::ACCEPT, + ]) + .max_age(3600) + .finish(), + ) + .wrap(IdentityService::new( + CookieIdentityPolicy::new(dotenv!("SECRET").as_bytes()) + .domain(dotenv!("DOMAIN")) + .name("thesis") + .path("/") + .max_age(Duration::days(1).num_seconds()) + .secure(dotenv!("COOKIE_SECURE").parse().unwrap()), + )) + .data(get_pool()) + .service(web::resource("/register").route(web::post().to(handlers::register::register))) }) .bind(&bind)? .run() diff --git a/project/src/mariadb.rs b/project/src/mariadb.rs new file mode 100644 index 0000000..64a5bfb --- /dev/null +++ b/project/src/mariadb.rs @@ -0,0 +1,15 @@ +use diesel::prelude::*; +use diesel::r2d2::{self, ConnectionManager}; + +pub type DbPool = r2d2::Pool>; +pub type PooledConnection = r2d2::Pool>; + +fn init_pool(database_url: &str) -> Result { + let manager = ConnectionManager::::new(database_url); + r2d2::Pool::builder().build(manager) +} + +pub fn get_pool() -> DbPool { + let connspec = std::env::var("DATABASE_URL").expect("DATABASE_URL"); + init_pool(connspec).expect("Failed to create DB pool") +} diff --git a/project/src/models.rs b/project/src/models.rs deleted file mode 100644 index 159d83d..0000000 --- a/project/src/models.rs +++ /dev/null @@ -1,30 +0,0 @@ -use serde::{Deserialize, Serialize}; - -use crate::schema::users; - -#[derive(Debug, Clone, Serialize, Deserialize, Queryable, Insertable)] -pub struct User { - pub id: i32, - pub username: String, - pub is_admin: bool, - pub password_hash: String, -} - -#[derive(Debug, Clone, Serialize, Deserialize, Insertable)] -#[table_name = "users"] -pub struct NewUser { - pub username: String, - pub is_admin: bool, - pub password_hash: String, -} - -#[derive(Debug, Serialize, Deserialize)] -pub struct Auth { - pub username: String, - pub password: String, -} - -#[derive(Debug, Serialize, Deserialize)] -pub struct Token { - pub token: String, -} diff --git a/project/src/models/mod.rs b/project/src/models/mod.rs new file mode 100644 index 0000000..22d12a3 --- /dev/null +++ b/project/src/models/mod.rs @@ -0,0 +1 @@ +pub mod user; diff --git a/project/src/models/user.rs b/project/src/models/user.rs new file mode 100644 index 0000000..4db287d --- /dev/null +++ b/project/src/models/user.rs @@ -0,0 +1,106 @@ +use crate::errors::CustomError; +use crate::schema::users; +use bcrypt::{hash, verify, DEFAULT_COST}; +use chrono::{Local, NaiveDateTime}; +use diesel::prelude::*; +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, Serialize, Deserialize, Queryable, Insertable)] +#[table_name = "users"] +pub struct User { + #[serde(skip)] + pub id: i32, + pub username: String, + #[serde(skip)] + pub password: String, + pub admin: bool, + pub created_at: NaiveDateTime, +} + +// another user struct for new users since id is missing on +// creation (created by mariadb) +#[derive(Debug, Clone, Serialize, Deserialize, Insertable)] +#[table_name = "users"] +pub struct NewUser { + pub username: String, + pub password: String, + pub admin: bool, + pub created_at: NaiveDateTime, +} + +impl User { + pub fn hash_password(password: String) -> Result { + Ok(hash(password, DEFAULT_COST)?) + } + + pub fn create( + register_user: RegisterUser, + connection: &MysqlConnection, + ) -> Result { + use crate::schema::users::dsl::users; + + let new_user = NewUser { + username: register_user.username, + admin: register_user.admin, + password: Self::hash_password(register_user.password)?, + created_at: Local::now().naive_local(), + }; + + Ok(diesel::insert_into(users) + .values(new_user) + .execute(connection) + .is_ok()) + } +} + +#[derive(Serialize, Deserialize)] +pub struct RegisterUser { + pub username: String, + pub password: String, + pub admin: bool, + pub password_confirmation: String, +} + +impl RegisterUser { + pub fn validation(self) -> Result { + let passwords_are_equal = self.password == self.password_confirmation; + let password_not_empty = self.password.len() > 0; + + if passwords_are_equal && password_not_empty { + Ok(self) + } else if !passwords_are_equal { + Err(CustomError::PasswordMatchError( + "Password and confirmation do not match".to_string(), + )) + } else { + Err(CustomError::PasswordWrong( + "Wrong or empty password".to_string(), + )) + } + } +} + +#[derive(Deserialize)] +pub struct AuthUser { + pub username: String, + pub password: String, +} + +impl AuthUser { + pub fn login(&self, connection: &MysqlConnection) -> Result { + use crate::schema::users::dsl::*; + + let user = users + .filter(username.eq(&self.username)) + .first::(connection)?; + + let verify_password = verify(&self.password, &user.password) + .map_err(|_e| CustomError::PasswordWrong("Wrong password".to_string()))?; + + if verify_password { + Ok(user) + } else { + Err(CustomError::PasswordWrong("Wrong password".to_string())) + } + } +} diff --git a/project/src/schema.rs b/project/src/schema.rs index 63126c8..90050f3 100644 --- a/project/src/schema.rs +++ b/project/src/schema.rs @@ -2,7 +2,8 @@ table! { users (id) { id -> Integer, username -> Varchar, - is_admin -> Bool, - password_hash -> Varchar, + password -> Varchar, + admin -> Bool, + created_at -> Timestamp, } } diff --git a/project/src/utils/jwt.rs b/project/src/utils/jwt.rs new file mode 100644 index 0000000..490bed0 --- /dev/null +++ b/project/src/utils/jwt.rs @@ -0,0 +1,50 @@ +extern crate bcrypt; + +use actix_web::HttpResponse; +use chrono::{Duration, Local}; +use jwt::{decode, encode, DecodingKey, EncodingKey, Header, Validation}; + +#[derive(Debug, Serialize, Deserialize)] +struct Claims { + sub: String, + admin: bool, + exp: usize, +} + +pub struct UserWithToken { + pub username: String, + pub admin: bool, +} + +impl From for UserWithToken { + fn from(claims: Claims) -> Self { + UserWithToken { + username: claims.sub, + admin: claims.admin, + } + } +} + +impl Claims { + fn with_username(username: &str, admin: &bool) -> Self { + Claims { + sub: email.into(), + admin: admin.into(), + exp: (Local::now() + Duration::hours(24)).timestamp() as usize, + } + } +} + +pub fn new_token(username: &str) -> Result { + let secret = dotenv!("JWT_SECRET").as_bytes(); + + let claims = Claims::with_username(username, admin); + encode(&Header::default(), &claims, secret) + .map_err(|e| HttpResponse::InternalServerError().json(e.to_string())) +} + +pub fn decode_token(token: &str) -> Result { + decode::(token, get_secret(), &Validation::default()) + .map(|data| data.claims.into()) + .map_err(|e| HttpResponse::Unauthorized().json(e.to_string())) +} diff --git a/project/src/utils/mod.rs b/project/src/utils/mod.rs new file mode 100644 index 0000000..417233c --- /dev/null +++ b/project/src/utils/mod.rs @@ -0,0 +1 @@ +pub mod jwt;