mirror of
https://gitlab.com/comunic/comunicconsole
synced 2024-12-25 13:08:52 +00:00
Can generate a password reset token
This commit is contained in:
parent
113c38daff
commit
dcafcbb8e6
@ -71,4 +71,15 @@ export class ComunicUsersHelper {
|
||||
new_mail: newEmail,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a password reset link for a user
|
||||
*/
|
||||
static async CreatePasswordRecoveryLink(id: number): Promise<string> {
|
||||
return (
|
||||
await serverRequest("users/create_password_reset_link", {
|
||||
user_id: id,
|
||||
})
|
||||
).url;
|
||||
}
|
||||
}
|
||||
|
@ -16,9 +16,16 @@ import {
|
||||
import { validateEmail } from "../../utils/StringsUtils";
|
||||
import { AsyncWidget } from "../widgets/AsyncWidget";
|
||||
import { CustomCard } from "../widgets/CustomCard";
|
||||
import { input, matAlert } from "../widgets/DialogsProvider";
|
||||
import {
|
||||
input,
|
||||
matAlert,
|
||||
matConfirm,
|
||||
snackbar,
|
||||
} from "../widgets/DialogsProvider";
|
||||
import { PageTitle } from "../widgets/PageTitle";
|
||||
import { TimestampWidget } from "../widgets/TimestampWidget";
|
||||
import LinkIcon from "@material-ui/icons/Link";
|
||||
import { CopyToClipboard } from "../../utils/ClipboardUtils";
|
||||
interface UserProperty {
|
||||
name: string;
|
||||
value?: string | number;
|
||||
@ -40,7 +47,9 @@ export class ComunicUserRoute extends React.Component<
|
||||
|
||||
this.load = this.load.bind(this);
|
||||
this.build = this.build.bind(this);
|
||||
|
||||
this.changeEmailAddress = this.changeEmailAddress.bind(this);
|
||||
this.createPasswordResetLink = this.createPasswordResetLink.bind(this);
|
||||
}
|
||||
|
||||
get user(): ComunicUser {
|
||||
@ -129,6 +138,16 @@ export class ComunicUserRoute extends React.Component<
|
||||
|
||||
if (!newEmail || newEmail.length === 0) return;
|
||||
|
||||
if (
|
||||
!(await matConfirm(
|
||||
"Do you really want to change email to " +
|
||||
newEmail +
|
||||
" for " +
|
||||
this.fullName
|
||||
))
|
||||
)
|
||||
return;
|
||||
|
||||
await ComunicUsersHelper.ChangeEmail(this.userID, newEmail);
|
||||
|
||||
this.setState((s) => {
|
||||
@ -141,6 +160,32 @@ export class ComunicUserRoute extends React.Component<
|
||||
}
|
||||
}
|
||||
|
||||
async createPasswordResetLink() {
|
||||
try {
|
||||
if (
|
||||
!(await matConfirm(
|
||||
"Do you really want to create a password recovery link for " +
|
||||
this.fullName +
|
||||
"?"
|
||||
))
|
||||
)
|
||||
return;
|
||||
|
||||
const link = await ComunicUsersHelper.CreatePasswordRecoveryLink(
|
||||
this.userID
|
||||
);
|
||||
|
||||
CopyToClipboard(link);
|
||||
|
||||
snackbar(
|
||||
"A password reset link has been successfully copied to the clipboard!"
|
||||
);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
matAlert("Failed to update user email address!");
|
||||
}
|
||||
}
|
||||
|
||||
build() {
|
||||
const properties = this.userProperties.map((p) => {
|
||||
return (
|
||||
@ -200,16 +245,36 @@ export class ComunicUserRoute extends React.Component<
|
||||
</Grid>
|
||||
<Grid item xs={6}>
|
||||
<CustomCard title="Actions">
|
||||
<div style={{ padding: "10px" }}>
|
||||
<div
|
||||
style={{
|
||||
padding: "10px",
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
}}
|
||||
>
|
||||
<Button
|
||||
variant="outlined"
|
||||
color="default"
|
||||
startIcon={<EmailIcon />}
|
||||
style={{ width: "100%" }}
|
||||
style={{
|
||||
width: "100%",
|
||||
}}
|
||||
onClick={this.changeEmailAddress}
|
||||
>
|
||||
Change email address
|
||||
</Button>
|
||||
|
||||
<div> </div>
|
||||
|
||||
<Button
|
||||
variant="outlined"
|
||||
color="default"
|
||||
startIcon={<LinkIcon />}
|
||||
style={{ width: "100%" }}
|
||||
onClick={this.createPasswordResetLink}
|
||||
>
|
||||
Create password reset link
|
||||
</Button>
|
||||
</div>
|
||||
</CustomCard>
|
||||
</Grid>
|
||||
|
Loading…
Reference in New Issue
Block a user