Can generate reset access token for an account

This commit is contained in:
2021-05-14 15:33:04 +02:00
parent 585a66ef0a
commit 9b0f3c1fec
3 changed files with 66 additions and 1 deletions

View File

@@ -26,6 +26,7 @@ import {
AdminAccount,
AdminAccountKey,
} from "../../helpers/AccountHelper";
import { CopyToClipboard } from "../../utils/ClipboardUtils";
import { AsyncWidget } from "../widgets/AsyncWidget";
import {
input,
@@ -192,6 +193,7 @@ export class KeySettingsSection extends React.Component<
this.load = this.load.bind(this);
this.build = this.build.bind(this);
this.generateResetToken = this.generateResetToken.bind(this);
this.registerNewKey = this.registerNewKey.bind(this);
this.deleteKey = this.deleteKey.bind(this);
}
@@ -202,6 +204,27 @@ export class KeySettingsSection extends React.Component<
this.setState({ keys: keys });
}
async generateResetToken() {
try {
if (
!(await matConfirm(
"Do you really want to generate a reset token for this account?"
))
)
return;
const token = await AccountHelper.GenerateResetToken(
this.props.admin.id
);
CopyToClipboard(token.token);
snackbar("Reset token was successfully copied to the clipboard!");
} catch (e) {
console.error(e);
matAlert("Failed to generate a token!");
}
}
async registerNewKey() {
try {
const challenge = await AccountHelper.GetKeyRegistrationChallenge();
@@ -297,6 +320,9 @@ export class KeySettingsSection extends React.Component<
margin: "5px 10px",
}}
>
<Button onClick={this.generateResetToken}>
New reset token
</Button>
<Button
disabled={
this.props.admin.id !==
@@ -316,7 +342,7 @@ function SettingsSection(p: { title: string; children?: React.ReactNode }) {
return (
<Grid item sm={6}>
<Paper>
<Typography variant="h5" style={{ padding: "10px 10px " }}>
<Typography variant="h6" style={{ padding: "10px 15px " }}>
{p.title}
</Typography>
<Divider />