From ab653ad43964687bc3439c841069dfa91de83bc1 Mon Sep 17 00:00:00 2001 From: Logan Hunt Date: Thu, 19 Jan 2023 12:13:25 -0700 Subject: [PATCH] Add password form, some minor frontend changes as well --- front/src/index.js | 9 +- front/src/root.jsx | 7 +- front/src/routes/auth_successful.jsx | 12 ++- front/src/routes/home.jsx | 39 ++++---- front/src/routes/keys.jsx | 38 ++++--- front/src/routes/password.jsx | 144 +++++++++++++++++++++++++++ lib/chessh/release.ex | 1 - lib/chessh/web/web.ex | 58 ++++------- 8 files changed, 220 insertions(+), 88 deletions(-) create mode 100644 front/src/routes/password.jsx diff --git a/front/src/index.js b/front/src/index.js index b5d7dc9..e827e0a 100644 --- a/front/src/index.js +++ b/front/src/index.js @@ -7,6 +7,7 @@ import { Root } from "./root"; import { Demo } from "./routes/demo"; import { Home } from "./routes/home"; import { Keys } from "./routes/keys"; +import { Password } from "./routes/password"; import { AuthSuccessful } from "./routes/auth_successful"; import "./index.css"; @@ -23,17 +24,13 @@ const router = createBrowserRouter([ element: , }, { - path: "user", - element: , + path: "password", + element: , }, { path: "keys", element: , }, - { - path: "faq", - element: , - }, { path: "auth-successful", element: , diff --git a/front/src/root.jsx b/front/src/root.jsx index 5ba629a..61f8615 100644 --- a/front/src/root.jsx +++ b/front/src/root.jsx @@ -17,13 +17,10 @@ export const Root = () => {
- - FAQ - {signedIn ? ( <> - - User + + Password Keys diff --git a/front/src/routes/auth_successful.jsx b/front/src/routes/auth_successful.jsx index cb51573..7c66587 100644 --- a/front/src/routes/auth_successful.jsx +++ b/front/src/routes/auth_successful.jsx @@ -23,11 +23,17 @@ export const AuthSuccessful = () => { if (signedIn) { return ( <> -

Authentication Successful

+

Hello there, {player?.username || ""}!

+
+ If you have not already done so: + + Add a Public Key + +
+
- Hello there, {player?.username || ""}! - Go Home{" "} + Go Home
diff --git a/front/src/routes/home.jsx b/front/src/routes/home.jsx index 42734ad..4cfac77 100644 --- a/front/src/routes/home.jsx +++ b/front/src/routes/home.jsx @@ -14,27 +14,30 @@ export const Home = () => { PubkeyAuthentication yes`; return ( <> -

Hello there, {player?.username}!

-

- You can now start playing CheSSH by using any of your imported{" "} - public keys, or by{" "} - creating a password. -

- +

Welcome, {player?.username}


-

Getting Started

+

Getting Started

    -
  1. - Add the following to your ssh config (normally in ~/.ssh/config): -
  2. +
    +
  3. + Add a public key, or{" "} + set a password. +
  4. +
    +
    +
  5. + Insert the following block in your{" "} + ssh config: +
  6. - + +
  7. Then, connect with:
  8. diff --git a/front/src/routes/keys.jsx b/front/src/routes/keys.jsx index 3c552a1..4dee1ce 100644 --- a/front/src/routes/keys.jsx +++ b/front/src/routes/keys.jsx @@ -18,12 +18,18 @@ const KeyCard = ({ onDelete, props }) => { const { id, name, key } = props; const deleteThisKey = () => { - fetch(`/api/keys/${id}`, { - credentials: "same-origin", - method: "DELETE", - }) - .then((r) => r.json()) - .then((d) => d.success && onDelete && onDelete()); + if ( + window.confirm( + "Are you sure? This will close all your current ssh sessions." + ) + ) { + fetch(`/api/keys/${id}`, { + credentials: "same-origin", + method: "DELETE", + }) + .then((r) => r.json()) + .then((d) => d.success && onDelete && onDelete()); + } }; return ( @@ -44,13 +50,13 @@ const KeyCard = ({ onDelete, props }) => { const AddKeyButton = ({ onSave }) => { const [open, setOpen] = useState(false); - const [name, setName] = useState({ value: "", error: "" }); - const [key, setKey] = useState({ value: "", error: "" }); + const [name, setName] = useState(""); + const [key, setKey] = useState(""); const [errors, setErrors] = useState(null); const setDefaults = () => { - setName({ value: "", error: "" }); - setKey({ value: "", error: "" }); + setName(""); + setKey(""); setErrors(null); }; @@ -67,8 +73,8 @@ const AddKeyButton = ({ onSave }) => { "Content-Type": "application/json", }, body: JSON.stringify({ - key: key.value.trim(), - name: name.value, + key: key.trim(), + name: name.trim(), }), }) .then((r) => r.json()) @@ -119,8 +125,8 @@ const AddKeyButton = ({ onSave }) => {

    Key Name *

    setName({ ...name, value: e.target.value })} + value={name} + onChange={(e) => setName(e.target.value)} required />
    @@ -129,8 +135,8 @@ const AddKeyButton = ({ onSave }) => {