From b6e59c10619560b18f74a742f18f19330345cde7 Mon Sep 17 00:00:00 2001
From: david
- add('error', $error);
- unset($error);
- }
-
- if ( $wp_error->get_error_code() ) {
- $errors = '';
- $messages = '';
- foreach ( $wp_error->get_error_codes() as $code ) {
- $severity = $wp_error->get_error_data($code);
- foreach ( $wp_error->get_error_messages($code) as $error ) {
- if ( 'message' == $severity )
- $messages .= ' ' . $error . "
\n";
- else
- $errors .= ' ' . $error . "
\n";
- }
- }
- if ( !empty($errors) )
- echo '
\n" . __('Possible reason: your host may have disabled the mail() function...') );
-
- return true;
-}
-
-/**
- * Retrieves a user row based on password reset key and login
- *
- * @uses $wpdb WordPress Database object
- *
- * @param string $key Hash to validate sending user's password
- * @param string $login The user login
- * @return object|WP_Error User's database row on success, error object for invalid keys
- */
-function check_password_reset_key($key, $login) {
- global $wpdb;
-
- $key = preg_replace('/[^a-z0-9]/i', '', $key);
-
- if ( empty( $key ) || !is_string( $key ) )
- return new WP_Error('invalid_key', __('Invalid key'));
-
- if ( empty($login) || !is_string($login) )
- return new WP_Error('invalid_key', __('Invalid key'));
-
- $user = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->users WHERE user_activation_key = %s AND user_login = %s", $key, $login));
-
- if ( empty( $user ) )
- return new WP_Error('invalid_key', __('Invalid key'));
-
- return $user;
-}
-
-/**
- * Handles resetting the user's password.
- *
- * @param object $user The user
- * @param string $new_pass New password for the user in plaintext
- */
-function reset_password($user, $new_pass) {
- do_action('password_reset', $user, $new_pass);
-
- wp_set_password($new_pass, $user->ID);
-
- wp_password_change_notification($user);
-}
-
-/**
- * Handles registering a new user.
- *
- * @param string $user_login User's username for logging in
- * @param string $user_email User's email address to send password and add
- * @return int|WP_Error Either user's ID or error on failure.
- */
-function register_new_user( $user_login, $user_email ) {
- $errors = new WP_Error();
-
- $sanitized_user_login = sanitize_user( $user_login );
- $user_email = apply_filters( 'user_registration_email', $user_email );
-
- // Check the username
- if ( $sanitized_user_login == '' ) {
- $errors->add( 'empty_username', __( 'ERROR: Please enter a username.' ) );
- } elseif ( ! validate_username( $user_login ) ) {
- $errors->add( 'invalid_username', __( 'ERROR: This username is invalid because it uses illegal characters. Please enter a valid username.' ) );
- $sanitized_user_login = '';
- } elseif ( username_exists( $sanitized_user_login ) ) {
- $errors->add( 'username_exists', __( 'ERROR: This username is already registered, please choose another one.' ) );
- }
-
- // Check the e-mail address
- if ( $user_email == '' ) {
- $errors->add( 'empty_email', __( 'ERROR: Please type your e-mail address.' ) );
- } elseif ( ! is_email( $user_email ) ) {
- $errors->add( 'invalid_email', __( 'ERROR: The email address isn’t correct.' ) );
- $user_email = '';
- } elseif ( email_exists( $user_email ) ) {
- $errors->add( 'email_exists', __( 'ERROR: This email is already registered, please choose another one.' ) );
- }
-
- do_action( 'register_post', $sanitized_user_login, $user_email, $errors );
-
- $errors = apply_filters( 'registration_errors', $errors, $sanitized_user_login, $user_email );
-
- if ( $errors->get_error_code() )
- return $errors;
-
- $user_pass = wp_generate_password( 12, false);
- $user_id = wp_create_user( $sanitized_user_login, $user_pass, $user_email );
- if ( ! $user_id ) {
- $errors->add( 'registerfail', sprintf( __( 'ERROR: Couldn’t register you... please contact the webmaster !' ), get_option( 'admin_email' ) ) );
- return $errors;
- }
-
- update_user_option( $user_id, 'default_password_nag', true, true ); //Set up the Password change nag.
-
- wp_new_user_notification( $user_id, $user_pass );
-
- return $user_id;
-}
-
-//
-// Main
-//
-
-$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'login';
-$errors = new WP_Error();
-
-if ( isset($_GET['key']) )
- $action = 'resetpass';
-
-// validate action so as to default to the login screen
-if ( !in_array( $action, array( 'postpass', 'logout', 'lostpassword', 'retrievepassword', 'resetpass', 'rp', 'register', 'login' ), true ) && false === has_filter( 'login_form_' . $action ) )
- $action = 'login';
-
-nocache_headers();
-
-header('Content-Type: '.get_bloginfo('html_type').'; charset='.get_bloginfo('charset'));
-
-if ( defined('RELOCATE') ) { // Move flag is set
- if ( isset( $_SERVER['PATH_INFO'] ) && ($_SERVER['PATH_INFO'] != $_SERVER['PHP_SELF']) )
- $_SERVER['PHP_SELF'] = str_replace( $_SERVER['PATH_INFO'], '', $_SERVER['PHP_SELF'] );
-
- $schema = is_ssl() ? 'https://' : 'http://';
- if ( dirname($schema . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']) != get_option('siteurl') )
- update_option('siteurl', dirname($schema . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']) );
-}
-
-//Set a cookie now to see if they are supported by the browser.
-setcookie(TEST_COOKIE, 'WP Cookie check', 0, COOKIEPATH, COOKIE_DOMAIN);
-if ( SITECOOKIEPATH != COOKIEPATH )
- setcookie(TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN);
-
-// allow plugins to override the default actions, and to add extra actions if they want
-do_action( 'login_init' );
-do_action( 'login_form_' . $action );
-
-$http_post = ('POST' == $_SERVER['REQUEST_METHOD']);
-switch ($action) {
-
-case 'postpass' :
- if ( empty( $wp_hasher ) ) {
- require_once( ABSPATH . 'wp-includes/class-phpass.php' );
- // By default, use the portable hash from phpass
- $wp_hasher = new PasswordHash(8, true);
- }
-
- // 10 days
- setcookie( 'wp-postpass_' . COOKIEHASH, $wp_hasher->HashPassword( stripslashes( $_POST['post_password'] ) ), time() + 864000, COOKIEPATH );
-
- wp_safe_redirect( wp_get_referer() );
- exit();
-
-break;
-
-case 'logout' :
- check_admin_referer('log-out');
- wp_logout();
-
- $redirect_to = !empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : 'wp-login.php?loggedout=true';
- wp_safe_redirect( $redirect_to );
- exit();
-
-break;
-
-case 'lostpassword' :
-case 'retrievepassword' :
-
- if ( $http_post ) {
- $errors = retrieve_password();
- if ( !is_wp_error($errors) ) {
- $redirect_to = !empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : 'wp-login.php?checkemail=confirm';
- wp_safe_redirect( $redirect_to );
- exit();
- }
- }
-
- if ( isset($_GET['error']) && 'invalidkey' == $_GET['error'] ) $errors->add('invalidkey', __('Sorry, that key does not appear to be valid.'));
- $redirect_to = apply_filters( 'lostpassword_redirect', !empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '' );
-
- do_action('lost_password');
- login_header(__('Lost Password'), '', $errors);
-
- $user_login = isset($_POST['user_login']) ? stripslashes($_POST['user_login']) : '';
-
-?>
-
-
-
-
-
-' . __( 'Your password has been reset.' ) . ' ' . __( 'Log in' ) . '
-
- - - - - - -