You are here

function zopim_admin_settings_form_validate in Zopim Live Chat 6.2

Same name in this branch
  1. 6.2 includes/zopim-account.admin.inc \zopim_admin_settings_form_validate()
  2. 6.2 includes/zopim-customize.admin.inc \zopim_admin_settings_form_validate()
  3. 6.2 includes/zopim-visibility.admin.inc \zopim_admin_settings_form_validate()
Same name and namespace in other branches
  1. 6 zopim.admin.inc \zopim_admin_settings_form_validate()
  2. 7 zopim.admin.inc \zopim_admin_settings_form_validate()

File

includes/zopim-account.admin.inc, line 165
Administrative page callbacks for the zopim module.

Code

function zopim_admin_settings_form_validate($form, &$form_state) {
  $settings = zopim_get_settings();
  switch ($form_state['values']['account_setup']['account']) {
    case '1':

      // setting credentials for an existing account.
      $data = array(
        'email' => $form_state['values']['account_setup']['existing_account']['username'],
        'password' => $form_state['values']['account_setup']['existing_account']['password'],
      );
      $data_response = zopim_post_request(ZOPIM_LOGIN_URL, $data, $form_state['values']['general']['use_ssl']);
      if (isset($data_response->error)) {
        form_set_error('account_setup][existing_account][username', 'Zopim Username and/or Password are incorrect.');
        form_set_error('account_setup][existing_account][password', ' ');
      }
      else {
        $form_state['values']['general']['salt'] = $data_response->salt;
        $form_state['values']['general']['account'] = 1;
        $form_state['values']['general']['username'] = $form_state['values']['account_setup']['existing_account']['username'];
        $form_state['values']['general']['password'] = md5($form_state['values']['account_setup']['existing_account']['password']);
        $account_details = zopim_get_account_details($data_response->salt);
        $form_state['values']['general']['account_key'] = $account_details->account_key;
        $form_state['values']['general']['customization']['color'] = $account_details->color_customization_enabled;
        $form_state['values']['general']['customization']['widget'] = $account_details->widget_customization_enabled;
      }
      break;
    case '0':

      // creating new account.
      $data = array(
        'email' => $form_state['values']['account_setup']['new_account']['email'],
        'first_name' => $form_state['values']['account_setup']['new_account']['first_name'],
        'last_name' => $form_state['values']['account_setup']['new_account']['last_name'],
        'display_name' => $form_state['values']['account_setup']['new_account']['first_name'] . ' ' . $form_state['values']['account_setup']['new_account']['last_name'],
        'eref' => '',
        'source' => "drupal",
        'recaptcha_challenge_field' => $_POST["recaptcha_challenge_field"],
        'recaptcha_response_field' => $_POST["recaptcha_response_field"],
      );
      $data_response = zopim_post_request(ZOPIM_SIGNUP_URL, $data, $form_state['values']['general']['use_ssl']);
      if ($data_response->account_key) {
        $account_key = $data_response->account_key;
        $form_state['values']['general']['account_key'] = $account_key;
        $form_state['values']['general']['account'] = 1;
        drupal_set_message(t('Thank you for signing up. Please check your E-mail for your password then enter your credentials here to complete the process.'), 'warning');
      }
      else {
        form_set_error('account_setup][new_account][first_name', t('Error during activation: ') . $data_response->error . '. Please try again.');
        form_set_error('account_setup][new_account][last_name', ' ');
        form_set_error('account_setup][new_account][email', ' ');
      }
      break;
    default:

      // reseting credentials.
      $form_state['values']['general']['account'] = 0;
      $form_state['values']['general']['account_key'] = FALSE;
      $form_state['values']['general']['agreement'] = 0;
      $form_state['values']['general']['username'] = FALSE;
      $form_state['values']['general']['password'] = FALSE;
      $form_state['values']['general']['salt'] = FALSE;
      drupal_set_message(t('Your credentials have been deleted.  You must add credentials for another account or create a new account to continue using Zopim.'), 'warning');
      break;
  }

  // remove account_setup and all child elements so as to not set them in the variable.
  unset($form_state['values']['account_setup']);
}