public function action() { if (isset($_POST['action']) && $_POST['action'] == 'change_password') { $errors = array(); $user = $this->wp->wpGetCurrentUser(); /** @noinspection PhpUndefinedFieldInspection */ if (!$this->wp->wpCheckPassword($_POST['password'], $user->user_pass, $user->ID)) { $errors[] = __('Current password is invalid.', 'jigoshop'); } if (empty($_POST['new-password'])) { $errors[] = __('Please enter new password.', 'jigoshop'); } else { if ($_POST['new-password'] != $_POST['new-password-2']) { $errors[] = __('Passwords do not match.', 'jigoshop'); } } if (!empty($errors)) { $this->messages->addError(join('<br/>', $errors), false); } else { $this->wp->wpUpdateUser(array('ID' => $user->ID, 'user_pass' => $_POST['new-password'])); $this->messages->addNotice(__('Password changed.', 'jigoshop')); $this->wp->redirectTo($this->options->getPageId(Pages::ACCOUNT)); } } }
private function createUserAccount() { // Check if user agreed to account creation if (isset($_POST['jigoshop_account']) && $_POST['jigoshop_account']['create'] != 'on') { return; } $email = $_POST['jigoshop_order']['billing_address']['email']; $errors = new \WP_Error(); $this->wp->doAction('register_post', $email, $email, $errors); if ($errors->get_error_code()) { throw new Exception($errors->get_error_message()); } $login = $_POST['jigoshop_account']['login']; $password = $_POST['jigoshop_account']['password']; if (empty($login) || empty($password)) { throw new Exception(__('You need to fill username and password fields.', 'jigoshop')); } if ($password != $_POST['jigoshop_account']['password2']) { throw new Exception(__('Passwords do not match.', 'jigoshop')); } $id = $this->wp->wpCreateUser($login, $password, $email); if (!$id) { throw new Exception(sprintf(__("<strong>Error</strong> Couldn't register an account for you. Please contact the <a href=\"mailto:%s\">administrator</a>.", 'jigoshop'), $this->options->get('general.email'))); } if (is_wp_error($id)) { throw new Exception(sprintf(__("<strong>Error</strong> Account creation failed: %s", 'jigoshop'), $id->get_error_message($id->get_error_code()))); } $this->wp->wpUpdateUser(array('ID' => $id, 'role' => 'customer', 'first_name' => $_POST['jigoshop_order']['billing_address']['first_name'], 'last_name' => $_POST['jigoshop_order']['billing_address']['last_name'])); $this->wp->doAction('jigoshop\\checkout\\created_account', $id); // send the user a confirmation and their login details if ($this->wp->applyFilters('jigoshop\\checkout\\new_user_notification', true, $id)) { $this->wp->wpNewUserNotification($id); } $this->wp->wpSetAuthCookie($id, true, $this->wp->isSsl()); $cart = $this->cartService->getCurrent(); $customer = $this->customerService->find($id); $customer->restoreState($cart->getCustomer()->getStateToSave()); $cart->setCustomer($customer); }