aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock101
-rw-r--r--Cargo.toml2
-rw-r--r--shell.nix1
-rw-r--r--src/bin/server.rs17
-rw-r--r--src/handlers/rating.rs1
-rw-r--r--src/handlers/users.rs4
6 files changed, 92 insertions, 34 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 55fc9f4..2f6aaaa 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -11,7 +11,7 @@ dependencies = [
11 "futures-core", 11 "futures-core",
12 "futures-sink", 12 "futures-sink",
13 "log", 13 "log",
14 "pin-project", 14 "pin-project 0.4.23",
15 "tokio", 15 "tokio",
16 "tokio-util", 16 "tokio-util",
17] 17]
@@ -37,14 +37,16 @@ dependencies = [
37 37
38[[package]] 38[[package]]
39name = "actix-cors" 39name = "actix-cors"
40version = "0.4.0" 40version = "0.5.3"
41source = "registry+https://github.com/rust-lang/crates.io-index" 41source = "registry+https://github.com/rust-lang/crates.io-index"
42checksum = "d88ea83af46935098feec2e19a28c919b54eb3cbf0e239b330298e2e69d4b76b" 42checksum = "3f3a3d5493dbc9b8769fe88c030d057ef8d2edc5728e5e26267780e8fc5db0be"
43dependencies = [ 43dependencies = [
44 "actix-service",
45 "actix-web", 44 "actix-web",
46 "derive_more", 45 "derive_more",
47 "futures-util", 46 "futures-util",
47 "log",
48 "once_cell",
49 "tinyvec 1.1.0",
48] 50]
49 51
50[[package]] 52[[package]]
@@ -83,7 +85,7 @@ dependencies = [
83 "log", 85 "log",
84 "mime", 86 "mime",
85 "percent-encoding 2.1.0", 87 "percent-encoding 2.1.0",
86 "pin-project", 88 "pin-project 0.4.23",
87 "rand", 89 "rand",
88 "regex", 90 "regex",
89 "serde", 91 "serde",
@@ -173,7 +175,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
173checksum = "0052435d581b5be835d11f4eb3bce417c8af18d87ddf8ace99f8e67e595882bb" 175checksum = "0052435d581b5be835d11f4eb3bce417c8af18d87ddf8ace99f8e67e595882bb"
174dependencies = [ 176dependencies = [
175 "futures-util", 177 "futures-util",
176 "pin-project", 178 "pin-project 0.4.23",
177] 179]
178 180
179[[package]] 181[[package]]
@@ -233,7 +235,7 @@ dependencies = [
233 "futures-sink", 235 "futures-sink",
234 "futures-util", 236 "futures-util",
235 "log", 237 "log",
236 "pin-project", 238 "pin-project 0.4.23",
237 "slab", 239 "slab",
238] 240]
239 241
@@ -265,14 +267,14 @@ dependencies = [
265 "fxhash", 267 "fxhash",
266 "log", 268 "log",
267 "mime", 269 "mime",
268 "pin-project", 270 "pin-project 0.4.23",
269 "regex", 271 "regex",
270 "serde", 272 "serde",
271 "serde_json", 273 "serde_json",
272 "serde_urlencoded", 274 "serde_urlencoded",
273 "socket2", 275 "socket2",
274 "time 0.2.21", 276 "time 0.2.21",
275 "tinyvec", 277 "tinyvec 0.3.4",
276 "url 2.1.1", 278 "url 2.1.1",
277] 279]
278 280
@@ -832,9 +834,9 @@ dependencies = [
832 834
833[[package]] 835[[package]]
834name = "futures-channel" 836name = "futures-channel"
835version = "0.3.5" 837version = "0.3.8"
836source = "registry+https://github.com/rust-lang/crates.io-index" 838source = "registry+https://github.com/rust-lang/crates.io-index"
837checksum = "f366ad74c28cca6ba456d95e6422883cfb4b252a83bed929c83abfdbbf2967d5" 839checksum = "4b7109687aa4e177ef6fe84553af6280ef2778bdb7783ba44c9dc3399110fe64"
838dependencies = [ 840dependencies = [
839 "futures-core", 841 "futures-core",
840 "futures-sink", 842 "futures-sink",
@@ -842,21 +844,21 @@ dependencies = [
842 844
843[[package]] 845[[package]]
844name = "futures-core" 846name = "futures-core"
845version = "0.3.5" 847version = "0.3.8"
846source = "registry+https://github.com/rust-lang/crates.io-index" 848source = "registry+https://github.com/rust-lang/crates.io-index"
847checksum = "59f5fff90fd5d971f936ad674802482ba441b6f09ba5e15fd8b39145582ca399" 849checksum = "847ce131b72ffb13b6109a221da9ad97a64cbe48feb1028356b836b47b8f1748"
848 850
849[[package]] 851[[package]]
850name = "futures-io" 852name = "futures-io"
851version = "0.3.5" 853version = "0.3.8"
852source = "registry+https://github.com/rust-lang/crates.io-index" 854source = "registry+https://github.com/rust-lang/crates.io-index"
853checksum = "de27142b013a8e869c14957e6d2edeef89e97c289e69d042ee3a49acd8b51789" 855checksum = "611834ce18aaa1bd13c4b374f5d653e1027cf99b6b502584ff8c9a64413b30bb"
854 856
855[[package]] 857[[package]]
856name = "futures-macro" 858name = "futures-macro"
857version = "0.3.5" 859version = "0.3.8"
858source = "registry+https://github.com/rust-lang/crates.io-index" 860source = "registry+https://github.com/rust-lang/crates.io-index"
859checksum = "d0b5a30a4328ab5473878237c447333c093297bded83a4983d10f4deea240d39" 861checksum = "77408a692f1f97bcc61dc001d752e00643408fbc922e4d634c655df50d595556"
860dependencies = [ 862dependencies = [
861 "proc-macro-hack", 863 "proc-macro-hack",
862 "proc-macro2", 864 "proc-macro2",
@@ -866,24 +868,24 @@ dependencies = [
866 868
867[[package]] 869[[package]]
868name = "futures-sink" 870name = "futures-sink"
869version = "0.3.5" 871version = "0.3.8"
870source = "registry+https://github.com/rust-lang/crates.io-index" 872source = "registry+https://github.com/rust-lang/crates.io-index"
871checksum = "3f2032893cb734c7a05d85ce0cc8b8c4075278e93b24b66f9de99d6eb0fa8acc" 873checksum = "f878195a49cee50e006b02b93cf7e0a95a38ac7b776b4c4d9cc1207cd20fcb3d"
872 874
873[[package]] 875[[package]]
874name = "futures-task" 876name = "futures-task"
875version = "0.3.5" 877version = "0.3.8"
876source = "registry+https://github.com/rust-lang/crates.io-index" 878source = "registry+https://github.com/rust-lang/crates.io-index"
877checksum = "bdb66b5f09e22019b1ab0830f7785bcea8e7a42148683f99214f73f8ec21a626" 879checksum = "7c554eb5bf48b2426c4771ab68c6b14468b6e76cc90996f528c3338d761a4d0d"
878dependencies = [ 880dependencies = [
879 "once_cell", 881 "once_cell",
880] 882]
881 883
882[[package]] 884[[package]]
883name = "futures-util" 885name = "futures-util"
884version = "0.3.5" 886version = "0.3.8"
885source = "registry+https://github.com/rust-lang/crates.io-index" 887source = "registry+https://github.com/rust-lang/crates.io-index"
886checksum = "8764574ff08b701a084482c3c7031349104b07ac897393010494beaa18ce32c6" 888checksum = "d304cff4a7b99cfb7986f7d43fbe93d175e72e704a8860787cc95e9ffd85cbd2"
887dependencies = [ 889dependencies = [
888 "futures-channel", 890 "futures-channel",
889 "futures-core", 891 "futures-core",
@@ -892,7 +894,7 @@ dependencies = [
892 "futures-sink", 894 "futures-sink",
893 "futures-task", 895 "futures-task",
894 "memchr", 896 "memchr",
895 "pin-project", 897 "pin-project 1.0.2",
896 "pin-utils", 898 "pin-utils",
897 "proc-macro-hack", 899 "proc-macro-hack",
898 "proc-macro-nested", 900 "proc-macro-nested",
@@ -1378,7 +1380,16 @@ version = "0.4.23"
1378source = "registry+https://github.com/rust-lang/crates.io-index" 1380source = "registry+https://github.com/rust-lang/crates.io-index"
1379checksum = "ca4433fff2ae79342e497d9f8ee990d174071408f28f726d6d83af93e58e48aa" 1381checksum = "ca4433fff2ae79342e497d9f8ee990d174071408f28f726d6d83af93e58e48aa"
1380dependencies = [ 1382dependencies = [
1381 "pin-project-internal", 1383 "pin-project-internal 0.4.23",
1384]
1385
1386[[package]]
1387name = "pin-project"
1388version = "1.0.2"
1389source = "registry+https://github.com/rust-lang/crates.io-index"
1390checksum = "9ccc2237c2c489783abd8c4c80e5450fc0e98644555b1364da68cc29aa151ca7"
1391dependencies = [
1392 "pin-project-internal 1.0.2",
1382] 1393]
1383 1394
1384[[package]] 1395[[package]]
@@ -1393,6 +1404,17 @@ dependencies = [
1393] 1404]
1394 1405
1395[[package]] 1406[[package]]
1407name = "pin-project-internal"
1408version = "1.0.2"
1409source = "registry+https://github.com/rust-lang/crates.io-index"
1410checksum = "f8e8d2bf0b23038a4424865103a4df472855692821aab4e4f5c3312d461d9e5f"
1411dependencies = [
1412 "proc-macro2",
1413 "quote",
1414 "syn",
1415]
1416
1417[[package]]
1396name = "pin-project-lite" 1418name = "pin-project-lite"
1397version = "0.1.7" 1419version = "0.1.7"
1398source = "registry+https://github.com/rust-lang/crates.io-index" 1420source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1438,9 +1460,9 @@ dependencies = [
1438 1460
1439[[package]] 1461[[package]]
1440name = "proc-macro-hack" 1462name = "proc-macro-hack"
1441version = "0.5.18" 1463version = "0.5.19"
1442source = "registry+https://github.com/rust-lang/crates.io-index" 1464source = "registry+https://github.com/rust-lang/crates.io-index"
1443checksum = "99c605b9a0adc77b7211c6b1f722dcb613d68d66859a44f3d485a6da332b0598" 1465checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5"
1444 1466
1445[[package]] 1467[[package]]
1446name = "proc-macro-nested" 1468name = "proc-macro-nested"
@@ -1450,9 +1472,9 @@ checksum = "eba180dafb9038b050a4c280019bbedf9f2467b61e5d892dcad585bb57aadc5a"
1450 1472
1451[[package]] 1473[[package]]
1452name = "proc-macro2" 1474name = "proc-macro2"
1453version = "1.0.21" 1475version = "1.0.24"
1454source = "registry+https://github.com/rust-lang/crates.io-index" 1476source = "registry+https://github.com/rust-lang/crates.io-index"
1455checksum = "36e28516df94f3dd551a587da5357459d9b36d945a7c37c3557928c1c2ff2a2c" 1477checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71"
1456dependencies = [ 1478dependencies = [
1457 "unicode-xid", 1479 "unicode-xid",
1458] 1480]
@@ -1784,9 +1806,9 @@ checksum = "343f3f510c2915908f155e94f17220b19ccfacf2a64a2a5d8004f2c3e311e7fd"
1784 1806
1785[[package]] 1807[[package]]
1786name = "syn" 1808name = "syn"
1787version = "1.0.41" 1809version = "1.0.54"
1788source = "registry+https://github.com/rust-lang/crates.io-index" 1810source = "registry+https://github.com/rust-lang/crates.io-index"
1789checksum = "6690e3e9f692504b941dc6c3b188fd28df054f7fb8469ab40680df52fdcc842b" 1811checksum = "9a2af957a63d6bd42255c359c93d9bfdb97076bd3b820897ce55ffbfbf107f44"
1790dependencies = [ 1812dependencies = [
1791 "proc-macro2", 1813 "proc-macro2",
1792 "quote", 1814 "quote",
@@ -1896,6 +1918,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1896checksum = "238ce071d267c5710f9d31451efec16c5ee22de34df17cc05e56cbc92e967117" 1918checksum = "238ce071d267c5710f9d31451efec16c5ee22de34df17cc05e56cbc92e967117"
1897 1919
1898[[package]] 1920[[package]]
1921name = "tinyvec"
1922version = "1.1.0"
1923source = "registry+https://github.com/rust-lang/crates.io-index"
1924checksum = "ccf8dbc19eb42fba10e8feaaec282fb50e2c14b2726d6301dbfeed0f73306a6f"
1925dependencies = [
1926 "tinyvec_macros",
1927]
1928
1929[[package]]
1930name = "tinyvec_macros"
1931version = "0.1.0"
1932source = "registry+https://github.com/rust-lang/crates.io-index"
1933checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
1934
1935[[package]]
1899name = "tokio" 1936name = "tokio"
1900version = "0.2.22" 1937version = "0.2.22"
1901source = "registry+https://github.com/rust-lang/crates.io-index" 1938source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2010,7 +2047,7 @@ version = "0.1.13"
2010source = "registry+https://github.com/rust-lang/crates.io-index" 2047source = "registry+https://github.com/rust-lang/crates.io-index"
2011checksum = "6fb19cf769fa8c6a80a162df694621ebeb4dafb606470b2b2fce0be40a98a977" 2048checksum = "6fb19cf769fa8c6a80a162df694621ebeb4dafb606470b2b2fce0be40a98a977"
2012dependencies = [ 2049dependencies = [
2013 "tinyvec", 2050 "tinyvec 0.3.4",
2014] 2051]
2015 2052
2016[[package]] 2053[[package]]
diff --git a/Cargo.toml b/Cargo.toml
index 2c962b7..8ce728b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -15,7 +15,7 @@ serde_json = "1.0"
15log = "0.4" 15log = "0.4"
16pretty_env_logger = "0.4" 16pretty_env_logger = "0.4"
17actix-identity = "0.3.1" 17actix-identity = "0.3.1"
18actix-cors = "0.4.0" 18actix-cors = "0.5"
19bigdecimal = "0.0.14" 19bigdecimal = "0.0.14"
20rand = "0.7" 20rand = "0.7"
21 21
diff --git a/shell.nix b/shell.nix
index 9805d80..9167821 100644
--- a/shell.nix
+++ b/shell.nix
@@ -29,5 +29,6 @@ in
29 libmysqlclient 29 libmysqlclient
30 jq 30 jq
31 python3 31 python3
32 insomnia
32 ]; 33 ];
33 } 34 }
diff --git a/src/bin/server.rs b/src/bin/server.rs
index 5af3135..7c67e4f 100644
--- a/src/bin/server.rs
+++ b/src/bin/server.rs
@@ -24,9 +24,24 @@ async fn main() -> std::io::Result<()> {
24 .wrap(IdentityService::new( 24 .wrap(IdentityService::new(
25 CookieIdentityPolicy::new(&private_key) 25 CookieIdentityPolicy::new(&private_key)
26 .name("user-login") 26 .name("user-login")
27 .domain("127.0.0.1")
28 .path("/")
29 .same_site(actix_web::cookie::SameSite::None)
30 .http_only(true)
27 .secure(false), 31 .secure(false),
28 )) 32 ))
29 .wrap(Cors::new().supports_credentials().finish()) 33 .wrap(
34 Cors::default()
35 .allowed_origin("http://127.0.0.1:8000")
36 .allowed_origin("http://localhost:8000")
37 .allow_any_method()
38 .allow_any_header(),
39 )
40 .wrap(
41 middleware::DefaultHeaders::new()
42 .header("Access-Control-Allow-Credentials", "true")
43 .header("Access-Control-Expose-Headers", "set-cookie"),
44 )
30 .wrap(middleware::Logger::default()) 45 .wrap(middleware::Logger::default())
31 .data(pool.clone()) 46 .data(pool.clone())
32 .service( 47 .service(
diff --git a/src/handlers/rating.rs b/src/handlers/rating.rs
index 309c2c6..dfbeb3e 100644
--- a/src/handlers/rating.rs
+++ b/src/handlers/rating.rs
@@ -22,6 +22,7 @@ pub async fn add_rating(
22 pool: web::Data<TPool>, 22 pool: web::Data<TPool>,
23) -> impl Responder { 23) -> impl Responder {
24 info!("Add rating hit: {:?}", rating_details.product_id); 24 info!("Add rating hit: {:?}", rating_details.product_id);
25 info!("{:?}", cookie.identity());
25 let conn = pool.get().unwrap(); 26 let conn = pool.get().unwrap();
26 if let Some(uname) = cookie.identity() { 27 if let Some(uname) = cookie.identity() {
27 let selected_user = customer 28 let selected_user = customer
diff --git a/src/handlers/users.rs b/src/handlers/users.rs
index bff532c..73fca84 100644
--- a/src/handlers/users.rs
+++ b/src/handlers/users.rs
@@ -57,6 +57,10 @@ pub async fn login(
57 login_details: web::Json<Login>, 57 login_details: web::Json<Login>,
58) -> impl Responder { 58) -> impl Responder {
59 info!("Login hit"); 59 info!("Login hit");
60 if let Some(uname) = cookie.identity() {
61 info!("Found existing cookie: {:?}", cookie.identity());
62 return HttpResponse::Ok().finish();
63 }
60 let conn = pool.get().unwrap(); 64 let conn = pool.get().unwrap();
61 let entered_pass = &login_details.password; 65 let entered_pass = &login_details.password;
62 let selected_user = customer 66 let selected_user = customer