Ticket #20279: 20279.2.diff
| File 20279.2.diff, 7.7 KB (added by , 13 years ago) |
|---|
-
src/wp-includes/user.php
1550 1550 } 1551 1551 return apply_filters( 'user_contactmethods', $user_contactmethods, $user ); 1552 1552 } 1553 1554 /** 1555 * Retrieves a user row based on password reset key and login 1556 * 1557 * @uses $wpdb WordPress Database object 1558 * 1559 * @param string $key Hash to validate sending user's password 1560 * @param string $login The user login 1561 * @return object|WP_Error User's database row on success, error object for invalid keys 1562 */ 1563 function check_password_reset_key( $key, $login ) { 1564 global $wpdb; 1565 1566 $key = preg_replace( '/[^a-z0-9]/i', '', $key ); 1567 1568 if ( empty( $key ) || ! is_string( $key ) ) 1569 return new WP_Error( 'invalid_key', __( 'Invalid key' ) ); 1570 1571 if ( empty( $login ) || ! is_string( $login ) ) 1572 return new WP_Error( 'invalid_key', __( 'Invalid key' ) ); 1573 1574 $user = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->users WHERE user_activation_key = %s AND user_login = %s", $key, $login ) ); 1575 1576 if ( empty( $user ) ) 1577 return new WP_Error( 'invalid_key', __( 'Invalid key' ) ); 1578 1579 return $user; 1580 } 1581 1582 /** 1583 * Handles resetting the user's password. 1584 * 1585 * @param object $user The user 1586 * @param string $new_pass New password for the user in plaintext 1587 */ 1588 function reset_password( $user, $new_pass ) { 1589 do_action( 'password_reset', $user, $new_pass ); 1590 1591 wp_set_password( $new_pass, $user->ID ); 1592 1593 wp_password_change_notification( $user ); 1594 } 1595 1596 /** 1597 * Handles registering a new user. 1598 * 1599 * @param string $user_login User's username for logging in 1600 * @param string $user_email User's email address to send password and add 1601 * @return int|WP_Error Either user's ID or error on failure. 1602 */ 1603 function register_new_user( $user_login, $user_email ) { 1604 $errors = new WP_Error(); 1605 1606 $sanitized_user_login = sanitize_user( $user_login ); 1607 $user_email = apply_filters( 'user_registration_email', $user_email ); 1608 1609 // Check the username 1610 if ( $sanitized_user_login == '' ) { 1611 $errors->add( 'empty_username', __( '<strong>ERROR</strong>: Please enter a username.' ) ); 1612 } elseif ( ! validate_username( $user_login ) ) { 1613 $errors->add( 'invalid_username', __( '<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.' ) ); 1614 $sanitized_user_login = ''; 1615 } elseif ( username_exists( $sanitized_user_login ) ) { 1616 $errors->add( 'username_exists', __( '<strong>ERROR</strong>: This username is already registered. Please choose another one.' ) ); 1617 } 1618 1619 // Check the e-mail address 1620 if ( $user_email == '' ) { 1621 $errors->add( 'empty_email', __( '<strong>ERROR</strong>: Please type your e-mail address.' ) ); 1622 } elseif ( ! is_email( $user_email ) ) { 1623 $errors->add( 'invalid_email', __( '<strong>ERROR</strong>: The email address isn’t correct.' ) ); 1624 $user_email = ''; 1625 } elseif ( email_exists( $user_email ) ) { 1626 $errors->add( 'email_exists', __( '<strong>ERROR</strong>: This email is already registered, please choose another one.' ) ); 1627 } 1628 1629 do_action( 'register_post', $sanitized_user_login, $user_email, $errors ); 1630 1631 $errors = apply_filters( 'registration_errors', $errors, $sanitized_user_login, $user_email ); 1632 1633 if ( $errors->get_error_code() ) 1634 return $errors; 1635 1636 $user_pass = wp_generate_password( 12, false ); 1637 $user_id = wp_create_user( $sanitized_user_login, $user_pass, $user_email ); 1638 if ( ! $user_id || is_wp_error( $user_id ) ) { 1639 $errors->add( 'registerfail', sprintf( __( '<strong>ERROR</strong>: Couldn’t register you… please contact the <a href="mailto:%s">webmaster</a> !' ), get_option( 'admin_email' ) ) ); 1640 return $errors; 1641 } 1642 1643 update_user_option( $user_id, 'default_password_nag', true, true ); //Set up the Password change nag. 1644 1645 wp_new_user_notification( $user_id, $user_pass ); 1646 1647 return $user_id; 1648 } -
src/wp-login.php
269 269 return true; 270 270 } 271 271 272 /**273 * Retrieves a user row based on password reset key and login274 *275 * @uses $wpdb WordPress Database object276 *277 * @param string $key Hash to validate sending user's password278 * @param string $login The user login279 * @return object|WP_Error User's database row on success, error object for invalid keys280 */281 function check_password_reset_key($key, $login) {282 global $wpdb;283 284 $key = preg_replace('/[^a-z0-9]/i', '', $key);285 286 if ( empty( $key ) || !is_string( $key ) )287 return new WP_Error('invalid_key', __('Invalid key'));288 289 if ( empty($login) || !is_string($login) )290 return new WP_Error('invalid_key', __('Invalid key'));291 292 $user = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->users WHERE user_activation_key = %s AND user_login = %s", $key, $login));293 294 if ( empty( $user ) )295 return new WP_Error('invalid_key', __('Invalid key'));296 297 return $user;298 }299 300 /**301 * Handles resetting the user's password.302 *303 * @param object $user The user304 * @param string $new_pass New password for the user in plaintext305 */306 function reset_password($user, $new_pass) {307 do_action('password_reset', $user, $new_pass);308 309 wp_set_password($new_pass, $user->ID);310 311 wp_password_change_notification($user);312 }313 314 /**315 * Handles registering a new user.316 *317 * @param string $user_login User's username for logging in318 * @param string $user_email User's email address to send password and add319 * @return int|WP_Error Either user's ID or error on failure.320 */321 function register_new_user( $user_login, $user_email ) {322 $errors = new WP_Error();323 324 $sanitized_user_login = sanitize_user( $user_login );325 $user_email = apply_filters( 'user_registration_email', $user_email );326 327 // Check the username328 if ( $sanitized_user_login == '' ) {329 $errors->add( 'empty_username', __( '<strong>ERROR</strong>: Please enter a username.' ) );330 } elseif ( ! validate_username( $user_login ) ) {331 $errors->add( 'invalid_username', __( '<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.' ) );332 $sanitized_user_login = '';333 } elseif ( username_exists( $sanitized_user_login ) ) {334 $errors->add( 'username_exists', __( '<strong>ERROR</strong>: This username is already registered. Please choose another one.' ) );335 }336 337 // Check the e-mail address338 if ( $user_email == '' ) {339 $errors->add( 'empty_email', __( '<strong>ERROR</strong>: Please type your e-mail address.' ) );340 } elseif ( ! is_email( $user_email ) ) {341 $errors->add( 'invalid_email', __( '<strong>ERROR</strong>: The email address isn’t correct.' ) );342 $user_email = '';343 } elseif ( email_exists( $user_email ) ) {344 $errors->add( 'email_exists', __( '<strong>ERROR</strong>: This email is already registered, please choose another one.' ) );345 }346 347 do_action( 'register_post', $sanitized_user_login, $user_email, $errors );348 349 $errors = apply_filters( 'registration_errors', $errors, $sanitized_user_login, $user_email );350 351 if ( $errors->get_error_code() )352 return $errors;353 354 $user_pass = wp_generate_password( 12, false);355 $user_id = wp_create_user( $sanitized_user_login, $user_pass, $user_email );356 if ( ! $user_id || is_wp_error( $user_id ) ) {357 $errors->add( 'registerfail', sprintf( __( '<strong>ERROR</strong>: Couldn’t register you… please contact the <a href="mailto:%s">webmaster</a> !' ), get_option( 'admin_email' ) ) );358 return $errors;359 }360 361 update_user_option( $user_id, 'default_password_nag', true, true ); //Set up the Password change nag.362 363 wp_new_user_notification( $user_id, $user_pass );364 365 return $user_id;366 }367 368 272 // 369 273 // Main 370 274 //
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)