/** @format */ import { useState, useEffect } from "react"; import { Cookies, useCookies } from "react-cookie"; import { useNavigate, useParams, Link } from "react-router-dom"; import { EventEmitter as event } from "../../eventEmitter.js"; import { motion } from "framer-motion"; // import Icon from "mdi-material-ui"; import EyeOffOutline from "mdi-material-ui/EyeOffOutline"; import EyeOutline from "mdi-material-ui/EyeOutline"; import ChevronRight from "mdi-material-ui/ChevronRight"; import Container from "@mui/material/Container"; import Grid from "@mui/material/Grid"; import Typography from "@mui/material/Typography"; import OutlinedInput from "@mui/material/OutlinedInput"; import FormControl from "@mui/material/FormControl"; import InputAdornment from "@mui/material/InputAdornment"; import InputLabel from "@mui/material/InputLabel"; import IconButton from "@mui/material/IconButton"; import Avatar from "@mui/material/Avatar"; import LoadingButton from "@mui/lab/LoadingButton"; import Button from "@mui/material/Button"; import { useSnackbar } from "notistack"; import { AvatarCard, AvatarImage } from "../../components/avatar/avatar.jsx"; import { AppBarBackOnly } from "../../components/appBar/backOnly.jsx"; // import { jellyfin } from "../../jellyfin"; // import getSystemApi from "@jellyfin/sdk"; import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api"; import "./login.module.scss"; export const LoginWithImage = () => { const { userName, userId } = useParams(); const [password, setPassword] = useState({ showpass: false, }); const [loading, setLoading] = useState(false); const navigate = useNavigate(); const { enqueueSnackbar } = useSnackbar(); const handlePassword = (prop) => (event) => { setPassword({ ...password, [prop]: event.target.value, }); }; const handleShowPassword = () => { setPassword({ ...password, showpass: !password.showpass, }); }; const authUser = async () => { try { const auth = await api.authenticateUserByName( userName, password.password, ); return auth; } catch (error) { enqueueSnackbar("Incorrect Password!", { variant: "error" }); setLoading(false); console.error(error); } }; const handleLogin = async () => { setLoading(true); const user = await authUser(); sessionStorage.setItem("accessToken", user.data.AccessToken); event.emit("set-api-accessToken", window.api.basePath); // setAccessToken(user.data.AccessToken) setLoading(false); navigate(`/home`); }; return ( <> Login {userName} Password: {password.showpass ? ( ) : ( )} } /> } onClick={handleLogin} loading={loading} loadingPosition="end" size="large" fullWidth > Login > ); }; export const UserLogin = () => { const [userList, setUsers] = useState([]); const navigate = useNavigate(); const cookies = new Cookies(); const currentServer = cookies.get("currentServer"); const serverList = cookies.get("servers"); const handleChangeServer = () => { navigate("/servers/list"); }; const handleManualLogin = () => { navigate("/login/manual"); }; const getUsers = async () => { const users = await getUserApi(window.api).getPublicUsers(); // console.log(users.data); return users; // return {}; }; useEffect(() => { getUsers().then((users) => { setUsers(users.data); }); }); return ( <> WIP-user login {userList.map((item, index) => { return ( // {item.ImageTags == undefined ? ( ) : ( )} ); })} Change Server Manual Login > ); }; export const UserLoginManual = () => { const [loading, setLoading] = useState(false); const navigate = useNavigate(); const { enqueueSnackbar } = useSnackbar(); const [password, setPassword] = useState({ showpass: false, }); const [userName, setUserName] = useState(""); const handleUsername = (event) => { setUserName(event.target.value); }; const handlePassword = (prop) => (event) => { setPassword({ ...password, [prop]: event.target.value, }); }; const handleShowPassword = () => { setPassword({ ...password, showpass: !password.showpass, }); }; const authUser = async () => { try { const auth = await api.authenticateUserByName( userName, password.password, ); return auth; } catch (error) { enqueueSnackbar("Incorrect Username or Password!", { variant: "error", }); setLoading(false); console.error(error); } }; const handleLogin = async () => { setLoading(true); const user = await authUser(); sessionStorage.setItem("accessToken", user.data.AccessToken); event.emit("set-api-accessToken", window.api.basePath); // setAccessToken(user.data.AccessToken) setLoading(false); navigate(`/home`); }; return ( <> Login Username: Password: {password.showpass ? ( ) : ( )} } /> } onClick={handleLogin} loading={loading} loadingPosition="end" size="large" sx={{ width: "100%" }} > Login > ); };