Skip to content

Commit fc4567e

Browse files
authored
feat(reader-registration-block): password, OTP, and verification flows (#4452)
1 parent 1188958 commit fc4567e

17 files changed

Lines changed: 548 additions & 255 deletions

File tree

includes/class-magic-link.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,8 +861,12 @@ public static function process_otp_request() {
861861
if ( ! Reader_Activation::is_enabled() ) {
862862
return;
863863
}
864+
// Allow logged-in unverified readers to verify via OTP.
864865
if ( \is_user_logged_in() ) {
865-
return;
866+
$current_user = \wp_get_current_user();
867+
if ( ! Reader_Activation::is_user_reader( $current_user ) || Reader_Activation::is_reader_verified( $current_user ) ) {
868+
return;
869+
}
866870
}
867871

868872
// phpcs:disable WordPress.Security.NonceVerification.Missing
@@ -923,6 +927,7 @@ public static function process_otp_request() {
923927
'email' => $email,
924928
'existing_user' => true,
925929
'metadata' => $metadata,
930+
'verified' => Reader_Activation::is_reader_verified( $user ),
926931
];
927932

928933
return self::send_otp_request_response( __( 'Login successful!', 'newspack-plugin' ), true, $data );

includes/class-newspack-ui-icons.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ public static function sanitize_svgs() {
150150
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" aria-hidden="true" focusable="false" class="newspack-ui__svg-icon--key">
151151
<path d="M10.4984 9.5C10.4984 7.29063 12.289 5.5 14.4984 5.5C16.7078 5.5 18.4984 7.29063 18.4984 9.5C18.4984 11.7094 16.7078 13.5 14.4984 13.5C14.1734 13.5 13.8578 13.4625 13.5578 13.3875C13.3047 13.325 13.0359 13.4 12.8515 13.5875L11.939 14.5H10.2484C9.83279 14.5 9.49841 14.8344 9.49841 15.25V16.5H8.24841C7.83279 16.5 7.49841 16.8344 7.49841 17.25V18.5H5.49841V16.0594L10.4109 11.1469C10.5953 10.9625 10.6703 10.6938 10.6109 10.4406C10.539 10.1406 10.4984 9.825 10.4984 9.5ZM14.4984 4C11.4609 4 8.99841 6.4625 8.99841 9.5C8.99841 9.79688 9.02029 10.0875 9.06716 10.3719L4.21716 15.2188C4.07654 15.3594 3.99841 15.55 3.99841 15.75V19.25C3.99841 19.6656 4.33279 20 4.74841 20H8.24841C8.66404 20 8.99841 19.6656 8.99841 19.25V18H10.2484C10.664 18 10.9984 17.6656 10.9984 17.25V16H12.2484C12.4484 16 12.639 15.9219 12.7797 15.7812L13.6297 14.9312C13.914 14.975 14.2047 15 14.5015 15C17.539 15 20.0015 12.5375 20.0015 9.5C20.0015 6.4625 17.5359 4 14.4984 4ZM15.4984 9.5C15.7636 9.5 16.018 9.39464 16.2055 9.20711C16.3931 9.01957 16.4984 8.76522 16.4984 8.5C16.4984 8.23478 16.3931 7.98043 16.2055 7.79289C16.018 7.60536 15.7636 7.5 15.4984 7.5C15.2332 7.5 14.9788 7.60536 14.7913 7.79289C14.6038 7.98043 14.4984 8.23478 14.4984 8.5C14.4984 8.76522 14.6038 9.01957 14.7913 9.20711C14.9788 9.39464 15.2332 9.5 15.4984 9.5Z" />
152152
</svg>',
153+
'login' =>
154+
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" aria-hidden="true" focusable="false" class="newspack-ui__svg-icon--login">
155+
<path d="M11 14.5l1.1 1.1 3-3 .5-.5-.6-.6-3-3-1 1 1.7 1.7H5v1.5h7.7L11 14.5zM16.8 5h-7c-1.1 0-2 .9-2 2v1.5h1.5V7c0-.3.2-.5.5-.5h7c.3 0 .5.2.5.5v10c0 .3-.2.5-.5.5h-7c-.3 0-.5-.2-.5-.5v-1.5H7.8V17c0 1.1.9 2 2 2h7c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2z" />
156+
</svg>',
153157
'logout' =>
154158
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" aria-hidden="true" focusable="false" class="newspack-ui__svg-icon--logout">
155159
<path d="M19.03 8.47L22.56 12L19.03 15.53L17.97 14.47L19.69 12.75H8.5V11.25H19.69L17.97 9.53L19.03 8.47ZM13.5 17C13.5 17.1326 13.4473 17.2598 13.3536 17.3536C13.2598 17.4473 13.1326 17.5 13 17.5H6C5.86739 17.5 5.74021 17.4473 5.64645 17.3536C5.55268 17.2598 5.5 17.1326 5.5 17V7C5.5 6.86739 5.55268 6.74021 5.64645 6.64645C5.74021 6.55268 5.86739 6.5 6 6.5H13C13.1326 6.5 13.2598 6.55268 13.3536 6.64645C13.4473 6.74021 13.5 6.86739 13.5 7V8.5H15V7C15 6.46957 14.7893 5.96086 14.4142 5.58579C14.0391 5.21071 13.5304 5 13 5H6C5.46957 5 4.96086 5.21071 4.58579 5.58579C4.21071 5.96086 4 6.46957 4 7V17C4 17.5304 4.21071 18.0391 4.58579 18.4142C4.96086 18.7893 5.46957 19 6 19H13C13.5304 19 14.0391 18.7893 14.4142 18.4142C14.7893 18.0391 15 17.5304 15 17V15.5H13.5V17Z" />

includes/content-gate/class-content-gate.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -719,22 +719,6 @@ public static function handle_edit_gate_layout() {
719719
}
720720
}
721721

722-
/**
723-
* Get the inline gate content.
724-
*/
725-
public static function get_inline_gate_content() {
726-
return self::get_inline_gate_content_for_post( self::get_gate_layout_id() );
727-
}
728-
729-
/**
730-
* Get the inline gate HTML for rendering.
731-
*
732-
* @return string
733-
*/
734-
public static function get_inline_gate_html() {
735-
return apply_filters( 'newspack_gate_content', self::get_inline_gate_content() );
736-
}
737-
738722
/**
739723
* Get the post excerpt to be displayed in the gate.
740724
*
@@ -859,6 +843,9 @@ public static function get_registration_settings( $gate_id ) {
859843
public static function requires_account_verification( $gate_id = null ) {
860844
if ( ! $gate_id ) {
861845
$gate_id = self::get_gate_post_id();
846+
if ( ! $gate_id ) {
847+
return false;
848+
}
862849
}
863850
$registration = self::get_registration_settings( $gate_id );
864851
return $registration['require_verification'];

includes/content-gate/trait-content-gate-layout.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,22 @@ public static function get_restricted_post_excerpt_for_gate( $post, $gate_layout
280280
return $content;
281281
}
282282

283+
/**
284+
* Get the inline gate content.
285+
*/
286+
public static function get_inline_gate_content() {
287+
return self::get_inline_gate_content_for_post( self::get_gate_layout_id() );
288+
}
289+
290+
/**
291+
* Get the inline gate HTML for rendering.
292+
*
293+
* @return string
294+
*/
295+
public static function get_inline_gate_html() {
296+
return apply_filters( 'newspack_gate_content', self::get_inline_gate_content() );
297+
}
298+
283299
/**
284300
* Render the overlay gate HTML.
285301
*

includes/oauth/class-google-login.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,9 @@ public static function api_google_login_register( $request ) {
315315
return $result;
316316
}
317317

318+
$current_user = \wp_get_current_user();
318319
$data['metadata'] = $metadata;
320+
$data['verified'] = $current_user ? Reader_Activation::is_reader_verified( $current_user ) : false;
319321
return \rest_ensure_response(
320322
[
321323
'data' => $data,

includes/reader-activation/class-reader-activation.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ private static function get_reader_activation_labels( $key = null ) {
286286
'continue' => __( 'Continue', 'newspack-plugin' ),
287287
'resend_code' => __( 'Resend code', 'newspack-plugin' ),
288288
'otp' => __( 'Email me a one-time code instead', 'newspack-plugin' ),
289-
'otp_title' => __( 'Enter the code sent to your email.', 'newspack-plugin' ),
289+
'otp_title' => __( 'Enter the code sent to your email', 'newspack-plugin' ),
290290
'forgot_password' => __( 'Forgot password', 'newspack-plugin' ),
291291
'create_account' => __( 'Create an account', 'newspack-plugin' ),
292292
'register' => __( 'Sign in to an existing account', 'newspack-plugin' ),
@@ -1954,7 +1954,7 @@ public static function render_third_party_auth() {
19541954
<div class="newspack-ui">
19551955
<button type="button" class="newspack-ui__button newspack-ui__button--wide newspack-ui__button--secondary newspack-ui__button--google-oauth">
19561956
<?php Newspack_UI_Icons::print_svg( 'google' ); ?>
1957-
<?php echo \esc_html__( 'Sign in with Google', 'newspack-plugin' ); ?>
1957+
<?php echo \esc_html__( 'Continue with Google', 'newspack-plugin' ); ?>
19581958
</button>
19591959
<div class="newspack-ui__word-divider">
19601960
<?php echo \esc_html__( 'Or', 'newspack-plugin' ); ?>
@@ -2092,6 +2092,9 @@ public static function process_auth_form() {
20922092
$authenticated = self::set_current_reader( $user->ID );
20932093
$payload['authenticated'] = \is_wp_error( $authenticated ) ? 0 : 1;
20942094
$payload['existing_user'] = \is_wp_error( $authenticated ) ? 0 : 1;
2095+
if ( ! \is_wp_error( $authenticated ) ) {
2096+
$payload['verified'] = self::is_reader_verified( $user );
2097+
}
20952098
$metadata['login_method'] = 'auth-form-password';
20962099
break;
20972100
case 'link':

src/blocks/reader-registration/block.json

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
"label": {
2121
"type": "string",
22-
"default": "Sign up",
22+
"default": "Continue",
2323
"required": true
2424
},
2525
"privacyLabel": {
@@ -52,14 +52,6 @@
5252
"listsCheckboxes": {
5353
"type": "object",
5454
"default": {}
55-
},
56-
"signInLabel": {
57-
"type": "string",
58-
"default": "Sign in to an existing account"
59-
},
60-
"signedInLabel": {
61-
"type": "string",
62-
"default": "An account was already registered with this email. Please check your inbox for an authentication link."
6355
}
6456
},
6557
"supports": {

src/blocks/reader-registration/edit.js

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { Icon, check } from '@wordpress/icons';
1919
* Internal dependencies
2020
*/
2121
import './editor.scss';
22-
import { emailSend } from '../../../packages/icons';
2322

2423
const getListCheckboxId = listId => {
2524
return 'newspack-reader-registration-list-checkbox-' + listId;
@@ -28,7 +27,6 @@ const getListCheckboxId = listId => {
2827
const editedStateOptions = [
2928
{ label: __( 'Initial', 'newspack-plugin' ), value: 'initial' },
3029
{ label: __( 'Registration Success', 'newspack-plugin' ), value: 'registration' },
31-
{ label: __( 'Login Success', 'newspack-plugin' ), value: 'login' },
3230
];
3331
export default function ReaderRegistrationEdit( {
3432
setAttributes,
@@ -42,8 +40,6 @@ export default function ReaderRegistrationEdit( {
4240
displayListDescription,
4341
hideSubscriptionInput,
4442
newsletterLabel,
45-
signInLabel,
46-
signedInLabel,
4743
lists,
4844
listsCheckboxes,
4945
},
@@ -292,7 +288,7 @@ export default function ReaderRegistrationEdit( {
292288
__html: newspack_blocks.google_logo_svg,
293289
} }
294290
/>
295-
{ __( 'Sign in with Google', 'newspack-plugin' ) }
291+
{ __( 'Continue with Google', 'newspack-plugin' ) }
296292
</button>
297293
<div className="newspack-ui__word-divider">{ __( 'Or', 'newspack-plugin' ) }</div>
298294
</div>
@@ -303,7 +299,7 @@ export default function ReaderRegistrationEdit( {
303299
<button type="submit" className="newspack-ui__button newspack-ui__button--primary">
304300
<RichText
305301
onChange={ value => setAttributes( { label: value } ) }
306-
placeholder={ __( 'Sign up', 'newspack-plugin' ) }
302+
placeholder={ __( 'Continue', 'newspack-plugin' ) }
307303
value={ label }
308304
allowedFormats={ [] }
309305
tagName="span"
@@ -314,21 +310,6 @@ export default function ReaderRegistrationEdit( {
314310
</div>
315311
</div>
316312
</div>
317-
<div className="newspack-registration__have-account">
318-
<a
319-
href="/my-account"
320-
onClick={ ev => ev.preventDefault() }
321-
className="newspack-ui__button newspack-ui__button--ghost"
322-
>
323-
<RichText
324-
onChange={ value => setAttributes( { signInLabel: value } ) }
325-
placeholder={ __( 'Sign in to an existing account', 'newspack-plugin' ) }
326-
value={ signInLabel }
327-
allowedFormats={ [] }
328-
tagName="span"
329-
/>
330-
</a>
331-
</div>
332313
<div className="newspack-registration__help-text">
333314
<RichText
334315
onChange={ value => setAttributes( { privacyLabel: value } ) }
@@ -343,31 +324,14 @@ export default function ReaderRegistrationEdit( {
343324
) }
344325
{ editedState === 'registration' && (
345326
<div className="newspack-registration newspack-ui">
346-
<div className="newspack-ui__box newspack-ui__box--success newspack-ui__box--text-center">
327+
<div className="newspack-ui__box newspack-ui__box--success newspack-ui__box--x-large newspack-ui__box--text-center">
347328
<span className="newspack-ui__icon newspack-ui__icon--success">
348329
<Icon icon={ check } />
349330
</span>
350331
<div { ...innerBlocksProps } />
351332
</div>
352333
</div>
353334
) }
354-
{ editedState === 'login' && (
355-
<div className="newspack-registration newspack-ui">
356-
<div className="newspack-ui__box newspack-ui__box--success newspack-ui__box--text-center">
357-
<span className="newspack-ui__icon newspack-ui__icon--success">
358-
<Icon icon={ emailSend } />
359-
</span>
360-
<RichText
361-
align="center"
362-
onChange={ value => setAttributes( { signedInLabel: value } ) }
363-
placeholder={ __( 'Logged in message…', 'newspack-plugin' ) }
364-
value={ signedInLabel }
365-
allowedFormats={ [] }
366-
tagName="p"
367-
/>
368-
</div>
369-
</div>
370-
) }
371335
</div>
372336
</>
373337
);

0 commit comments

Comments
 (0)