コード例 #1
0
 public function create_user()
 {
     // Get groups
     $groups = \Sentry::group()->all('front');
     if (\Input::post()) {
         // Get POST values
         $insert = \Input::post();
         $register_type = 'register';
         if (\Input::post('register')) {
             $register_type = $insert['register'];
         }
         $ship_to = 'billing';
         if ($insert['ship'] == 'other') {
             $ship_to = 'shipping';
         }
         $val = \User\Controller_Validate::forge($register_type == 'register' ? 'create' : 'guest', false, $ship_to == 'shipping' ? 'shipping' : false);
         if ($val->run()) {
             array_walk($insert, create_function('&$val', '$val = trim($val);'));
             try {
                 // Generate random username
                 $email = $insert['email'];
                 $user_group = 3;
                 if ($register_type == 'guest') {
                     $username = '******' . \Str::random('numeric', 16);
                     $insert['guest'] = 1;
                     $random_password = '******' . \Str::random(unique);
                     $password = $random_password;
                 } else {
                     $username = $email;
                     $insert['guest'] = 0;
                     $password = $insert['password'];
                 }
                 unset($insert['email'], $insert['password'], $insert['confirm_password'], $insert['user_group'], $insert['details'], $insert['save'], $insert['update']);
                 $only_billing = array('email');
                 $billing_data = \Arr::filter_prefixed($insert, "billing_");
                 // Set shipping data to be same as billing by default
                 if ($ship_to_billing) {
                     foreach ($billing_data as $key => $value) {
                         if (!in_array($key, $only_billing)) {
                             $insert['shipping_' . $key] = $value;
                         }
                     }
                 }
                 $metadata = \Arr::remove_prefixed($insert, "billing_") + $billing_data;
                 $table = \DB::table_prefix('users_metadata');
                 $columns = \DB::list_columns($table);
                 $insert = array_intersect_key($metadata, $columns);
                 // create the user - no activation required
                 $vars = array('username' => $username, 'email' => $email, 'password' => $password, 'metadata' => $insert);
                 $user_id = \Sentry::user()->create($vars);
                 $user = \Sentry::user($user_id);
                 // Add user to 'customer' group (id = 3)
                 if ($user_id and $user->add_to_group($user_group)) {
                     if ($register_type == 'account') {
                         \Messages::success('User successfully created.');
                     }
                     if ($register_type == 'guest') {
                         \Messages::success('You register as a guest.');
                     }
                     $login_column = \Config::get('sentry.login_column', 'email');
                     if (\Sentry::login(${$login_column}, $password, true)) {
                         \Response::redirect(\Uri::create('order/checkout/cost'));
                     } else {
                         if ($register_type == 'account') {
                             \Messages::error('There was an error while trying to create account. Please try to create new account.');
                         }
                         if ($register_type == 'guest') {
                             \Messages::error('There was an error. Please try to login with your account details.');
                         }
                     }
                 } else {
                     // show validation errors
                     \Messages::error('There was an error while trying to create account.');
                 }
             } catch (\Sentry\SentryException $e) {
                 // show validation errors
                 \Messages::error('There was an error while trying to create user.');
                 $errors = $e->getMessage();
                 \Messages::error($errors);
             }
         } else {
             if ($val->error() != array()) {
                 // show validation errors
                 \Messages::error('There was an error while trying to create user.');
                 foreach ($val->error() as $e) {
                     \Messages::error($e->get_message());
                 }
             }
         }
     }
 }
コード例 #2
0
ファイル: user.php プロジェクト: EdgeCommerce/edgecommerce
 /**
  * Change user password
  * 
  * @access public
  * @return void
  */
 public function action_password()
 {
     \View::set_global('title', 'Forgot Password');
     if (\Input::post('forgot')) {
         $val = \User\Controller_Validate::forge('forgot_password');
         if ($val->run()) {
             // Get POST values
             $identity = \Input::post('identity', '');
             if (\Sentry::user_exists($identity)) {
                 try {
                     // reset the password
                     $reset = \Sentry::reset_password($identity);
                     if ($reset) {
                         $customer_email = $reset['email'];
                         // Load email package
                         \Package::load('email');
                         // Load email addresses from config (these will be bcc receivers)
                         \Config::load('auto_response_emails', true);
                         $bcc = \Config::get('autoresponders.forgot_password_emails');
                         if (!$bcc) {
                             $bcc = \Config::get('autoresponders.default_emails');
                         }
                         $settings = \Config::load('autoresponder.db');
                         $email_data = array('site_title' => $settings['company_name'], 'customer_identity' => $identity, 'reset_link' => \Uri::front_create('user/reset_password/' . $reset['link']));
                         $email = \Email::forge();
                         $email->to($customer_email);
                         $email->from(\Config::get('auto_response_emails.autoresponder_from_email'), $settings['company_name']);
                         if ($bcc) {
                             $email->bcc($bcc);
                         }
                         $email->subject($email_data['site_title'] . ' - Forgot Password');
                         $email_html = \Theme::instance()->view('views/_email/forgot_password')->set('email_data', $email_data, false);
                         $email->html_body($email_html);
                         try {
                             $email->send();
                             \Messages::success('You have been sent an email to reset your password.');
                         } catch (\EmailValidationFailedException $e) {
                             \Messages::error('Error while sending email.');
                         } catch (\EmailSendingFailedException $e) {
                             \Messages::error('Error while sending email.');
                         }
                         \Response::redirect(\Input::referrer(\Uri::front_create('/')));
                     } else {
                         \Messages::error('There was a problem while trying to change your password. Please try again.');
                     }
                 } catch (\Sentry\SentryException $e) {
                     // show validation errors
                     //\Messages::error('<h4>There was an error while trying to create user</h4>');
                     $errors = $e->getMessage();
                     \Messages::error($errors);
                 }
             } else {
                 \Messages::error('There doesn`t appear to be an account associated with this email address. Try a different email address or register for a new account on the homepage.');
             }
         } else {
             if ($val->error() != array()) {
                 // show validation errors
                 //\Messages::error('<h4>There was an error while trying to create user</h4>');
                 foreach ($val->error() as $e) {
                     \Messages::error($e->get_message());
                 }
             }
         }
     }
     if (\Input::is_ajax()) {
         echo \Theme::instance()->view($this->view_dir . 'forgot_password');
     } else {
         if (isset($val)) {
             \View::set_global('validation', $val, false);
         }
         \Theme::instance()->set_partial('content', $this->view_dir . 'single_forgot_password');
     }
 }
コード例 #3
0
ファイル: account.php プロジェクト: EdgeCommerce/edgecommerce
 /**
  * Change user details
  * 
  * @param $field = Field name (username, email, password)
  * 
  * @access public
  * @return void
  */
 public function action_change($field = 'password')
 {
     $field = strtolower($field);
     $allowed_changes = array('username', 'email', 'password', 'dob');
     if (!in_array($field, $allowed_changes)) {
         \Response::redirect(\Uri::front_create('user'));
     }
     \View::set_global('title', __('Change :field_name', array('field_name' => ucfirst($field))));
     // Get current user
     $user = \Sentry::user();
     if (\Input::post()) {
         $val = \User\Controller_Validate::forge('change_' . $field, $user->id);
         if ($val->run()) {
             // Get POST values
             $insert = \Input::post();
             try {
                 // update the user
                 if ($field == 'dob') {
                     $user->update(array('metadata' => array('dob_year' => $insert['dob_year'], 'dob_month' => $insert['dob_month'], 'dob_day' => $insert['dob_day'])));
                 } else {
                     $user->update(array($field => $insert[$field]));
                 }
                 if ($user->in_group(4)) {
                     $user->remove_from_group(4);
                     // Remove from guest group
                     $user->add_to_group(3);
                     // Add to standard customers group
                 }
                 \Messages::success(__(':field_name successfully changed.', array('field_name' => ucfirst($field))));
                 \Response::redirect(\Input::referrer(\Uri::front('current')));
             } catch (\Sentry\SentryException $e) {
                 // show validation errors
                 //\Messages::error('<h4>There was an error while trying to create user</h4>');
                 $errors = $e->getMessage();
                 \Messages::error($errors);
             }
         } else {
             if ($val->error() != array()) {
                 // show validation errors
                 //\Messages::error('<h4>There was an error while trying to create user</h4>');
                 foreach ($val->error() as $e) {
                     \Messages::error($e->get_message());
                 }
             }
         }
     }
     if (\Input::is_ajax()) {
         \View::set_global('language', $this->language);
         echo \Theme::instance()->view($this->view_dir . 'change_' . $field, array('user' => $user));
     } else {
         if (isset($val)) {
             \View::set_global('validation', $val, false);
         }
         \Theme::instance()->set_partial('content', $this->view_dir . 'single_change_' . $field);
     }
 }