mirror of
https://gitlab.com/comunic/comunicconsole
synced 2024-11-27 07:49:22 +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,
|
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 { validateEmail } from "../../utils/StringsUtils";
|
||||||
import { AsyncWidget } from "../widgets/AsyncWidget";
|
import { AsyncWidget } from "../widgets/AsyncWidget";
|
||||||
import { CustomCard } from "../widgets/CustomCard";
|
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 { PageTitle } from "../widgets/PageTitle";
|
||||||
import { TimestampWidget } from "../widgets/TimestampWidget";
|
import { TimestampWidget } from "../widgets/TimestampWidget";
|
||||||
|
import LinkIcon from "@material-ui/icons/Link";
|
||||||
|
import { CopyToClipboard } from "../../utils/ClipboardUtils";
|
||||||
interface UserProperty {
|
interface UserProperty {
|
||||||
name: string;
|
name: string;
|
||||||
value?: string | number;
|
value?: string | number;
|
||||||
@ -40,7 +47,9 @@ export class ComunicUserRoute extends React.Component<
|
|||||||
|
|
||||||
this.load = this.load.bind(this);
|
this.load = this.load.bind(this);
|
||||||
this.build = this.build.bind(this);
|
this.build = this.build.bind(this);
|
||||||
|
|
||||||
this.changeEmailAddress = this.changeEmailAddress.bind(this);
|
this.changeEmailAddress = this.changeEmailAddress.bind(this);
|
||||||
|
this.createPasswordResetLink = this.createPasswordResetLink.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
get user(): ComunicUser {
|
get user(): ComunicUser {
|
||||||
@ -129,6 +138,16 @@ export class ComunicUserRoute extends React.Component<
|
|||||||
|
|
||||||
if (!newEmail || newEmail.length === 0) return;
|
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);
|
await ComunicUsersHelper.ChangeEmail(this.userID, newEmail);
|
||||||
|
|
||||||
this.setState((s) => {
|
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() {
|
build() {
|
||||||
const properties = this.userProperties.map((p) => {
|
const properties = this.userProperties.map((p) => {
|
||||||
return (
|
return (
|
||||||
@ -200,16 +245,36 @@ export class ComunicUserRoute extends React.Component<
|
|||||||
</Grid>
|
</Grid>
|
||||||
<Grid item xs={6}>
|
<Grid item xs={6}>
|
||||||
<CustomCard title="Actions">
|
<CustomCard title="Actions">
|
||||||
<div style={{ padding: "10px" }}>
|
<div
|
||||||
|
style={{
|
||||||
|
padding: "10px",
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: "column",
|
||||||
|
}}
|
||||||
|
>
|
||||||
<Button
|
<Button
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
color="default"
|
color="default"
|
||||||
startIcon={<EmailIcon />}
|
startIcon={<EmailIcon />}
|
||||||
style={{ width: "100%" }}
|
style={{
|
||||||
|
width: "100%",
|
||||||
|
}}
|
||||||
onClick={this.changeEmailAddress}
|
onClick={this.changeEmailAddress}
|
||||||
>
|
>
|
||||||
Change email address
|
Change email address
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
|
<div> </div>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="outlined"
|
||||||
|
color="default"
|
||||||
|
startIcon={<LinkIcon />}
|
||||||
|
style={{ width: "100%" }}
|
||||||
|
onClick={this.createPasswordResetLink}
|
||||||
|
>
|
||||||
|
Create password reset link
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</CustomCard>
|
</CustomCard>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
Loading…
Reference in New Issue
Block a user