3 files changed
+288
-48
No files matched your search
+274
-48
@@ -1,11 +1,20 @@
|
|||||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||||
import React, { useState } from "react";
|
import React, { useLayoutEffect, useState } from "react";
|
||||||
import { useNavigate, useParams } from "react-router-dom";
|
import { useNavigate, useParams } from "react-router-dom";
|
||||||
import { EventEmitter as event } from "../../eventEmitter.js";
|
import { EventEmitter as event } from "../../eventEmitter.js";
|
||||||
|
|
||||||
import { saveUser } from "../../utils/storage/user";
|
import { saveUser } from "../../utils/storage/user";
|
||||||
|
|
||||||
import LoadingButton from "@mui/lab/LoadingButton";
|
import LoadingButton from "@mui/lab/LoadingButton";
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogActions,
|
||||||
|
DialogContent,
|
||||||
|
DialogContentText,
|
||||||
|
Grid,
|
||||||
|
OutlinedInput,
|
||||||
|
Typography,
|
||||||
|
} from "@mui/material";
|
||||||
import Button from "@mui/material/Button";
|
import Button from "@mui/material/Button";
|
||||||
import Checkbox from "@mui/material/Checkbox";
|
import Checkbox from "@mui/material/Checkbox";
|
||||||
import CircularProgress from "@mui/material/CircularProgress";
|
import CircularProgress from "@mui/material/CircularProgress";
|
||||||
@@ -17,9 +26,7 @@ import IconButton from "@mui/material/IconButton";
|
|||||||
import InputAdornment from "@mui/material/InputAdornment";
|
import InputAdornment from "@mui/material/InputAdornment";
|
||||||
import InputLabel from "@mui/material/InputLabel";
|
import InputLabel from "@mui/material/InputLabel";
|
||||||
import LinearProgress from "@mui/material/LinearProgress";
|
import LinearProgress from "@mui/material/LinearProgress";
|
||||||
import OutlinedInput from "@mui/material/OutlinedInput";
|
|
||||||
import Typography from "@mui/material/Typography";
|
|
||||||
import Grid from "@mui/material/Unstable_Grid2";
|
|
||||||
import { useSnackbar } from "notistack";
|
import { useSnackbar } from "notistack";
|
||||||
|
|
||||||
import { AppBarBackOnly } from "../../components/appBar/backOnly.jsx";
|
import { AppBarBackOnly } from "../../components/appBar/backOnly.jsx";
|
||||||
@@ -34,6 +41,8 @@ import { ErrorNotice } from "../../components/notices/errorNotice/errorNotice.js
|
|||||||
import { useApi } from "../../utils/store/api";
|
import { useApi } from "../../utils/store/api";
|
||||||
import "./login.module.scss";
|
import "./login.module.scss";
|
||||||
|
|
||||||
|
import { setBackdrop } from "../../utils/store/backdrop.js";
|
||||||
|
|
||||||
export const LoginRoute = () => {
|
export const LoginRoute = () => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [api] = useApi((state) => [state.api]);
|
const [api] = useApi((state) => [state.api]);
|
||||||
@@ -124,6 +133,10 @@ export const LoginWithImage = () => {
|
|||||||
navigate("/home");
|
navigate("/home");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useLayoutEffect(() => {
|
||||||
|
setBackdrop("", "");
|
||||||
|
}, []);
|
||||||
|
|
||||||
const handleCheckRememberMe = (event) => {
|
const handleCheckRememberMe = (event) => {
|
||||||
setRememberMe(event.target.checked);
|
setRememberMe(event.target.checked);
|
||||||
};
|
};
|
||||||
@@ -220,7 +233,9 @@ export const LoginWithImage = () => {
|
|||||||
<Grid minWidth="100%">
|
<Grid minWidth="100%">
|
||||||
<LoadingButton
|
<LoadingButton
|
||||||
variant="contained"
|
variant="contained"
|
||||||
endIcon={<MdiChevronRight />}
|
endIcon={
|
||||||
|
<span className="material-symbols-rounded">chevron_right</span>
|
||||||
|
}
|
||||||
onClick={handleLogin}
|
onClick={handleLogin}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
loadingPosition="end"
|
loadingPosition="end"
|
||||||
@@ -243,6 +258,10 @@ export const UserLogin = () => {
|
|||||||
|
|
||||||
const [api] = useApi((state) => [state.api]);
|
const [api] = useApi((state) => [state.api]);
|
||||||
|
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [quickConnectLoading, setQuickConnectLoading] = useState(-1);
|
||||||
|
const [quickConnectCode, setQuickConnectCode] = useState("");
|
||||||
|
|
||||||
const handleChangeServer = () => {
|
const handleChangeServer = () => {
|
||||||
navigate("/servers/list");
|
navigate("/servers/list");
|
||||||
};
|
};
|
||||||
@@ -258,6 +277,94 @@ export const UserLogin = () => {
|
|||||||
staleTime: 0,
|
staleTime: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const handleQuickConnect = async () => {
|
||||||
|
setQuickConnectLoading(0);
|
||||||
|
|
||||||
|
const quickApi = getQuickConnectApi(api);
|
||||||
|
|
||||||
|
const headers = {
|
||||||
|
"X-Emby-Authorization": `MediaBrowser Client="${api.clientInfo.name}", Device="${api.deviceInfo.name}", DeviceId="${api.deviceInfo.id}", Version="${api.clientInfo.version}"`,
|
||||||
|
};
|
||||||
|
|
||||||
|
const quickConnectInitiation = await quickApi
|
||||||
|
.initiate({
|
||||||
|
headers,
|
||||||
|
})
|
||||||
|
.catch(() => ({ status: 401 }));
|
||||||
|
|
||||||
|
if (quickConnectInitiation.status !== 200) {
|
||||||
|
setQuickConnectLoading(-1);
|
||||||
|
enqueueSnackbar("Unable to use Quick Connect", {
|
||||||
|
variant: "error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setQuickConnectLoading(1);
|
||||||
|
|
||||||
|
const { Secret, Code } = quickConnectInitiation.data;
|
||||||
|
|
||||||
|
setQuickConnectCode(Code);
|
||||||
|
|
||||||
|
const interval = setInterval(async () => {
|
||||||
|
const quickConnectCheck = await quickApi
|
||||||
|
.connect({
|
||||||
|
secret: Secret,
|
||||||
|
})
|
||||||
|
.catch(() => ({ status: 401, data: { Authenticated: false } }));
|
||||||
|
|
||||||
|
if (quickConnectCheck.status !== 200) {
|
||||||
|
enqueueSnackbar("Unable to use Quick Connect", {
|
||||||
|
variant: "error",
|
||||||
|
});
|
||||||
|
|
||||||
|
setQuickConnectLoading(-1);
|
||||||
|
clearInterval(interval);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!quickConnectCheck.data.Authenticated) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auth = await getUserApi(api)
|
||||||
|
.authenticateWithQuickConnect({
|
||||||
|
quickConnectDto: {
|
||||||
|
Secret: Secret,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.catch(() => ({ status: 401 }));
|
||||||
|
|
||||||
|
api.accessToken = auth.data.AccessToken;
|
||||||
|
|
||||||
|
clearInterval(interval);
|
||||||
|
|
||||||
|
if (auth.status !== 200) {
|
||||||
|
enqueueSnackbar("Unable to use Quick Connect", {
|
||||||
|
variant: "error",
|
||||||
|
});
|
||||||
|
setQuickConnectLoading(-1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sessionStorage.setItem("accessToken", auth.data.AccessToken);
|
||||||
|
|
||||||
|
if (rememberMe === true) {
|
||||||
|
await saveUser(userName, auth.data.AccessToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
event.emit("set-api-accessToken", api.basePath);
|
||||||
|
setQuickConnectLoading(-1);
|
||||||
|
navigate("/home");
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
setLoading(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
useLayoutEffect(() => {
|
||||||
|
setBackdrop("", "");
|
||||||
|
}, []);
|
||||||
|
|
||||||
if (users.isPending) {
|
if (users.isPending) {
|
||||||
return <LinearProgress />;
|
return <LinearProgress />;
|
||||||
}
|
}
|
||||||
@@ -331,22 +438,91 @@ export const UserLogin = () => {
|
|||||||
>
|
>
|
||||||
Change Server
|
Change Server
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<LoadingButton
|
||||||
|
onClick={handleQuickConnect}
|
||||||
variant="contained"
|
variant="contained"
|
||||||
className="userEventButton"
|
className="userEventButton"
|
||||||
onClick={handleInitiateQuickConnect.mutate}
|
sx={{ width: "100%" }}
|
||||||
// disabled
|
loading={quickConnectLoading === 1}
|
||||||
|
size="large"
|
||||||
>
|
>
|
||||||
Quick Connect
|
Quick Connect
|
||||||
</Button>
|
</LoadingButton>
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
className="userEventButton"
|
className="userEventButton"
|
||||||
onClick={handleManualLogin}
|
onClick={handleManualLogin}
|
||||||
|
size="small"
|
||||||
>
|
>
|
||||||
Manual Login
|
Manual Login
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<Dialog open={Boolean(quickConnectCode)} fullWidth maxWidth="xs">
|
||||||
|
<DialogContent
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: "column",
|
||||||
|
alignItems: "center",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
variant="h5"
|
||||||
|
mb={2}
|
||||||
|
style={{
|
||||||
|
width: "100%",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Quick Connect Code:
|
||||||
|
</Typography>
|
||||||
|
<DialogContentText>
|
||||||
|
Use this code in the Quick Connect tab in your server to login.
|
||||||
|
</DialogContentText>
|
||||||
|
<div
|
||||||
|
className="flex flex-row"
|
||||||
|
style={{ gap: "1em", alignItems: "center", marginTop: "1em" }}
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
variant="h3"
|
||||||
|
color="textPrimary"
|
||||||
|
textAlign="center"
|
||||||
|
sx={{
|
||||||
|
background: "rgb(255 255 255 / 0.1)",
|
||||||
|
width: "fit-content",
|
||||||
|
padding: "0.4em",
|
||||||
|
borderRadius: "10px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{quickConnectCode}
|
||||||
|
</Typography>
|
||||||
|
<IconButton
|
||||||
|
onClick={(e) => {
|
||||||
|
navigator.clipboard.writeText(quickConnectCode);
|
||||||
|
enqueueSnackbar("Quick Connect Code copied!", {
|
||||||
|
variant: "info",
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span className="material-symbols-rounded">content_copy</span>
|
||||||
|
</IconButton>
|
||||||
|
</div>
|
||||||
|
</DialogContent>
|
||||||
|
<DialogActions
|
||||||
|
sx={{
|
||||||
|
padding: "0em 1em 1em 0em",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
onClick={() => {
|
||||||
|
setQuickConnectCode("");
|
||||||
|
setQuickConnectLoading(-1);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Close
|
||||||
|
</Button>
|
||||||
|
</DialogActions>
|
||||||
|
</Dialog>
|
||||||
</Container>
|
</Container>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
@@ -514,6 +690,10 @@ export const UserLoginManual = () => {
|
|||||||
setLoading(false);
|
setLoading(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useLayoutEffect(() => {
|
||||||
|
setBackdrop("", "");
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{server.isPending && <LinearProgress />}
|
{server.isPending && <LinearProgress />}
|
||||||
@@ -544,7 +724,7 @@ export const UserLoginManual = () => {
|
|||||||
Login
|
Login
|
||||||
</Typography>
|
</Typography>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid sx={{ width: "100%" }}>
|
<Grid sx={{ width: "100%", mb: 1 }}>
|
||||||
<FormControl sx={{ width: "100%" }} variant="outlined">
|
<FormControl sx={{ width: "100%" }} variant="outlined">
|
||||||
<InputLabel htmlFor="user-name">Username:</InputLabel>
|
<InputLabel htmlFor="user-name">Username:</InputLabel>
|
||||||
<OutlinedInput
|
<OutlinedInput
|
||||||
@@ -580,9 +760,13 @@ export const UserLoginManual = () => {
|
|||||||
aria-label="toggle password visibility"
|
aria-label="toggle password visibility"
|
||||||
>
|
>
|
||||||
{password.showpass ? (
|
{password.showpass ? (
|
||||||
<MdiEyeOffOutline />
|
<span className="material-symbols-rounded">
|
||||||
|
visibility
|
||||||
|
</span>
|
||||||
) : (
|
) : (
|
||||||
<MdiEyeOutline />
|
<span className="material-symbols-rounded">
|
||||||
|
visibility_off
|
||||||
|
</span>
|
||||||
)}
|
)}
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</InputAdornment>
|
</InputAdornment>
|
||||||
@@ -600,67 +784,109 @@ export const UserLoginManual = () => {
|
|||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid sx={{ width: "100%" }}>
|
<div
|
||||||
|
className="flex flex-column"
|
||||||
|
style={{ width: "100%", gap: "0.4em" }}
|
||||||
|
>
|
||||||
<LoadingButton
|
<LoadingButton
|
||||||
variant="contained"
|
variant="contained"
|
||||||
endIcon={<MdiChevronRight />}
|
endIcon={
|
||||||
|
<span className="material-symbols-rounded">chevron_right</span>
|
||||||
|
}
|
||||||
onClick={handleLogin}
|
onClick={handleLogin}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
loadingPosition="end"
|
loadingPosition="end"
|
||||||
size="large"
|
size="large"
|
||||||
sx={{ width: "100%", mb: 1 }}
|
sx={{ width: "100%" }}
|
||||||
>
|
>
|
||||||
Login
|
Login
|
||||||
</LoadingButton>
|
</LoadingButton>
|
||||||
|
<LoadingButton
|
||||||
|
onClick={handleQuickConnect}
|
||||||
|
variant="contained"
|
||||||
|
className="userEventButton"
|
||||||
|
sx={{ width: "100%" }}
|
||||||
|
loading={quickConnectLoading === 1}
|
||||||
|
// size="large"
|
||||||
|
>
|
||||||
|
Quick Connect
|
||||||
|
</LoadingButton>
|
||||||
<Button
|
<Button
|
||||||
color="secondary"
|
color="secondary"
|
||||||
variant="contained"
|
variant="contained"
|
||||||
className="userEventButton"
|
className="userEventButton"
|
||||||
size="large"
|
// size="large"
|
||||||
sx={{ width: "100%" }}
|
sx={{ width: "100%" }}
|
||||||
onClick={() => navigate("/servers/list")}
|
onClick={() => navigate("/servers/list")}
|
||||||
>
|
>
|
||||||
Change Server
|
Change Server
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
</div>
|
||||||
onClick={handleQuickConnect}
|
<Dialog open={Boolean(quickConnectCode)} fullWidth maxWidth="xs">
|
||||||
variant="contained"
|
<DialogContent
|
||||||
className="userEventButton"
|
|
||||||
size="large"
|
|
||||||
sx={{ width: "100%", marginTop: "0.6em" }}
|
|
||||||
>
|
|
||||||
{
|
|
||||||
{
|
|
||||||
[-1]: "Quick Connect",
|
|
||||||
[0]: "Connecting",
|
|
||||||
[1]: <CircularProgress color="white" size={24} />,
|
|
||||||
}[Math.min(quickConnectLoading, 1)]
|
|
||||||
}
|
|
||||||
</Button>
|
|
||||||
{quickConnectCode !== "" && (
|
|
||||||
<div
|
|
||||||
style={{
|
style={{
|
||||||
position: "fixed",
|
|
||||||
top: 0,
|
|
||||||
left: 0,
|
|
||||||
width: "100%",
|
|
||||||
height: "100%",
|
|
||||||
display: "flex",
|
display: "flex",
|
||||||
justifyContent: "center",
|
flexDirection: "column",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
zIndex: 9999,
|
|
||||||
backgroundColor: "rgba(0,0,0,0.8)",
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div>
|
<Typography
|
||||||
<Typography variant="h5" color="textPrimary">
|
variant="h5"
|
||||||
{quickConnectCode}
|
mb={2}
|
||||||
|
style={{
|
||||||
|
width: "100%",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Quick Connect Code:
|
||||||
</Typography>
|
</Typography>
|
||||||
<Button onClick={() => setQuickConnectCode("")}>Close</Button>
|
<DialogContentText>
|
||||||
|
Use this code in the Quick Connect tab in your server to login.
|
||||||
|
</DialogContentText>
|
||||||
|
<div
|
||||||
|
className="flex flex-row"
|
||||||
|
style={{ gap: "1em", alignItems: "center", marginTop: "1em" }}
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
variant="h3"
|
||||||
|
color="textPrimary"
|
||||||
|
textAlign="center"
|
||||||
|
sx={{
|
||||||
|
background: "rgb(255 255 255 / 0.1)",
|
||||||
|
width: "fit-content",
|
||||||
|
padding: "0.4em",
|
||||||
|
borderRadius: "10px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{quickConnectCode ?? "******"}
|
||||||
|
</Typography>
|
||||||
|
<IconButton
|
||||||
|
onClick={(e) => {
|
||||||
|
navigator.clipboard.writeText(quickConnectCode);
|
||||||
|
enqueueSnackbar("Quick Connect Code copied!", {
|
||||||
|
variant: "info",
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span className="material-symbols-rounded">content_copy</span>
|
||||||
|
</IconButton>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</DialogContent>
|
||||||
)}
|
<DialogActions
|
||||||
</Grid>
|
sx={{
|
||||||
|
padding: "0em 1em 1em 0em",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
onClick={() => {
|
||||||
|
setQuickConnectCode("");
|
||||||
|
setQuickConnectLoading(-1);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Close
|
||||||
|
</Button>
|
||||||
|
</DialogActions>
|
||||||
|
</Dialog>
|
||||||
<Grid sx={{ width: "100%" }}>
|
<Grid sx={{ width: "100%" }}>
|
||||||
<Typography variant="subtitle2">
|
<Typography variant="subtitle2">
|
||||||
{server.isSuccess && server.data.LoginDisclaimer}
|
{server.isSuccess && server.data.LoginDisclaimer}
|
||||||
|
|||||||
@@ -66,5 +66,15 @@ export const theme = createTheme({
|
|||||||
disableScrollLock: true,
|
disableScrollLock: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
MuiDialog: {
|
||||||
|
styleOverrides: {
|
||||||
|
paper: {
|
||||||
|
borderRadius: "20px",
|
||||||
|
background: "rgb(0 0 0 / 0.5)",
|
||||||
|
backdropFilter: "blur(10px)",
|
||||||
|
border: "1px solid rgb(255 255 255 / 0.2)",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -6,3 +6,7 @@ export const useBackdropStore = create((set) => ({
|
|||||||
setBackdrop: (url, id) =>
|
setBackdrop: (url, id) =>
|
||||||
set((state) => ({ backdropUrl: url, backdropId: id })),
|
set((state) => ({ backdropUrl: url, backdropId: id })),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
export const setBackdrop = (url, id) => {
|
||||||
|
useBackdropStore.setState(() => ({ backdropUrl: url, backdropId: id }));
|
||||||
|
};
|
||||||
Reference in new issue
Block a user