users complete, i hope.
parent
f3c8a2e482
commit
0bfe2d9719
|
|
@ -1,4 +1,4 @@
|
||||||
import { useContext } from "react";
|
import { useContext, useEffect } from "react";
|
||||||
import ServerConnection from "./components/ServerConnection";
|
import ServerConnection from "./components/ServerConnection";
|
||||||
import Sidebar from "./components/Sidebar";
|
import Sidebar from "./components/Sidebar";
|
||||||
import TwoPanel from "./components/TwoPanel";
|
import TwoPanel from "./components/TwoPanel";
|
||||||
|
|
@ -21,13 +21,17 @@ export default function Router(props: RouterProps) {
|
||||||
const { clientId } = useClientId();
|
const { clientId } = useClientId();
|
||||||
const { sessionToken } = useSessionToken();
|
const { sessionToken } = useSessionToken();
|
||||||
const { homeServer } = useHomeServer();
|
const { homeServer } = useHomeServer();
|
||||||
const { isSettingsOpen } = useContext(SettingsContext);
|
const { isSettingsOpen, closeSettings } = useContext(SettingsContext);
|
||||||
|
|
||||||
const configured =
|
const configured =
|
||||||
homeServer !== null &&
|
homeServer !== null &&
|
||||||
clientId !== null &&
|
clientId !== null &&
|
||||||
sessionToken !== null;
|
sessionToken !== null;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if(!configured) closeSettings();
|
||||||
|
}, [configured])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
configured ? (
|
configured ? (
|
||||||
<ServerConnection url={homeServer}>
|
<ServerConnection url={homeServer}>
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ export default function EphemeralState(props: {
|
||||||
const [channel, setChannel] = useState<string | null>(null);
|
const [channel, setChannel] = useState<string | null>(null);
|
||||||
const [transparent, setTransparent] = useState(false);
|
const [transparent, setTransparent] = useState(false);
|
||||||
|
|
||||||
const [settings, setSettings] = useState(true);
|
const [settings, setSettings] = useState(false);
|
||||||
|
|
||||||
const channelContextValue = useMemo(() => {
|
const channelContextValue = useMemo(() => {
|
||||||
return { channel, setChannel };
|
return { channel, setChannel };
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import { AiOutlineEdit } from "react-icons/ai";
|
||||||
import { useApi } from "../lib/useApi";
|
import { useApi } from "../lib/useApi";
|
||||||
import useSessionToken from "../hooks/useSessionToken";
|
import useSessionToken from "../hooks/useSessionToken";
|
||||||
import useClientId from "../hooks/useClientId";
|
import useClientId from "../hooks/useClientId";
|
||||||
|
import QR from 'qrcode';
|
||||||
|
|
||||||
export default function NewAccount() {
|
export default function NewAccount() {
|
||||||
|
|
||||||
|
|
@ -399,13 +400,67 @@ interface SignUpProps {
|
||||||
|
|
||||||
function SignUp(props: SignUpProps) {
|
function SignUp(props: SignUpProps) {
|
||||||
const [usernameInput, setUsernameInput] = useState('');
|
const [usernameInput, setUsernameInput] = useState('');
|
||||||
|
const [displayNameInput, setDisplayNameInput] = useState('');
|
||||||
const [authCodeInput, setAuthCodeInput] = useState('');
|
const [authCodeInput, setAuthCodeInput] = useState('');
|
||||||
|
const [tempClientId, setTempClientId] = useState<string | null>(null);
|
||||||
|
const [qr, setQr] = useState<string | null>(null);
|
||||||
|
|
||||||
const next = () => {
|
const { setClientId } = useClientId();
|
||||||
|
const { setSessionToken } = useSessionToken();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
send('totp:propose', {
|
||||||
|
clientId: tempClientId
|
||||||
|
})
|
||||||
|
}, [tempClientId])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setDisplayNameInput(usernameInput);
|
||||||
|
}, [usernameInput])
|
||||||
|
|
||||||
|
const { send } = useApi({
|
||||||
|
'client:new'({clientId}) {
|
||||||
|
setTempClientId(clientId)
|
||||||
|
},
|
||||||
|
async 'totp:propose'(data: any) {
|
||||||
|
const { key } = data;
|
||||||
|
const totpUrl =
|
||||||
|
'otpauth://totp/' +
|
||||||
|
(usernameInput ?? '') +
|
||||||
|
'?secret=' +
|
||||||
|
key +
|
||||||
|
'&issuer=xyz-valnet-corner';
|
||||||
|
console.log(totpUrl);
|
||||||
|
setQr(await QR.toDataURL(totpUrl));
|
||||||
|
},
|
||||||
|
'totp:confirm'(data: any) {
|
||||||
|
console.log(data);
|
||||||
|
const { sessionToken } = data;
|
||||||
|
setClientId(tempClientId);
|
||||||
|
setSessionToken(sessionToken);
|
||||||
|
console.log(sessionToken, tempClientId);
|
||||||
}
|
}
|
||||||
|
}, [usernameInput, tempClientId]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const next = useCallback(() => {
|
||||||
|
if(!tempClientId) {
|
||||||
|
send('client:new', {
|
||||||
|
displayName: displayNameInput,
|
||||||
|
username: usernameInput
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
send('totp:confirm', {
|
||||||
|
clientId: tempClientId,
|
||||||
|
code: authCodeInput
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [tempClientId, displayNameInput, usernameInput, authCodeInput]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
|
{!tempClientId ? (
|
||||||
<>
|
<>
|
||||||
<Label>Username</Label>
|
<Label>Username</Label>
|
||||||
<div style={{
|
<div style={{
|
||||||
|
|
@ -419,6 +474,31 @@ function SignUp(props: SignUpProps) {
|
||||||
focusOnEenable={true}
|
focusOnEenable={true}
|
||||||
></Input>
|
></Input>
|
||||||
</div>
|
</div>
|
||||||
|
<Label>Display Name</Label>
|
||||||
|
<div style={{
|
||||||
|
transform: 'skew(6deg, 0deg)',
|
||||||
|
margin: '8px',
|
||||||
|
}}>
|
||||||
|
<Input
|
||||||
|
disabled={props.disabled}
|
||||||
|
value={displayNameInput}
|
||||||
|
setValue={setDisplayNameInput}
|
||||||
|
></Input>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
{qr && (
|
||||||
|
<div style={{
|
||||||
|
textAlign: 'center',
|
||||||
|
transform: 'skew(6deg, 0deg)',
|
||||||
|
}}>
|
||||||
|
<img
|
||||||
|
src={qr}
|
||||||
|
></img>
|
||||||
|
<br></br>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<Label>Auth Code</Label>
|
<Label>Auth Code</Label>
|
||||||
<div style={{
|
<div style={{
|
||||||
transform: 'skew(6deg, 0deg)',
|
transform: 'skew(6deg, 0deg)',
|
||||||
|
|
@ -428,8 +508,11 @@ function SignUp(props: SignUpProps) {
|
||||||
disabled={props.disabled}
|
disabled={props.disabled}
|
||||||
value={authCodeInput}
|
value={authCodeInput}
|
||||||
setValue={setAuthCodeInput}
|
setValue={setAuthCodeInput}
|
||||||
|
focusOnEenable={true}
|
||||||
></Input>
|
></Input>
|
||||||
</div>
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
{!props.disabled && <Next onClick={next}></Next>}
|
{!props.disabled && <Next onClick={next}></Next>}
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,9 @@ export default router({
|
||||||
data.username,
|
data.username,
|
||||||
);
|
);
|
||||||
if(response === null) return;
|
if(response === null) return;
|
||||||
return reply(response[0][0].uid);
|
return reply({
|
||||||
|
clientId: response[0][0].uid
|
||||||
|
});
|
||||||
},
|
},
|
||||||
async 'get'(data: any) {
|
async 'get'(data: any) {
|
||||||
const response = await query(_get, data.clientId);
|
const response = await query(_get, data.clientId);
|
||||||
|
|
|
||||||
|
|
@ -9,16 +9,16 @@ import { generateTotpKey } from "../lib/generateTotpKey";
|
||||||
const proposals: any = {}
|
const proposals: any = {}
|
||||||
|
|
||||||
export default router({
|
export default router({
|
||||||
'propose'(clientId: string) {
|
'propose'(data: any) {
|
||||||
|
const { clientId } = data;
|
||||||
|
if(!clientId) return;
|
||||||
if(clientId in proposals) return reply(proposals[clientId]);
|
if(clientId in proposals) return reply(proposals[clientId]);
|
||||||
const key = generateTotpKey();
|
const key = generateTotpKey();
|
||||||
proposals[clientId] = key;
|
proposals[clientId] = key;
|
||||||
console.log(clientId, proposals)
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
delete proposals[clientId];
|
delete proposals[clientId];
|
||||||
}, 5 * 60 * 1000);
|
}, 5 * 60 * 1000);
|
||||||
console.log('created totp proposal');
|
return reply({ key });
|
||||||
return reply(key)
|
|
||||||
},
|
},
|
||||||
async 'confirm'(data: any) {
|
async 'confirm'(data: any) {
|
||||||
const { clientId, code } = data;
|
const { clientId, code } = data;
|
||||||
|
|
@ -34,8 +34,9 @@ export default router({
|
||||||
err: 'unknown database error, contact server admin.'
|
err: 'unknown database error, contact server admin.'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
delete proposals[clientId];
|
||||||
return reply({
|
return reply({
|
||||||
token: await generateSessionToken(clientId),
|
sessionToken: await generateSessionToken(clientId),
|
||||||
err: null
|
err: null
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Reference in New Issue