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";
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 (
<>
<h2>Hello there, {username}!</h2>
<h2>Hello there, {player?.username}!</h2>
<p>
You can now start playing CheSSH by using any of your imported{" "}
<Link to="/keys">public keys</Link>, or by{" "}

View File

@ -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

View File

@ -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)