Beispiel #1
0
 public static function login($result)
 {
     $Customer = ShoppOrder()->Customer;
     if ($Customer->loggedin()) {
         return $result;
     }
     $accounts = shopp_setting('account_system');
     $pleaselogin = '******' . Shopp::__('If you have an account with us, please login now.');
     // This specific !isset condition checks if the loginname is not provided
     // If no loginname is provided, but an account system is used, we need to
     // generate a new login name for the customer
     if ('wordpress' == $accounts && !isset($_POST['loginname'])) {
         ShoppLoginGenerator::object();
         $_POST['loginname'] = ShoppLoginGenerator::name();
         if (apply_filters('shopp_login_required', empty($_POST['loginname']))) {
             return shopp_add_error(Shopp::__('A login could not be created with the information you provided. Enter a different name or email address.') . $pleaselogin);
         }
         shopp_debug('Login set to ' . $_POST['loginname'] . ' for WordPress account creation.');
     }
     // Validate unique email address for new account
     if (in_array($accounts, array('wordpress', 'shopp')) && !$Customer->session(ShoppCustomer::GUEST)) {
         $ShoppCustomer = new ShoppCustomer($_POST['email'], 'email');
         if (apply_filters('shopp_email_exists', 'wordpress' == $accounts ? email_exists($_POST['email']) : $ShoppCustomer->exists())) {
             return shopp_add_error(Shopp::__('The email address you entered is already in use. Enter a different email address to create a new account.') . $pleaselogin);
         }
     }
     // Validate WP login
     if (isset($_POST['loginname'])) {
         if (apply_filters('shopp_login_required', empty($_POST['loginname']))) {
             return shopp_add_error(Shopp::__('You must enter a login name for your account.'));
         }
         if (apply_filters('shopp_login_valid', !validate_username($_POST['loginname']))) {
             $sanitized = sanitize_user($_POST['loginname'], true);
             $illegal = array_diff(str_split($_POST['loginname']), str_split($sanitized));
             return shopp_add_error(Shopp::__('The login name provided includes invalid characters: %s', esc_html(join(' ', $illegal))));
         }
         if (apply_filters('shopp_login_exists', username_exists($_POST['loginname']))) {
             return shopp_add_error(Shopp::__('"%s" is already in use. Enter a different login name to create a new account.', esc_html($_POST['loginname'])) . $pleaselogin);
         }
     }
     return $result;
 }
Beispiel #2
0
 public function load()
 {
     $id = (int) $this->request('id');
     if (empty($id)) {
         return;
     }
     if ($this->request('new')) {
         return new ShoppCustomer();
     }
     $Customer = new ShoppCustomer($id);
     if (!$Customer->exists()) {
         wp_die(Shopp::__('The requested customer record does not exist.'));
     }
     $Customer->Billing = new BillingAddress($Customer->id, 'customer');
     $Customer->Shipping = new ShippingAddress($Customer->id, 'customer');
     return $Customer;
 }
Beispiel #3
0
 public function add()
 {
     if ('new-customer' != $this->form('order-action')) {
         return;
     }
     if (!($updates = $this->form('customer'))) {
         return;
     }
     if (!is_array($updates)) {
         return;
     }
     extract($this->references, EXTR_SKIP);
     // Create the new customer record
     $Customer = new ShoppCustomer();
     $Customer->updates($updates);
     $Customer->password = wp_generate_password(12, true);
     if ('wordpress' == shopp_setting('account_system')) {
         $Customer->create_wpuser();
     } else {
         unset($this->form['loginname']);
     }
     $Customer->save();
     if (!$Customer->exists()) {
         return $this->notice(Shopp::__('An unknown error occured. The customer could not be created.'), 'error');
     }
     $Purchase->customer = $Customer->id;
     $Purchase->copydata($Customer);
     $Purchase->save();
     // Create a new billing address record for the new customer
     if ($billing = $this->form('billing') && is_array($billing) && empty($billing['id'])) {
         $Billing = new BillingAddress($billing);
         $Billing->customer = $Customer->id;
         $Billing->save();
     }
     // Create a new shipping address record for the new customer
     if ($shipping = $this->form('shipping') && is_array($shipping) && empty($shipping['id'])) {
         $Shipping = new ShippingAddress($shipping);
         $Shipping->customer = $Customer->id;
         $Shipping->save();
     }
 }