-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prompt for revalidation of 2FA details before changing 2FA details. (#…
…147) * Switch to using an Iframe for the revalidation. * Speed up the UI by assuming the 2FA is successful while the user record is async refresed. * Use single modal flow to match design * Style modal and iframe contents from login page * Display the account status screen behind the modal --------- Co-authored-by: Adam Wood <[email protected]>
- Loading branch information
1 parent
12a8458
commit a1fa9e5
Showing
6 changed files
with
230 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useContext, useEffect, useRef } from '@wordpress/element'; | ||
import { GlobalContext } from '../script'; | ||
import { Modal } from '@wordpress/components'; | ||
import { useMergeRefs, useFocusableIframe } from '@wordpress/compose'; | ||
import { refreshRecord } from '../utilities'; | ||
|
||
export default function RevalidateModal() { | ||
const { clickScreenLink } = useContext( GlobalContext ); | ||
|
||
const goBack = ( event ) => clickScreenLink( event, 'account-status' ); | ||
|
||
return ( | ||
<Modal | ||
title="Two-Factor Authentication" | ||
onRequestClose={ goBack } | ||
className="wporg-2fa__revalidate-modal" | ||
> | ||
<p>To update your two-factor options, you must first revalidate your session.</p> | ||
|
||
<RevalidateIframe /> | ||
</Modal> | ||
); | ||
} | ||
|
||
function RevalidateIframe() { | ||
const { setGlobalNotice, userRecord } = useContext( GlobalContext ); | ||
const ref = useRef(); | ||
|
||
useEffect( () => { | ||
function maybeRefreshUser( { data: { type, message } = {} } ) { | ||
if ( type !== 'reValidationComplete' ) { | ||
return; | ||
} | ||
|
||
setGlobalNotice( message || 'Two-Factor confirmed' ); | ||
|
||
// Pretend that the expires_at is in the future (+1hr), this provides a 'faster' UI. | ||
// This intentionally doesn't use `edit()` to prevent it attempting to update it on the server. | ||
userRecord.record[ '2fa_revalidation' ].expires_at = new Date().getTime() / 1000 + 3600; | ||
|
||
// Refresh the user record, to fetch the correct 2fa_revalidation data. | ||
refreshRecord( userRecord ); | ||
} | ||
|
||
window.addEventListener( 'message', maybeRefreshUser ); | ||
|
||
return () => { | ||
window.removeEventListener( 'message', maybeRefreshUser ); | ||
}; | ||
}, [] ); | ||
|
||
return ( | ||
<iframe | ||
title="Two-Factor Revalidation" | ||
ref={ useMergeRefs( [ ref, useFocusableIframe() ] ) } | ||
src={ userRecord.record[ '2fa_revalidation' ].revalidate_url } | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
.wporg-2fa__revalidate-modal { | ||
$header-height: 100px; | ||
|
||
&.components-modal__frame { | ||
border-radius: 8px; | ||
} | ||
|
||
.components-modal__header { | ||
height: $header-height; | ||
|
||
h1 { | ||
margin: unset; | ||
} | ||
} | ||
|
||
.components-modal__content { | ||
margin-top: $header-height; | ||
padding: 0; | ||
} | ||
|
||
p { | ||
margin: 0 32px 1rem; | ||
// Match style of login page text in iframe | ||
font-size: 14px; | ||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; | ||
} | ||
|
||
iframe { | ||
border: none; | ||
width: 100%; | ||
// Allow for error messages above form | ||
height: 330px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters