From 44ff69586c14001c4801f7199ecbdbee20f125f0 Mon Sep 17 00:00:00 2001 From: stevepodell Date: Fri, 27 Dec 2024 16:37:35 -0800 Subject: [PATCH] Login.js enhanced with signout and link to protected FAQ page FAQ is protected just as an example -- it can be unprotected with no downside. --- package-lock.json | 526 +----------------- package.json | 2 +- src/App.jsx | 18 +- .../icons/we-vote-icon-square-color-dark.svg | 3 + src/js/auth.js | 37 ++ src/js/common/utils/initializejQuery.js | 6 + src/js/pages/Login.jsx | 243 ++++---- src/js/pages/Teams.jsx | 8 +- 8 files changed, 194 insertions(+), 649 deletions(-) create mode 100755 src/img/global/icons/we-vote-icon-square-color-dark.svg create mode 100644 src/js/auth.js diff --git a/package-lock.json b/package-lock.json index 46f05df..62a5980 100644 --- a/package-lock.json +++ b/package-lock.json @@ -54,7 +54,7 @@ "react-player": "^2.16.0", "react-rewards": "^2.0.4", "react-router-dom": "^5.3.4", - "react-router-dom-v5-compat": "^6.23.1", + "react-router-dom-v5-compat": "^6.28.1", "react-share": "^4.4.1", "react-slick": "^0.30.2", "react-svg": "^14.1.9", @@ -2246,57 +2246,6 @@ "integrity": "sha512-snKqtPW01tN0ui7yu9rGv69aJXr/a/Ywvl11sUjNtEcRc+ng/mQriFL0wLXMef74iHa/EkftbDzU9F8iFbH+zg==", "license": "MIT" }, - "node_modules/@esbuild/android-arm": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.18.20.tgz", - "integrity": "sha512-fyi7TDI/ijKKNZTUJAQqiG5T7YjJXgnzkURqmGj13C6dCqckZBLdl4h7bkhHt/t0WP+zO9/zwroDvANaOqO5Sw==", - "cpu": [ - "arm" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/android-arm64": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.18.20.tgz", - "integrity": "sha512-Nz4rJcchGDtENV0eMKUNa6L12zz2zBDXuhj/Vjh18zGqB44Bi7MBMSXjgunJgjRhCmKOjnPuZp4Mb6OKqtMHLQ==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/android-x64": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.18.20.tgz", - "integrity": "sha512-8GDdlePJA8D6zlZYJV/jnrRAi6rOiNaCC/JclcXpB+KIuvfBN4owLtgzY2bsxnx666XjJx2kDPUmnTtR8qKQUg==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=12" - } - }, "node_modules/@esbuild/darwin-arm64": { "version": "0.18.20", "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.18.20.tgz", @@ -2314,312 +2263,6 @@ "node": ">=12" } }, - "node_modules/@esbuild/darwin-x64": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.18.20.tgz", - "integrity": "sha512-pc5gxlMDxzm513qPGbCbDukOdsGtKhfxD1zJKXjCCcU7ju50O7MeAZ8c4krSJcOIJGFR+qx21yMMVYwiQvyTyQ==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/freebsd-arm64": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.18.20.tgz", - "integrity": "sha512-yqDQHy4QHevpMAaxhhIwYPMv1NECwOvIpGCZkECn8w2WFHXjEwrBn3CeNIYsibZ/iZEUemj++M26W3cNR5h+Tw==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "freebsd" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/freebsd-x64": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.18.20.tgz", - "integrity": "sha512-tgWRPPuQsd3RmBZwarGVHZQvtzfEBOreNuxEMKFcd5DaDn2PbBxfwLcj4+aenoh7ctXcbXmOQIn8HI6mCSw5MQ==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "freebsd" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-arm": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.18.20.tgz", - "integrity": "sha512-/5bHkMWnq1EgKr1V+Ybz3s1hWXok7mDFUMQ4cG10AfW3wL02PSZi5kFpYKrptDsgb2WAJIvRcDm+qIvXf/apvg==", - "cpu": [ - "arm" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-arm64": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.18.20.tgz", - "integrity": "sha512-2YbscF+UL7SQAVIpnWvYwM+3LskyDmPhe31pE7/aoTMFKKzIc9lLbyGUpmmb8a8AixOL61sQ/mFh3jEjHYFvdA==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-ia32": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.18.20.tgz", - "integrity": "sha512-P4etWwq6IsReT0E1KHU40bOnzMHoH73aXp96Fs8TIT6z9Hu8G6+0SHSw9i2isWrD2nbx2qo5yUqACgdfVGx7TA==", - "cpu": [ - "ia32" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-loong64": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.18.20.tgz", - "integrity": "sha512-nXW8nqBTrOpDLPgPY9uV+/1DjxoQ7DoB2N8eocyq8I9XuqJ7BiAMDMf9n1xZM9TgW0J8zrquIb/A7s3BJv7rjg==", - "cpu": [ - "loong64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-mips64el": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.18.20.tgz", - "integrity": "sha512-d5NeaXZcHp8PzYy5VnXV3VSd2D328Zb+9dEq5HE6bw6+N86JVPExrA6O68OPwobntbNJ0pzCpUFZTo3w0GyetQ==", - "cpu": [ - "mips64el" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-ppc64": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.18.20.tgz", - "integrity": "sha512-WHPyeScRNcmANnLQkq6AfyXRFr5D6N2sKgkFo2FqguP44Nw2eyDlbTdZwd9GYk98DZG9QItIiTlFLHJHjxP3FA==", - "cpu": [ - "ppc64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-riscv64": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.18.20.tgz", - "integrity": "sha512-WSxo6h5ecI5XH34KC7w5veNnKkju3zBRLEQNY7mv5mtBmrP/MjNBCAlsM2u5hDBlS3NGcTQpoBvRzqBcRtpq1A==", - "cpu": [ - "riscv64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-s390x": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.18.20.tgz", - "integrity": "sha512-+8231GMs3mAEth6Ja1iK0a1sQ3ohfcpzpRLH8uuc5/KVDFneH6jtAJLFGafpzpMRO6DzJ6AvXKze9LfFMrIHVQ==", - "cpu": [ - "s390x" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-x64": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.18.20.tgz", - "integrity": "sha512-UYqiqemphJcNsFEskc73jQ7B9jgwjWrSayxawS6UVFZGWrAAtkzjxSqnoclCXxWtfwLdzU+vTpcNYhpn43uP1w==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/netbsd-x64": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.18.20.tgz", - "integrity": "sha512-iO1c++VP6xUBUmltHZoMtCUdPlnPGdBom6IrO4gyKPFFVBKioIImVooR5I83nTew5UOYrk3gIJhbZh8X44y06A==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "netbsd" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/openbsd-x64": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.18.20.tgz", - "integrity": "sha512-e5e4YSsuQfX4cxcygw/UCPIEP6wbIL+se3sxPdCiMbFLBWu0eiZOJ7WoD+ptCLrmjZBK1Wk7I6D/I3NglUGOxg==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "openbsd" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/sunos-x64": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.18.20.tgz", - "integrity": "sha512-kDbFRFp0YpTQVVrqUd5FTYmWo45zGaXe0X8E1G/LKFC0v8x0vWrhOWSLITcCn63lmZIxfOMXtCfti/RxN/0wnQ==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "sunos" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/win32-arm64": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.18.20.tgz", - "integrity": "sha512-ddYFR6ItYgoaq4v4JmQQaAI5s7npztfV4Ag6NrhiaW0RrnOXqBkgwZLofVTlq1daVTQNhtI5oieTvkRPfZrePg==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/win32-ia32": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.18.20.tgz", - "integrity": "sha512-Wv7QBi3ID/rROT08SABTS7eV4hX26sVduqDOTe1MvGMjNd3EjOz4b7zeexIR62GTIEKrfJXKL9LFxTYgkyeu7g==", - "cpu": [ - "ia32" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/win32-x64": { - "version": "0.18.20", - "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.18.20.tgz", - "integrity": "sha512-kTdfRcSiDfQca/y9QIkng02avJ+NCaQvrMejlsB3RRv5sE9rRoeBPISaZpKxHELzRxZyLvNts1P27W3wV+8geQ==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=12" - } - }, "node_modules/@eslint-community/eslint-utils": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.1.tgz", @@ -9292,159 +8935,6 @@ "node": ">=10" } }, - "node_modules/@swc/core-darwin-x64": { - "version": "1.10.1", - "resolved": "https://registry.npmjs.org/@swc/core-darwin-x64/-/core-darwin-x64-1.10.1.tgz", - "integrity": "sha512-L4BNt1fdQ5ZZhAk5qoDfUnXRabDOXKnXBxMDJ+PWLSxOGBbWE6aJTnu4zbGjJvtot0KM46m2LPAPY8ttknqaZA==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "Apache-2.0 AND MIT", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-linux-arm-gnueabihf": { - "version": "1.10.1", - "resolved": "https://registry.npmjs.org/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.10.1.tgz", - "integrity": "sha512-Y1u9OqCHgvVp2tYQAJ7hcU9qO5brDMIrA5R31rwWQIAKDkJKtv3IlTHF0hrbWk1wPR0ZdngkQSJZple7G+Grvw==", - "cpu": [ - "arm" - ], - "dev": true, - "license": "Apache-2.0", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-linux-arm64-gnu": { - "version": "1.10.1", - "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.10.1.tgz", - "integrity": "sha512-tNQHO/UKdtnqjc7o04iRXng1wTUXPgVd8Y6LI4qIbHVoVPwksZydISjMcilKNLKIwOoUQAkxyJ16SlOAeADzhQ==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "Apache-2.0 AND MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-linux-arm64-musl": { - "version": "1.10.1", - "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.10.1.tgz", - "integrity": "sha512-x0L2Pd9weQ6n8dI1z1Isq00VHFvpBClwQJvrt3NHzmR+1wCT/gcYl1tp9P5xHh3ldM8Cn4UjWCw+7PaUgg8FcQ==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "Apache-2.0 AND MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-linux-x64-gnu": { - "version": "1.10.1", - "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.10.1.tgz", - "integrity": "sha512-yyYEwQcObV3AUsC79rSzN9z6kiWxKAVJ6Ntwq2N9YoZqSPYph+4/Am5fM1xEQYf/kb99csj0FgOelomJSobxQA==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "Apache-2.0 AND MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-linux-x64-musl": { - "version": "1.10.1", - "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.10.1.tgz", - "integrity": "sha512-tcaS43Ydd7Fk7sW5ROpaf2Kq1zR+sI5K0RM+0qYLYYurvsJruj3GhBCaiN3gkzd8m/8wkqNqtVklWaQYSDsyqA==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "Apache-2.0 AND MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-win32-arm64-msvc": { - "version": "1.10.1", - "resolved": "https://registry.npmjs.org/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.10.1.tgz", - "integrity": "sha512-D3Qo1voA7AkbOzQ2UGuKNHfYGKL6eejN8VWOoQYtGHHQi1p5KK/Q7V1ku55oxXBsj79Ny5FRMqiRJpVGad7bjQ==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "Apache-2.0 AND MIT", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-win32-ia32-msvc": { - "version": "1.10.1", - "resolved": "https://registry.npmjs.org/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.10.1.tgz", - "integrity": "sha512-WalYdFoU3454Og+sDKHM1MrjvxUGwA2oralknXkXL8S0I/8RkWZOB++p3pLaGbTvOO++T+6znFbQdR8KRaa7DA==", - "cpu": [ - "ia32" - ], - "dev": true, - "license": "Apache-2.0 AND MIT", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-win32-x64-msvc": { - "version": "1.10.1", - "resolved": "https://registry.npmjs.org/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.10.1.tgz", - "integrity": "sha512-JWobfQDbTnoqaIwPKQ3DVSywihVXlQMbDuwik/dDWlj33A8oEHcjPOGs4OqcA3RHv24i+lfCQpM3Mn4FAMfacA==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "Apache-2.0 AND MIT", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=10" - } - }, "node_modules/@swc/counter": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/@swc/counter/-/counter-0.1.3.tgz", @@ -25207,14 +24697,14 @@ } }, "node_modules/react-router-dom-v5-compat": { - "version": "6.28.0", - "resolved": "https://registry.npmjs.org/react-router-dom-v5-compat/-/react-router-dom-v5-compat-6.28.0.tgz", - "integrity": "sha512-KrTxsn2vibvoTeGstcBMEuchuT+BxXGftfa7njf1vNSlzO8t+4Y5oN2h3WeAq2rK7MyA5mFUXrE/+lMOR0ay9Q==", + "version": "6.28.1", + "resolved": "https://registry.npmjs.org/react-router-dom-v5-compat/-/react-router-dom-v5-compat-6.28.1.tgz", + "integrity": "sha512-yJLpBnJd69x6RoUNCGNAScTWyc3/N8ztwXYM6si8EfleWHs3JYI800/HrwtpBgifOy6oHYtJQ2cpFlPbFosR+Q==", "license": "MIT", "dependencies": { "@remix-run/router": "1.21.0", "history": "^5.3.0", - "react-router": "6.28.0" + "react-router": "6.28.1" }, "engines": { "node": ">=14.0.0" @@ -25235,9 +24725,9 @@ } }, "node_modules/react-router-dom-v5-compat/node_modules/react-router": { - "version": "6.28.0", - "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.28.0.tgz", - "integrity": "sha512-HrYdIFqdrnhDw0PqG/AKjAqEqM7AvxCz0DQ4h2W8k6nqmc5uRBYDag0SBxx9iYz5G8gnuNVLzUe13wl9eAsXXg==", + "version": "6.28.1", + "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.28.1.tgz", + "integrity": "sha512-2omQTA3rkMljmrvvo6WtewGdVh45SpL9hGiCI9uUrwGGfNFDIvGK4gYJsKlJoNVi6AQZcopSCballL+QGOm7fA==", "license": "MIT", "dependencies": { "@remix-run/router": "1.21.0" diff --git a/package.json b/package.json index 20bf995..abdf2ab 100644 --- a/package.json +++ b/package.json @@ -153,7 +153,7 @@ "react-player": "^2.16.0", "react-rewards": "^2.0.4", "react-router-dom": "^5.3.4", - "react-router-dom-v5-compat": "^6.23.1", + "react-router-dom-v5-compat": "^6.28.1", "react-share": "^4.4.1", "react-slick": "^0.30.2", "react-svg": "^14.1.9", diff --git a/src/App.jsx b/src/App.jsx index 2322788..15e22a9 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -20,6 +20,8 @@ import HeaderBarSuspense from './js/components/Navigation/HeaderBarSuspense'; import webAppConfig from './js/config'; import VoterStore from './js/stores/VoterStore'; import Login from './js/pages/Login'; +import { PrivateRoute } from './js/auth'; + // importRemoveCordovaListenersToken1 -- Do not remove this line! // Root URL pages @@ -44,6 +46,7 @@ class App extends Component { hideFooter: false, showReadyLight: true, enableFullStory: false, + isJqueryInitialized: false, }; this.setShowHeader = this.setShowHeader.bind(this); this.setShowFooter = this.setShowFooter.bind(this); @@ -51,6 +54,8 @@ class App extends Component { this.setShowReadyHeavy = this.setShowReadyHeavy.bind(this); this.bypass2FA = this.bypass2FA.bind(this); this.localIsCordova(); + console.log('--------- initializejQuery() -----------------------------'); + initializejQuery(() => {}); } // See https://reactjs.org/docs/error-boundaries.html @@ -64,14 +69,6 @@ class App extends Component { this.appStateSubscription = messageService.getMessage().subscribe(() => this.onAppObservableStoreChange()); this.voterStoreListener = VoterStore.addListener(this.onVoterStoreChange.bind(this)); - // let { hostname } = window.location; - // hostname = hostname || ''; - initializejQuery(() => { - // AppObservableStore.siteConfigurationRetrieve(hostname); - }); - // console.log('href in App.js componentDidMount: ', window.location.href); - // console.log('normalizedHrefPage in App.js componentDidMount: ', normalizedHref()); - if (isCordova()) { const size = isIOS() ? getIOSSizeString() : getAndroidSize(); console.log('Cordova: device model', window.device.model, ' size: ', size); @@ -259,6 +256,9 @@ class App extends Component { window.location.href = destinationHref; } + + console.log('======================================== ', localStorage.getItem('isAuthenticated'), ' ============================='); + return ( <> @@ -274,7 +274,7 @@ class App extends Component { }> - + diff --git a/src/img/global/icons/we-vote-icon-square-color-dark.svg b/src/img/global/icons/we-vote-icon-square-color-dark.svg new file mode 100755 index 0000000..5fec769 --- /dev/null +++ b/src/img/global/icons/we-vote-icon-square-color-dark.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/js/auth.js b/src/js/auth.js new file mode 100644 index 0000000..9674a02 --- /dev/null +++ b/src/js/auth.js @@ -0,0 +1,37 @@ +import React from 'react'; +import { Redirect, Route } from 'react-router-dom'; +import webAppConfig from './config'; + +/* global $ */ + +// eslint-disable-next-line import/prefer-default-export +export async function getAuthentication () { + if (window.$) { + console.log(`${webAppConfig.STAFF_API_SERVER_API_ROOT_URL}getAuth`); + $.get(`${webAppConfig.STAFF_API_SERVER_API_ROOT_URL}auth/`, + {}, + (data, status) => { + console.log(`/auth response -- status: '${status}', data: ${JSON.stringify(data)}`); + localStorage.setItem('isAuthenticated', data.userId); + return data.authenticated; + }); + } else { + console.log('jquery not yet defined in getAuthentication'); + } +} + +/* eslint-disable react/jsx-props-no-spreading */ +// eslint-disable-next-line react/prop-types +export const PrivateRoute = ({ component: Component, isAuthenticated, ...rest }) => ( + (isAuthenticated ? ( + + ) : ( + // eslint-disable-next-line react/prop-types + + ))} + /> +); + + diff --git a/src/js/common/utils/initializejQuery.js b/src/js/common/utils/initializejQuery.js index ca68493..c678e92 100644 --- a/src/js/common/utils/initializejQuery.js +++ b/src/js/common/utils/initializejQuery.js @@ -14,6 +14,12 @@ const initializejQuery = (afterFunction) => { window.jQuery = jquery; window.$ = jquery; // console.log('jquery loaded'); + window.$.ajaxSetup({ + crossDomain: true, + xhrFields: { + withCredentials: true, + }, + }); if (afterFunction) { afterFunction(); } diff --git a/src/js/pages/Login.jsx b/src/js/pages/Login.jsx index 065edd7..526c7b5 100644 --- a/src/js/pages/Login.jsx +++ b/src/js/pages/Login.jsx @@ -8,6 +8,7 @@ import styled from 'styled-components'; import { PageContentContainer } from '../components/Style/pageLayoutStyles'; import webAppConfig from '../config'; import { renderLog } from '../common/utils/logging'; +import historyPush from '../common/utils/historyPush'; /* global $ */ @@ -23,7 +24,9 @@ const Login = ({ classes }) => { const confirmPasswordFldRef = useRef(''); const [showCreateStuff, setShowCreateStuff] = React.useState(false); const [warningLine, setWarningLine] = React.useState(''); - const [successLine, setSuccessLine] = React.useState(''); + const isAuthenticated = localStorage.getItem('isAuthenticated'); + const initialSuccess = isAuthenticated ? `Signed in as ${isAuthenticated}` : 'Please sign in'; + const [successLine, setSuccessLine] = React.useState(initialSuccess); renderLog('Login'); // Set LOG_RENDER_EVENTS to log all renders @@ -38,12 +41,6 @@ const Login = ({ classes }) => { } console.log(`${webAppConfig.STAFF_API_SERVER_API_ROOT_URL}login`); - $.ajaxSetup({ - crossDomain: true, - xhrFields: { - withCredentials: true, - }, - }); $.post(`${webAppConfig.STAFF_API_SERVER_API_ROOT_URL}login/`, { email, password }, (data, status) => { @@ -51,6 +48,7 @@ const Login = ({ classes }) => { if (data.userId > 0) { setWarningLine(''); setSuccessLine(`Cheers person #${data.userId}! You are signed in!`); + localStorage.setItem('isAuthenticated', data.userId); } else { setWarningLine(data.errors.msg); setSuccessLine(''); @@ -58,16 +56,27 @@ const Login = ({ classes }) => { }); }; + const logoutApi = () => { + console.log(`${webAppConfig.STAFF_API_SERVER_API_ROOT_URL}logout`); + $.post(`${webAppConfig.STAFF_API_SERVER_API_ROOT_URL}logout/`, + {}, + (data, status) => { + console.log(`/logout response -- status: '${status}', data: ${JSON.stringify(data)}`); + if (data.authenticated) { + setWarningLine(data.errors.msg); + setSuccessLine(''); + } else { + setWarningLine(''); + setSuccessLine('You are signed out'); + localStorage.removeItem('isAuthenticated'); + } + }); + }; + const signupApi = (firstName, lastName, location, emailPersonal, emailOfficial, password, confirmPassword) => { const postURL = `${webAppConfig.STAFF_API_SERVER_API_ROOT_URL}signup`; console.log('postURL: ', postURL); try { - $.ajaxSetup({ - crossDomain: true, - xhrFields: { - withCredentials: true, - }, - }); $.post(postURL, { firstName, @@ -87,6 +96,7 @@ const Login = ({ classes }) => { setWarningLine(errStr); if (data.personCreated) { setSuccessLine(`user # ${data.userId} created, and signedIn is ${data.signedIn}`); + localStorage.setItem('isAuthenticated', data.userId); } }); } catch (e) { @@ -94,29 +104,6 @@ const Login = ({ classes }) => { } }; - const testAuthApi = () => { - $.ajaxSetup({ - crossDomain: true, - xhrFields: { - withCredentials: true, - }, - }); - $.post(`${webAppConfig.STAFF_API_SERVER_API_ROOT_URL}auth-test`, - {}, - (data, status) => { - console.log(`/test-auth response -- status: '${status}', data: ${JSON.stringify(data)}`); - let errStr = ''; - for (let i = 0; i < data.errors.length; i++) { - errStr += data.errors[i].msg; - } - setWarningLine(errStr); - if (data.personCreated) { - setSuccessLine(`user # ${data.userId} auth checked, and signedIn is ${data.signedIn}`); - } - }); - }; - - const loginPressed = () => { const email = emailPersonalFldRef.current.value; const password = passwordFldRef.current.value; @@ -130,6 +117,10 @@ const Login = ({ classes }) => { } }; + const signOutPressed = () => { + logoutApi(); + }; + const createPressed = () => { if (!showCreateStuff) { setShowCreateStuff(true); @@ -160,10 +151,6 @@ const Login = ({ classes }) => { } }; - const testPressed = () => { - testAuthApi(); - }; - return (
@@ -175,100 +162,118 @@ const Login = ({ classes }) => { -

- Sign in -

- -
{warningLine}
-
{successLine}
- +
+

+ + we vote logo + + + Sign in + +

+
+
+
{warningLine}
+
{successLine}
+ + + + - - - - - - - - + + + + + + + Forgot your password? + +
+
+ +
+ - Forgot your password? - -
- - - -
- This page's purpose is to test and exercise the API. Feel free to replace me.
diff --git a/src/js/pages/Teams.jsx b/src/js/pages/Teams.jsx index 3bab623..f9ef5bd 100644 --- a/src/js/pages/Teams.jsx +++ b/src/js/pages/Teams.jsx @@ -119,10 +119,14 @@ const Teams = ({ classes, match }) => { // classes, teamId ))}
- + Sign in - +
+
+ + Example protected page +