Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
05/18/2019 06:57:54 AM (6 years ago)
Author:
imath
Message:

BP Nouveau: use the same control than WP to set the user password

On the BuddyPress registration page and on the general settings user’s page, BP Nouveau is now using the same control WordPress is using to let users choose their password. By default it generates a strong password to make the user aware of the importance of its robustness. The user can still edit it and if the password is too weak, the submit button is disabled until the user activates the checkbox to force the use of a weak password.

Developers, please note the src/bp-templates/bp-nouveau/js/password-verify.js is now deprecated and will be deleted in version 6.0.0. If you were using the bp-nouveau-password-verify script handle as a dependency of your script(s), please stop doing so before the 6.0.0 release.

Fixes #8092

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-templates/bp-nouveau/includes/template-tags.php

    r12322 r12397  
    23102310
    23112311    foreach ( $fields as $name => $attributes ) {
    2312         list( $label, $required, $value, $attribute_type, $type, $class ) = array_values( $attributes );
    2313 
    2314         // Text fields are using strings, radios are using their inputs
    2315         $label_output = '<label for="%1$s">%2$s</label>';
    2316         $id           = $name;
    2317         $classes      = '';
    2318 
    2319         if ( $required ) {
    2320             /* translators: Do not translate placeholders. 2 = form field name, 3 = "(required)". */
    2321             $label_output = __( '<label for="%1$s">%2$s %3$s</label>', 'buddypress' );
    2322         }
    2323 
    2324         // Output the label for regular fields
    2325         if ( 'radio' !== $type ) {
     2312        if ( 'signup_password' === $name ) {
     2313            ?>
     2314            <label for="pass1"><?php esc_html_e( 'Choose a Password (required)', 'buddypress' ); ?></label>
     2315            <div class="user-pass1-wrap">
     2316                <div class="wp-pwd">
     2317                    <div class="password-input-wrapper">
     2318                        <input type="password" data-reveal="1" name="signup_password" id="pass1" class="password-entry" size="24" value="" <?php bp_form_field_attributes( 'password', array( 'data-pw' => wp_generate_password( 12 ), 'aria-describedby' => 'pass-strength-result' ) ); ?> />
     2319                        <button type="button" class="button wp-hide-pw">
     2320                            <span class="dashicons dashicons-hidden" aria-hidden="true"></span>
     2321                        </button>
     2322                    </div>
     2323                    <div id="pass-strength-result" aria-live="polite"><?php esc_html_e( 'Strength indicator', 'buddypress' ); ?></div>
     2324                </div>
     2325                <div class="pw-weak">
     2326                    <label>
     2327                        <input type="checkbox" name="pw_weak" class="pw-checkbox" />
     2328                        <?php esc_html_e( 'Confirm use of weak password', 'buddypress' ); ?>
     2329                    </label>
     2330                </div>
     2331            </div>
     2332            <?php
     2333        } elseif ( 'signup_password_confirm' === $name ) {
     2334            ?>
     2335            <p class="user-pass2-wrap">
     2336                <label for="pass2"><?php esc_html_e( 'Confirm new password', 'buddypress' ); ?></label><br />
     2337                <input type="password" name="signup_password_confirm" id="pass2" class="password-entry-confirm" size="24" value="" <?php bp_form_field_attributes( 'password' ); ?> />
     2338            </p>
     2339
     2340            <p class="description indicator-hint"><?php echo wp_get_password_hint(); ?></p>
     2341            <?php
     2342        } else {
     2343            list( $label, $required, $value, $attribute_type, $type, $class ) = array_values( $attributes );
     2344
     2345            // Text fields are using strings, radios are using their inputs
     2346            $label_output = '<label for="%1$s">%2$s</label>';
     2347            $id           = $name;
     2348            $classes      = '';
     2349
    23262350            if ( $required ) {
    2327                 printf( $label_output, esc_attr( $name ), esc_html( $label ), __( '(required)', 'buddypress' ) );
    2328             } else {
    2329                 printf( $label_output, esc_attr( $name ), esc_html( $label ) );
     2351                /* translators: Do not translate placeholders. 2 = form field name, 3 = "(required)". */
     2352                $label_output = __( '<label for="%1$s">%2$s %3$s</label>', 'buddypress' );
    23302353            }
    23312354
    2332             if ( ! empty( $value ) && is_callable( $value ) ) {
    2333                 $value = call_user_func( $value );
     2355            // Output the label for regular fields
     2356            if ( 'radio' !== $type ) {
     2357                if ( $required ) {
     2358                    printf( $label_output, esc_attr( $name ), esc_html( $label ), __( '(required)', 'buddypress' ) );
     2359                } else {
     2360                    printf( $label_output, esc_attr( $name ), esc_html( $label ) );
     2361                }
     2362
     2363                if ( ! empty( $value ) && is_callable( $value ) ) {
     2364                    $value = call_user_func( $value );
     2365                }
     2366
     2367            // Handle the specific case of Site's privacy differently
     2368            } elseif ( 'signup_blog_privacy_private' !== $name ) {
     2369                ?>
     2370                    <span class="label">
     2371                        <?php esc_html_e( 'I would like my site to appear in search engines, and in public listings around this network.', 'buddypress' ); ?>
     2372                    </span>
     2373                <?php
    23342374            }
    23352375
    2336         // Handle the specific case of Site's privacy differently
    2337         } elseif ( 'signup_blog_privacy_private' !== $name ) {
    2338             ?>
    2339                 <span class="label">
    2340                     <?php esc_html_e( 'I would like my site to appear in search engines, and in public listings around this network.', 'buddypress' ); ?>
    2341                 </span>
    2342             <?php
    2343         }
    2344 
    2345         // Set the additional attributes
    2346         if ( $attribute_type ) {
    2347             $existing_attributes = array();
    2348 
    2349             if ( ! empty( $required ) ) {
    2350                 $existing_attributes = array( 'aria-required' => 'true' );
     2376            // Set the additional attributes
     2377            if ( $attribute_type ) {
     2378                $existing_attributes = array();
     2379
     2380                if ( ! empty( $required ) ) {
     2381                    $existing_attributes = array( 'aria-required' => 'true' );
     2382
     2383                    /**
     2384                     * The blog section is hidden, so let's avoid a browser warning
     2385                     * and deal with the Blog section in Javascript.
     2386                     */
     2387                    if ( $section !== 'blog_details' ) {
     2388                        $existing_attributes['required'] = 'required';
     2389                    }
     2390                }
     2391
     2392                $attribute_type = ' ' . bp_get_form_field_attributes( $attribute_type, $existing_attributes );
     2393            }
     2394
     2395            // Specific case for Site's privacy
     2396            if ( 'signup_blog_privacy_public' === $name || 'signup_blog_privacy_private' === $name ) {
     2397                $name      = 'signup_blog_privacy';
     2398                $submitted = bp_get_signup_blog_privacy_value();
     2399
     2400                if ( ! $submitted ) {
     2401                    $submitted = 'public';
     2402                }
     2403
     2404                $attribute_type = ' ' . checked( $value, $submitted, false );
     2405            }
     2406
     2407            // Do not run function to display errors for the private radio.
     2408            if ( 'private' !== $value ) {
    23512409
    23522410                /**
    2353                  * The blog section is hidden, so let's avoid a browser warning
    2354                  * and deal with the Blog section in Javascript.
     2411                 * Fetch & display any BP member registration field errors.
     2412                 *
     2413                 * Passes BP signup errors to Nouveau's template function to
     2414                 * render suitable markup for error string.
    23552415                 */
    2356                 if ( $section !== 'blog_details' ) {
    2357                     $existing_attributes['required'] = 'required';
     2416                if ( isset( buddypress()->signup->errors[ $name ] ) ) {
     2417                    nouveau_error_template( buddypress()->signup->errors[ $name ] );
     2418                    $invalid = 'invalid';
    23582419                }
    23592420            }
    23602421
    2361             $attribute_type = ' ' . bp_get_form_field_attributes( $attribute_type, $existing_attributes );
    2362         }
    2363 
    2364         // Specific case for Site's privacy
    2365         if ( 'signup_blog_privacy_public' === $name || 'signup_blog_privacy_private' === $name ) {
    2366             $name      = 'signup_blog_privacy';
    2367             $submitted = bp_get_signup_blog_privacy_value();
    2368 
    2369             if ( ! $submitted ) {
    2370                 $submitted = 'public';
     2422            if ( isset( $invalid ) && isset( buddypress()->signup->errors[ $name ] ) ) {
     2423                if ( ! empty( $class ) ) {
     2424                    $class = $class . ' ' . $invalid;
     2425                } else {
     2426                    $class = $invalid;
     2427                }
    23712428            }
    23722429
    2373             $attribute_type = ' ' . checked( $value, $submitted, false );
    2374         }
    2375 
    2376         // Do not run function to display errors for the private radio.
    2377         if ( 'private' !== $value ) {
    2378 
    2379             /**
    2380              * Fetch & display any BP member registration field errors.
    2381              *
    2382              * Passes BP signup errors to Nouveau's template function to
    2383              * render suitable markup for error string.
    2384              */
    2385             if ( isset( buddypress()->signup->errors[ $name ] ) ) {
    2386                 nouveau_error_template( buddypress()->signup->errors[ $name ] );
    2387                 $invalid = 'invalid';
    2388             }
    2389         }
    2390 
    2391         if ( isset( $invalid ) && isset( buddypress()->signup->errors[ $name ] ) ) {
    2392             if ( ! empty( $class ) ) {
    2393                 $class = $class . ' ' . $invalid;
    2394             } else {
    2395                 $class = $invalid;
    2396             }
    2397         }
    2398 
    2399         if ( $class ) {
    2400             $class = sprintf(
    2401                 ' class="%s"',
    2402                 esc_attr( join( ' ', array_map( 'sanitize_html_class', explode( ' ', $class ) ) ) )
    2403             );
    2404         }
    2405 
    2406         // Set the input.
    2407         $field_output = sprintf(
    2408             '<input type="%1$s" name="%2$s" id="%3$s" %4$s value="%5$s" %6$s />',
    2409             esc_attr( $type ),
    2410             esc_attr( $name ),
    2411             esc_attr( $id ),
    2412             $class,  // Constructed safely above.
    2413             esc_attr( $value ),
    2414             $attribute_type // Constructed safely above.
    2415         );
    2416 
    2417         // Not a radio, let's output the field
    2418         if ( 'radio' !== $type ) {
    2419             if ( 'signup_blog_url' !== $name ) {
    2420                 print( $field_output );  // Constructed safely above.
    2421 
    2422             // If it's the signup blog url, it's specific to Multisite config.
    2423             } elseif ( is_subdomain_install() ) {
    2424                 // Constructed safely above.
    2425                 printf(
    2426                     '%1$s %2$s . %3$s',
    2427                     is_ssl() ? 'https://' : 'http://',
    2428                     $field_output,
    2429                     bp_signup_get_subdomain_base()
    2430                 );
    2431 
    2432             // Subfolders!
    2433             } else {
    2434                 printf(
    2435                     '%1$s %2$s',
    2436                     home_url( '/' ),
    2437                     $field_output  // Constructed safely above.
     2430            if ( $class ) {
     2431                $class = sprintf(
     2432                    ' class="%s"',
     2433                    esc_attr( join( ' ', array_map( 'sanitize_html_class', explode( ' ', $class ) ) ) )
    24382434                );
    24392435            }
    24402436
    2441         // It's a radio, let's output the field inside the label
    2442         } else {
    2443             // $label_output and $field_output are constructed safely above.
    2444             printf( $label_output, esc_attr( $name ), $field_output . ' ' . esc_html( $label ) );
    2445         }
    2446 
    2447         // Password strength is restricted to the signup_password field
    2448         if ( 'signup_password' === $name ) :
    2449         ?>
    2450             <div id="pass-strength-result"></div>
    2451         <?php
    2452         endif;
     2437            // Set the input.
     2438            $field_output = sprintf(
     2439                '<input type="%1$s" name="%2$s" id="%3$s" %4$s value="%5$s" %6$s />',
     2440                esc_attr( $type ),
     2441                esc_attr( $name ),
     2442                esc_attr( $id ),
     2443                $class,  // Constructed safely above.
     2444                esc_attr( $value ),
     2445                $attribute_type // Constructed safely above.
     2446            );
     2447
     2448            // Not a radio, let's output the field
     2449            if ( 'radio' !== $type ) {
     2450                if ( 'signup_blog_url' !== $name ) {
     2451                    print( $field_output );  // Constructed safely above.
     2452
     2453                // If it's the signup blog url, it's specific to Multisite config.
     2454                } elseif ( is_subdomain_install() ) {
     2455                    // Constructed safely above.
     2456                    printf(
     2457                        '%1$s %2$s . %3$s',
     2458                        is_ssl() ? 'https://' : 'http://',
     2459                        $field_output,
     2460                        bp_signup_get_subdomain_base()
     2461                    );
     2462
     2463                // Subfolders!
     2464                } else {
     2465                    printf(
     2466                        '%1$s %2$s',
     2467                        home_url( '/' ),
     2468                        $field_output  // Constructed safely above.
     2469                    );
     2470                }
     2471
     2472            // It's a radio, let's output the field inside the label
     2473            } else {
     2474                // $label_output and $field_output are constructed safely above.
     2475                printf( $label_output, esc_attr( $name ), $field_output . ' ' . esc_html( $label ) );
     2476            }
     2477        }
    24532478    }
    24542479
Note: See TracChangeset for help on using the changeset viewer.