/** * Resets a customer/user password with a valid activation key * * @since 1.0 * * @param string $activation The activation key * @return void **/ static function resetpassword($activation) { if ('none' == shopp_setting('account_system') || ShoppCustomer()->loggedin()) { return; } $user_data = false; $activation = preg_replace('/[^a-z0-9]/i', '', $activation); $errors = array(); if (empty($activation) || !is_string($activation)) { $errors[] = shopp_add_error(Shopp::__("Invalid password reset key. Try copy/pasting the url in password reset email into your web browser's address bar.")); } else { $RecoveryCustomer = new ShoppCustomer($activation, 'activation'); if (empty($RecoveryCustomer->id)) { $errors[] = shopp_add_error(Shopp::__("Invalid password reset key. Try copy/pasting the url in password reset email into your web browser's address bar.")); } } if (!empty($errors)) { return false; } // Generate a new random password $password = wp_generate_password(12, false); do_action_ref_array('password_reset', array($RecoveryCustomer, $password)); $RecoveryCustomer->password = wp_hash_password($password); if ('wordpress' == shopp_setting('account_system')) { $user_data = get_userdata($RecoveryCustomer->wpuser); wp_set_password($password, $user_data->ID); } $RecoveryCustomer->activation = ''; $RecoveryCustomer->save(); $subject = apply_filters('shopp_reset_password_subject', Shopp::__('[%s] New Password', get_option('blogname'))); $_ = array(); $_[] = 'From: ' . Shopp::email_from(shopp_setting('merchant_email'), shopp_setting('business_name')); $_[] = 'To: ' . $RecoveryCustomer->email; $_[] = 'Subject: ' . $subject; $_[] = 'Content-type: text/html'; $_[] = ''; $_[] = '<p>' . Shopp::__('Your new password for %s:', get_bloginfo('url')) . '</p>'; $_[] = ''; $_[] = '<ul>'; if (apply_filters('shopp_reset_password_wpuser', true) && !empty($user_data->user_login)) { $_[] = '<li>' . Shopp::__('Login: %s', $user_data->user_login) . '</li>'; } elseif (!empty($RecoveryCustomer->email)) { $_[] = '<li>' . Shopp::__('Login: %s', $RecoveryCustomer->email) . '</li>'; } $_[] = '<li>' . Shopp::__('Password: %s', $password) . '</li>'; $_[] = '</ul>'; $_[] = ''; $_[] = '<p>' . Shopp::__('Click here to login: %s', Shopp::url(false, 'account')) . '</p>'; $message = apply_filters('shopp_reset_password_message', $_); if (!Shopp::email(join("\n", $message))) { shopp_add_notice(Shopp::__('Your password was reset to: ' . $password)); } else { shopp_add_notice(Shopp::__('Your new password has been emailed to you for your records. Your password was reset to: ' . $password)); } unset($_GET['acct']); // Auto-login $RecoveryCustomer->login(); // Login the customer if (!empty($user_data)) { // Log the WordPress user in ShoppLogin::wpuser($user_data); } // Show notice after login in case of failures during login shopp_add_notice(Shopp::__('You are now logged into your account.')); if (apply_filters('shopp_reset_password_redirect', true)) { shopp_add_notice(Shopp::__('If you wish, please use the form below to change your password to one of your choosing.')); Shopp::redirect(add_query_arg('profile', '', Shopp::url(false, 'account'))); } }