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K,OAAO,aAAa,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAE7D,SAAS,SAAS,CAAC,SAAkB;YACnC,MAAM,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC;YACpE,MAAM,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QACtE,CAAC;QAED,IAAU,MAAM,CAWf;QAXD,WAAU,MAAM;YACd,IAAI,WAAmB,CAAC;YAExB,SAAgB,IAAI,CAAsC,OAAgC;gBACxF,OAAO,CAAC,WAAW,GAAG,WAAW,CAAC;gBAClC,OAAO,IAAI,EAAE,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACtD,CAAC;YAHe,WAAI,OAGnB,CAAA;YAED,SAAgB,cAAc,CAAC,WAAmB;gBAChD,WAAW,GAAG,WAAW,CAAC;YAC5B,CAAC;YAFe,qBAAc,iBAE7B,CAAA;QACH,CAAC,EAXS,MAAM,KAAN,MAAM,QAWf;IAGH,CAAC,EA5IgB,SAAS,GAAT,kBAAS,KAAT,kBAAS,QA4IzB;AAAD,CAAC,EA5IS,MAAM,KAAN,MAAM,QA4If","sourcesContent":["namespace Dialog.LoginTotp {\r\n\r\n export interface TotpChallengeResponse {\r\n /** The user's session id. */\r\n sessionGuid: string;\r\n /** Url to the LoginActions page */\r\n loginActionsUrl: string;\r\n /** Markup for the (localized) TOTP dialog */\r\n totpDialogHtml: string;\r\n /** Authorize result from SSO, requiring TOTP */\r\n ssoAuthResult: object;\r\n /** The password provided by the user that cleared the password check. */\r\n userProvidedPassword: string;\r\n }\r\n\r\n interface TotpForm {\r\n totp: string;\r\n }\r\n\r\n class RespondToTotpChallengeRequest extends G2.ClientSessionRequest {\r\n constructor(public form: TotpForm, public ssoAuthenticateResult: object) {\r\n super(\"RespondToTotpChallenge\");\r\n }\r\n }\r\n\r\n interface RespondToTotpChallengeResponse extends G2.ServerResponse {\r\n invalidProperties: G2.InvalidProperties;\r\n }\r\n\r\n class SendResetMfaEmailRequest extends G2.ClientSessionRequest {\r\n constructor(public ssoAuthenticateResult: object) {\r\n super(\"SendResetMfaEmail\");\r\n }\r\n }\r\n\r\n interface SendResetMfaEmailResponse extends G2.ServerResponse {\r\n resetMfaCodeKey: string;\r\n }\r\n\r\n class ResetMfaRequest extends G2.ClientSessionRequest {\r\n constructor(public ssoAuthenticateResult: object, public resetMfaCodeKey: string, public totpForm: TotpForm, public userProvidedPassword: string) {\r\n super(\"ResetMfa\");\r\n }\r\n }\r\n\r\n interface ResetMfaResponse extends G2.ServerResponse {\r\n invalidProperties: G2.InvalidProperties;\r\n }\r\n\r\n let Dialog: G2.BoundDialog;\r\n let TotpChallengeResponse: TotpChallengeResponse;\r\n\r\n /** The reset code emailed to the user. If null, the reset code has not yet been sent. */\r\n let ResetMfaCodeKey: string = null;\r\n\r\n function ResetCheckbox() { return Dialog.BoundForm.Container().find(\"#login-mfa-reset-checkbox\"); }\r\n\r\n export function Open(r: TotpChallengeResponse) {\r\n TotpChallengeResponse = r;\r\n Server.SetSessionGuid(r.sessionGuid);\r\n\r\n Dialog = new G2.BoundDialog($(r.totpDialogHtml), { wijmo: { hideTrigger: wijmo.input.PopupTrigger.None } });\r\n Dialog.Control().hiding.addHandler((_, e) => { e.cancel = true }); // prevent closing dialog\r\n Dialog.BoundForm.Container().find(\"button\").on(G2.EventMouse.Click, OkClick);\r\n Dialog.BoundForm.Tag(f => f.totp).on(\"input\", evt => {\r\n const totp = $(evt.target).val() as string;\r\n if (totp.length === 6) {\r\n OkClick();\r\n }\r\n });\r\n ShowReset(false);\r\n Dialog.Show();\r\n\r\n ResetCheckbox().on(G2.EventGeneric.Change, () => {\r\n if (!IsReset()) {\r\n ShowReset(false); // If checkbox cleared go back to MFA request form\r\n ResetMfaCodeKey = null; // And forget any code sent\r\n Dialog.BoundForm.SetProperties({totp: \"\"});\r\n }\r\n });\r\n }\r\n\r\n /** Handler for click of both the button to enter TOTP and that to enter a reset code. */\r\n function OkClick() { //NOSONAR\r\n if (IsReset()) {\r\n // We are processing an MFA reset\r\n if (ResetMfaCodeKey) {\r\n // We have sent the reset code via email\r\n if (Dialog.BoundForm.Validate()) {\r\n const totpForm = Dialog.BoundForm.GetProperties();\r\n Server.Post(new ResetMfaRequest(TotpChallengeResponse.ssoAuthResult, ResetMfaCodeKey, totpForm, TotpChallengeResponse.userProvidedPassword))\r\n .then(r => {\r\n if (Dialog.BoundForm.SetProperties(totpForm, r.invalidProperties)) {\r\n location.replace(TotpChallengeResponse.loginActionsUrl);\r\n }\r\n });\r\n }\r\n } else {\r\n // We need to send the reset code via email\r\n Server.Post(new SendResetMfaEmailRequest(TotpChallengeResponse.ssoAuthResult))\r\n .then(r => {\r\n ResetMfaCodeKey = r.resetMfaCodeKey;\r\n ShowReset(true);\r\n });\r\n }\r\n } else {\r\n // We are processing a TOTP\r\n if (Dialog.BoundForm.Validate()) { //NOSONAR\r\n const form = Dialog.BoundForm.GetProperties();\r\n Server.Post(new RespondToTotpChallengeRequest(form, TotpChallengeResponse.ssoAuthResult))\r\n .then(r => {\r\n if (Dialog.BoundForm.SetProperties(form, r.invalidProperties)) {\r\n location.replace(TotpChallengeResponse.loginActionsUrl);\r\n }\r\n });\r\n }\r\n }\r\n }\r\n\r\n function IsReset() { return ResetCheckbox().is(\":checked\"); }\r\n\r\n function ShowReset(showReset: boolean) {\r\n Dialog.BoundForm.Container().find(\"[data-totp]\").toggle(!showReset);\r\n Dialog.BoundForm.Container().find(\"[data-reset]\").toggle(showReset);\r\n }\r\n\r\n namespace Server {\r\n let SessionGuid: string;\r\n\r\n export function Post(request: G2.ClientSessionRequest): Promise {\r\n request.sessionGuid = SessionGuid;\r\n return new G2.Handler(\"LoginHandler\").Post(request);\r\n }\r\n\r\n export function SetSessionGuid(sessionGuid: string) {\r\n SessionGuid = sessionGuid;\r\n }\r\n } // namespace Server\r\n\r\n\r\n}"]}