Web Client #11

Merged
Simponic merged 19 commits from web into main 2023-01-19 16:04:10 -05:00
3 changed files with 14 additions and 7 deletions
Showing only changes of commit af0207d8ce - Show all commits

View File

@ -4,20 +4,17 @@ import { Link } from "react-router-dom";
import { useAuthContext } from "../context/auth_context"; import { useAuthContext } from "../context/auth_context";
export const Home = () => { export const Home = () => {
const { const { player, signedIn } = useAuthContext();
player: { username },
signedIn,
} = useAuthContext();
if (signedIn) { if (signedIn) {
const sshConfig = `Host chessh const sshConfig = `Host chessh
Hostname ${process.env.REACT_APP_SSH_SERVER} Hostname ${process.env.REACT_APP_SSH_SERVER}
Port ${process.env.REACT_APP_SSH_PORT} Port ${process.env.REACT_APP_SSH_PORT}
User ${username} User ${player?.username}
PubkeyAuthentication yes`; PubkeyAuthentication yes`;
return ( return (
<> <>
<h2>Hello there, {username}!</h2> <h2>Hello there, {player?.username}!</h2>
<p> <p>
You can now start playing CheSSH by using any of your imported{" "} You can now start playing CheSSH by using any of your imported{" "}
<Link to="/keys">public keys</Link>, or by{" "} <Link to="/keys">public keys</Link>, or by{" "}

View File

@ -108,4 +108,12 @@ defmodule Chessh.PlayerSession do
3_000 -> false 3_000 -> false
end end
end end
def close_all_player_sessions(player) do
player_sessions = Repo.all(from(p in PlayerSession, where: p.player_id == ^player.id))
Enum.map(player_sessions, fn session ->
:syn.publish(:player_sessions, {:session, session.id}, :session_closed)
end)
end
end end

View File

@ -1,5 +1,5 @@
defmodule Chessh.Web.Endpoint do defmodule Chessh.Web.Endpoint do
alias Chessh.{Player, Repo, Key} alias Chessh.{Player, Repo, Key, PlayerSession}
alias Chessh.Web.Token alias Chessh.Web.Token
use Plug.Router use Plug.Router
require Logger require Logger
@ -45,6 +45,7 @@ defmodule Chessh.Web.Endpoint do
put "/player/password" do put "/player/password" do
player = get_player_from_jwt(conn) player = get_player_from_jwt(conn)
PlayerSession.close_all_player_sessions(player)
{status, body} = {status, body} =
case conn.body_params do case conn.body_params do
@ -180,6 +181,7 @@ defmodule Chessh.Web.Endpoint do
delete "/keys/:id" do delete "/keys/:id" do
player = get_player_from_jwt(conn) player = get_player_from_jwt(conn)
PlayerSession.close_all_player_sessions(player)
%{"id" => key_id} = conn.path_params %{"id" => key_id} = conn.path_params
key = Repo.get(Key, key_id) key = Repo.get(Key, key_id)