import { Button, Chip, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, Divider, Grid, Paper, TextField, Theme, Typography, } from "@mui/material"; import React, { useContext, useState } from "react"; import { CommonMenuList, Headline } from "../component/mod"; import { UserContext } from "../state"; import { PagePad } from "../component/pagepad"; const useStyles = (theme: Theme) => ({ paper: { alignSelf: "center", padding: theme.spacing(2), }, formfield: { display: "flex", flexFlow: "column", }, }); export function ProfilePage() { const userctx = useContext(UserContext); // const classes = useStyles(); const menu = CommonMenuList(); const [pw_open, set_pw_open] = useState(false); const [oldpw, setOldpw] = useState(""); const [newpw, setNewpw] = useState(""); const [newpwch, setNewpwch] = useState(""); const [msg_dialog, set_msg_dialog] = useState({ opened: false, msg: "" }); const permission_list = userctx.permission.map((p) => ); const isElectronContent = ((window["electron"] as any) !== undefined) as boolean; const handle_open = () => set_pw_open(true); const handle_close = () => { set_pw_open(false); setNewpw(""); setNewpwch(""); }; const handle_ok = async () => { if (newpw != newpwch) { set_msg_dialog({ opened: true, msg: "password and password check is not equal." }); handle_close(); return; } if (isElectronContent) { const elec = window["electron"] as any; const success = elec.passwordReset(userctx.username, newpw); if (!success) { set_msg_dialog({ opened: true, msg: "user not exist." }); } } else { const res = await fetch("/user/reset", { method: "POST", body: JSON.stringify({ username: userctx.username, oldpassword: oldpw, newpassword: newpw, }), headers: { "content-type": "application/json", }, }); if (res.status != 200) { set_msg_dialog({ opened: true, msg: "failed to change password." }); } } handle_close(); }; return ( {userctx.username} Permission {permission_list.length == 0 ? "-" : permission_list} Password Reset type the old and new password
{!isElectronContent && ( setOldpw(e.target.value)} > )} setNewpw(e.target.value)} > setNewpwch(e.target.value)} >
set_msg_dialog({ opened: false, msg: "" })}> Alert! {msg_dialog.msg}
); }