-
Notifications
You must be signed in to change notification settings - Fork 805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Account Protection: Add password detection flow #41105
base: add/protect/account-protection-settings
Are you sure you want to change the base?
Account Protection: Add password detection flow #41105
Conversation
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available. 🔴 Action required: Please add missing changelog entries for the following projects: Use the Jetpack CLI tool to generate changelog entries by running the following command: Follow this PR Review Process:
Still unsure? Reach out in #jetpack-developers for guidance! Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. Protect plugin:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
@@ -0,0 +1,21 @@ | |||
<svg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that was probably supposed to be a .svg file? 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good eye!
$email_sent = Password_Reset_Email::send( $current_user ); | ||
if ( $email_sent ) { | ||
// Set transient to mark the email as sent | ||
set_transient( $transient_key, true, 15 * MINUTE_IN_SECONDS ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if a user will have to wait 15 minutes before re-sending it, if thats what we're using the transient for. I have seen things like 1 minute or maybe 2 before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this transient because we want to trigger an email when initially visiting the variant of the page that renders when we detect $_POST['reset']
(which is defined by submitting the Create new password
button in the initial state of the page) and not on browser refresh. I made it a lengthier period to avoid easily duplicating the process, but if you think a shorter duration is more appropriate I am happy to reconsider.
Also note that if within that timeframe the user does not receive the email, they can resend the email using the AJAX request facilitated around the Resend email
button (which does not respect the transient but does have its own internal resend limitations).
/** | ||
* Run AJAX request to resend password reset email. | ||
*/ | ||
public static function ajax_resend_password_reset_email() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this have to be an AJAX request? and if so, why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an AJAX action for the Resend button
only, perhaps it can be done in a different way but this approach allowed for a more dynamic handling of the outcome:
Note that the flow is modified in the above screen capture to demo the functionality.
Open to alternative suggestions if you have any that could attain a similar outcome.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to make sense. I'm just always wary with adding the whole complexity that an AJAX request brings when it could just be a normal request refreshing the site. And it sure could, but I can see how this can feel better from the user perspective.
* @param string $error The error message to display. | ||
* @param string $masked_email The masked email address. | ||
*/ | ||
public static function render_password_detection_template( $reset, $context, $error, $masked_email ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a gut feeling, but this method echo
s so much HTML, that I think it might be wise to end PHP and start it again, only for the dynamic parts? Not sure if you tried that before and it actually looked worse, though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was specifically interested in your opinion on this approach. I took the template approach initially with /templates/password-detection-template.php
(opening and closing PHP accordingly) and then used an include in the main render_password_detection_page
method, however, because the variables are defined in the method, and used in the template, the linter kept erroring out - no matter how attempted to approach it another issue surfaced (despite it actually working).
I opted for using the method here which resolved those errors but attempting to supply the HTML in the same fashion caused nothing to render. If this is your recommendation I'll attempt it again, but I am mostly curious about your take on the template approach as it seemed a lot cleaner/better organized - if you agree, and I can't figure out a solution to resolve the lint errors do you think it's safe to disable the lines?
UPDATE: Don't know what I doing wrong before but updated the method to open and close PHP instead of echoing all the HTML out, works fine - regardless, still interested in you opinion on the template use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The one advantage of ending/starting PHP is that (most) IDEs will properly display HTML syntax and stuff, but (most) not when it is in PHP strings as here.
Fixes #
Proposed changes:
Other information:
Jetpack product discussion
Does this pull request change what data or activity we track or use?
Testing instructions: