diff --git a/src/helpers/ComunicUsersHelper.ts b/src/helpers/ComunicUsersHelper.ts index 757ffeb..81e32bf 100644 --- a/src/helpers/ComunicUsersHelper.ts +++ b/src/helpers/ComunicUsersHelper.ts @@ -71,4 +71,15 @@ export class ComunicUsersHelper { new_mail: newEmail, }); } + + /** + * Create a password reset link for a user + */ + static async CreatePasswordRecoveryLink(id: number): Promise { + return ( + await serverRequest("users/create_password_reset_link", { + user_id: id, + }) + ).url; + } } diff --git a/src/ui/routes/ComunicUserRoute.tsx b/src/ui/routes/ComunicUserRoute.tsx index d9846a0..42c557d 100644 --- a/src/ui/routes/ComunicUserRoute.tsx +++ b/src/ui/routes/ComunicUserRoute.tsx @@ -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< -
+
+ +
 
+ +