diff --git a/front/src/routes/home.jsx b/front/src/routes/home.jsx index 935163d..42734ad 100644 --- a/front/src/routes/home.jsx +++ b/front/src/routes/home.jsx @@ -4,20 +4,17 @@ import { Link } from "react-router-dom"; import { useAuthContext } from "../context/auth_context"; export const Home = () => { - const { - player: { username }, - signedIn, - } = useAuthContext(); + const { player, signedIn } = useAuthContext(); if (signedIn) { const sshConfig = `Host chessh Hostname ${process.env.REACT_APP_SSH_SERVER} Port ${process.env.REACT_APP_SSH_PORT} - User ${username} + User ${player?.username} PubkeyAuthentication yes`; return ( <> -

Hello there, {username}!

+

Hello there, {player?.username}!

You can now start playing CheSSH by using any of your imported{" "} public keys, or by{" "} diff --git a/lib/chessh/schema/player_session.ex b/lib/chessh/schema/player_session.ex index b16519f..f12387a 100644 --- a/lib/chessh/schema/player_session.ex +++ b/lib/chessh/schema/player_session.ex @@ -108,4 +108,12 @@ defmodule Chessh.PlayerSession do 3_000 -> false 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 diff --git a/lib/chessh/web/web.ex b/lib/chessh/web/web.ex index 1fa5fc3..9539c9a 100644 --- a/lib/chessh/web/web.ex +++ b/lib/chessh/web/web.ex @@ -1,5 +1,5 @@ defmodule Chessh.Web.Endpoint do - alias Chessh.{Player, Repo, Key} + alias Chessh.{Player, Repo, Key, PlayerSession} alias Chessh.Web.Token use Plug.Router require Logger @@ -45,6 +45,7 @@ defmodule Chessh.Web.Endpoint do put "/player/password" do player = get_player_from_jwt(conn) + PlayerSession.close_all_player_sessions(player) {status, body} = case conn.body_params do @@ -180,6 +181,7 @@ defmodule Chessh.Web.Endpoint do delete "/keys/:id" do player = get_player_from_jwt(conn) + PlayerSession.close_all_player_sessions(player) %{"id" => key_id} = conn.path_params key = Repo.get(Key, key_id)