Exemple #1
0
 function submit()
 {
     $form_id = $this->input->post('form_id');
     if (empty($form_id)) {
         die(show_error('You did not specify a "form_id" in your form post.'));
     }
     $this->load->model('forms/form_model');
     $form = $this->form_model->get_form($form_id);
     if (empty($form)) {
         die(show_error('This form is invalid.'));
     }
     // do they have permissions?
     if (!$this->user_model->in_group($form['privileges'])) {
         die(show_error('Invalid permissions'));
     }
     // form validation and processing
     $this->load->library('custom_fields/form_builder');
     $this->form_builder->build_form_from_group($form['custom_field_group_id']);
     $recaptchaUserResponse = $this->CI->input->post('g-recaptcha-response');
     $this->CI->load->model('recaptcha_model');
     $recaptchaValidation = $this->recaptcha_model->recaptchaValidation($recaptchaUserResponse);
     if ($this->form_builder->validate_post() === FALSE || $recaptchaValidation == false) {
         $this->session->set_flashdata('validation_errors', $this->form_builder->validation_errors());
         $values = query_value_encode(serialize($this->form_builder->post_to_array($form['custom_field_group_id'])));
         return redirect($form['url_path'] . '?errors=true&values=' . $values);
     }
     // we validated!  let's make the post
     $custom_fields = $this->form_builder->post_to_array($form['custom_field_group_id']);
     $this->form_model->new_response($form['id'], $this->user_model->logged_in() ? $this->user_model->get('id') : 0, $custom_fields);
     redirect($form['redirect']);
 }
/**
* Registration Form Template Plugin
*
* Assists in the creation of registration forms
*
* @param string $return The relative or absolute URL to return to after registering
*/
function smarty_block_registration_form($params, $tagdata, &$smarty, &$repeat)
{
    if (!isset($params['var'])) {
        show_error('You must specify a "var" parameter for template {registration_form} calls.  This parameter specifies the variable name for the returned array.');
    } else {
        $variables = array();
        // get return URL
        if (isset($params['return']) and !empty($params['return'])) {
            $variables['return'] = query_value_encode($params['return']);
        } else {
            $variables['return'] = '';
        }
        // form action
        $variables['form_action'] = site_url('users/post_registration');
        if (setting('ssl_certificate') == '1') {
            $variables['form_action'] = secure($variables['form_action']);
        }
        // populated values
        $variables['first_name'] = $smarty->CI->input->post('firstname');
        $variables['last_name'] = $smarty->CI->input->post('last_name');
        $variables['email'] = $smarty->CI->input->post('email');
        $variables['username'] = $smarty->CI->input->post('username');
        $custom_fields = $smarty->CI->user_model->get_custom_fields(array('registration_form' => TRUE, 'not_in_admin' => TRUE));
        $variables['custom_fields'] = $custom_fields;
        if (is_array($custom_fields)) {
            foreach ($custom_fields as $field) {
                $variables[$field['name']] = $smarty->CI->input->post($field['name']);
            }
        }
        $smarty->assign($params['var'], $variables);
        echo $tagdata;
    }
}
Exemple #3
0
/**
* Login Form Template Plugin
*
* Assists in the creation of login forms
*
* @param string $return The relative or absolute URL to return to after logging in
* @param string $username Username value
*/
function smarty_block_login_form($params, $tagdata, &$smarty, &$repeat)
{
    if (!isset($params['var'])) {
        show_error('You must specify a "var" parameter for template {login_form} calls.  This parameter specifies the variable name for the returned array.');
    } else {
        $variables = array();
        // get return URL
        if (isset($params['return']) and !empty($params['return'])) {
            $variables['return'] = query_value_encode($params['return']);
        } else {
            $variables['return'] = '';
        }
        // form action
        $variables['form_action'] = site_url('users/post_login');
        if (setting('ssl_certificate') == '1') {
            $variables['form_action'] = secure($variables['form_action']);
        }
        // username
        $variables['username'] = isset($params['username']) ? $params['username'] : '';
        $smarty->assign($params['var'], $variables);
        echo $tagdata;
    }
}
Exemple #4
0
 function post_login()
 {
     // get $return if available
     if ($this->input->post('return') != '') {
         $return = query_value_decode($this->input->post('return'));
     } else {
         $return = site_url('users');
     }
     // validate fields
     $this->load->library('form_validation');
     $this->form_validation->set_rules('username', 'Username/Email', 'trim|required');
     $this->form_validation->set_rules('password', 'Password', 'trim|required');
     if ($this->form_validation->run() == FALSE) {
         $this->session->set_flashdata('login_errors', validation_errors());
         return redirect('users/login?return=' . query_value_encode($return) . '&errors=true&username='******'username'));
     }
     // are we remembering this user?
     $remember = ($this->input->post('remember') and $this->input->post('remember') != '') ? TRUE : FALSE;
     // attempt login
     if ($this->user_model->login($this->input->post('username'), $this->input->post('password'), $remember)) {
         // success!
         // do we have a relative URL?
         if (strpos($return, 'http') === FALSE) {
             $return = site_url($return);
         }
         return header('Location: ' . $return);
     } else {
         if ($this->user_model->failed_due_to_activation == TRUE) {
             $this->session->set_flashdata('login_errors', '<p>Login failed.  Your account email has not been activated yet.  Please click the link in your activation email to activate your account.  If you cannot find the email in your inbox or junk folders, contact website support for assistance.');
         } elseif ($this->user_model->failed_due_to_duplicate_login == TRUE) {
             $this->session->set_flashdata('login_errors', '<p>Login failed.  Someone is already logged in with this account.  If you believe this is in error, wait 1 minute and try again.  Otherwise, ensure that you are not logged in the site on another device before continuing.');
         } else {
             $this->session->set_flashdata('login_errors', '<p>Login failed.  Please verify your username/email and password.');
         }
         return redirect('users/login?return=' . query_value_encode($return) . '&errors=true');
     }
 }
Exemple #5
0
 /**
  * Post Billing/Shipping
  */
 function post_billing_shipping()
 {
     $this->prep_cart();
     $this->require_login();
     $this->load->library('form_validation');
     // new or existing billing address?
     if ($this->input->post('billing_address') == 'existing') {
         $billing_address_type = 'existing';
     } else {
         $billing_address_type = 'new';
     }
     // billing address validation
     if ($billing_address_type == 'new') {
         $this->form_validation->set_rules('first_name', 'First Name', 'required');
         $this->form_validation->set_rules('last_name', 'Last Name', 'required');
         $this->form_validation->set_rules('address_1', 'Address', 'required');
         $this->form_validation->set_rules('city', 'City', 'required');
         $this->form_validation->set_rules('country', 'Country', 'required');
         if ($this->input->post('state') == '') {
             $this->form_validation->set_rules('state_select', 'State/Province', 'required');
         }
         $this->form_validation->set_rules('postal_code', 'Postal/Zip Code', 'required');
         if (isset($_POST['phone_number'])) {
             // we only require this field if it was sent
             // it was added in 3.73 and we don't want to break old sites
             $this->form_validation->set_rules('phone_number', 'Phone Number', 'required');
         }
     }
     // shipping address validation
     if ($this->requires_shipping == TRUE) {
         $this->form_validation->set_rules('shipping_address', 'Shipping Address Type', 'required');
         if ($this->input->post('shipping_address') == 'new') {
             $this->form_validation->set_rules('shipping_first_name', 'First Name', 'required');
             $this->form_validation->set_rules('shipping_last_name', 'Last Name', 'required');
             $this->form_validation->set_rules('shipping_address_1', 'Address', 'required');
             $this->form_validation->set_rules('shipping_city', 'City', 'required');
             $this->form_validation->set_rules('shipping_country', 'Country', 'required');
             if ($this->input->post('shipping_state') == '') {
                 $this->form_validation->set_rules('shipping_state_select', 'State/Province', 'required');
             }
             $this->form_validation->set_rules('shipping_postal_code', 'Postal/Zip Code', 'required');
             if (isset($_POST['shipping_phone_number'])) {
                 // we only require this field if it was sent
                 // it was added in 3.73 and we don't want to break old sites
                 $this->form_validation->set_rules('shipping_phone_number', 'Phone Number', 'required');
             }
         }
     }
     // build arrays of values in case we need to redirect back to the form
     if ($billing_address_type == 'new') {
         $billing_values = array('first_name' => $this->input->post('first_name'), 'last_name' => $this->input->post('last_name'), 'company' => $this->input->post('company'), 'address_1' => $this->input->post('address_1'), 'address_2' => $this->input->post('address_2'), 'city' => $this->input->post('city'), 'country' => $this->input->post('country'), 'postal_code' => $this->input->post('postal_code'), 'state' => $this->input->post('state_select') == '' ? $this->input->post('state') : $this->input->post('state_select'), 'phone_number' => $this->input->post('phone_number'));
     } else {
         $billing_values = array();
     }
     if ($this->requires_shipping == TRUE and $this->input->post('shipping_address') == 'new') {
         $shipping_values = array('first_name' => $this->input->post('shipping_first_name'), 'last_name' => $this->input->post('shipping_last_name'), 'company' => $this->input->post('shipping_company'), 'address_1' => $this->input->post('shipping_address_1'), 'address_2' => $this->input->post('shipping_address_2'), 'city' => $this->input->post('shipping_city'), 'country' => $this->input->post('shipping_country'), 'postal_code' => $this->input->post('shipping_postal_code'), 'state' => $this->input->post('shipping_state_select') == '' ? $this->input->post('shipping_state') : $this->input->post('shipping_state_select'), 'phone_number' => $this->input->post('shipping_phone_number'));
     } else {
         $shipping_values = array();
     }
     if (!empty($this->form_validation->_config_rules) and $this->form_validation->run() === FALSE) {
         $this->session->set_userdata('errors', validation_errors());
         redirect('checkout/billing_shipping?billing_values=' . query_value_encode(serialize($billing_values)) . '&shipping_values=' . query_value_encode(serialize($shipping_values)));
     }
     // we are validated
     if ($billing_address_type == 'new') {
         // update their billing address
         // to stay compatible with the old UpdateCustomer code
         $billing_values['phone'] = $billing_values['phone_number'];
         $this->user_model->update_billing_address($this->user_model->get('id'), $billing_values);
     }
     // deal with shipping address
     if ($this->requires_shipping == FALSE) {
         $shipping_address = FALSE;
     } elseif ($this->input->post('shipping_address') == 'same') {
         $shipping_address = $this->user_model->get_billing_address($this->user_model->get('id'));
     } elseif ($this->input->post('shipping_address') == 'new') {
         $shipping_address = $shipping_values;
     }
     // save shipping address in session
     $this->session->set_userdata('shipping_address', $shipping_address);
     // trigger checkout_billing_shipping
     $this->load->library('app_hooks');
     $this->app_hooks->trigger('checkout_billing_shipping');
     // do we need to redirect to the shipping method selection page?
     if ($shipping_address and $this->requires_shipping) {
         return redirect('checkout/shipping_method');
     } else {
         return redirect('checkout/payment');
     }
 }