Esempio n. 1
0
 function callback()
 {
     $this->_secure();
     $fields_string = '';
     $get_params = get_to_assoc();
     $auth_code = $get_params['code'];
     $state = $get_params['state'];
     $post_data['code'] = $auth_code;
     $post_data['client_id'] = $this->google_auth->client_id;
     $post_data['client_secret'] = $this->google_auth->client_key;
     $post_data['redirect_uri'] = 'http://' . $_SERVER['SERVER_NAME'] . '/googleauth/callback';
     $post_data['grant_type'] = 'authorization_code';
     // New auth url set after authorization token received and its has to be posted to get the access token
     $config['auth_url'] = 'https://accounts.google.com/o/oauth2/token';
     $this->google_auth->initialize($config);
     // The following will post the retrived authorization token to get the access token from the google oauth server
     $response = $this->google_auth->get_access_token($post_data);
     if (isset($response['error'])) {
         die($response['error']);
     } else {
         $this->load->model('model_google_accounts');
         $user = $this->session->all_userdata();
         $google_account_id = $state;
         // Verify that this account is definitely for this user
         $google_account = $this->model_google_accounts->get_records(array('client_id' => $user['client_id'], 'google_account_id' => $google_account_id));
         if (!empty($google_account)) {
             $google_account_data = array();
             $google_account_data['client_id'] = $user['client_id'];
             $google_account_data['google_account_id'] = $google_account_id;
             $google_account_data[is_live() ? 'refresh_token' : 'dev_refresh_token'] = $response['refresh_token'];
             $this->model_google_accounts->save($google_account_data);
             $this->session->set_userdata('tab_nav_id', 'google_accounts_link');
             $this->session->set_flashdata('flash_message', 'Thank you - your Google account has been authorised.');
             redirect('/users/admin/google_accounts');
         }
     }
 }
Esempio n. 2
0
 function get_data()
 {
     $this->_secure(5);
     $result = array();
     $function_name = $this->uri->segment(3);
     if (!empty($function_name)) {
         $user = $this->session->all_userdata();
         $this->load->model('model_client_attributes');
         $client_attributes = $this->model_client_attributes->get_records(array('client_id' => $user['client_id'], 'attribute_array_index' => $function_name));
         $result['0'] = '-- Empty --';
         if (!empty($client_attributes)) {
             if (!empty($client_attributes[0]['attribute_values'])) {
                 foreach ($client_attributes[0]['attribute_values'] as $attribute_value) {
                     $id = ' ' . $attribute_value['id'];
                     if ($client_attributes[0]['attribute_value_type'] == 'PC') {
                         $value = $attribute_value['name'];
                         if (!empty($attribute_value['email'])) {
                             $value .= ', email: ' . $attribute_value['email'];
                         }
                         if (!empty($attribute_value['phone'])) {
                             $value .= ', phone: ' . $attribute_value['phone'];
                         }
                         if (!empty($attribute_value['mobile'])) {
                             $value .= ', mobile: ' . $attribute_value['mobile'];
                         }
                     } else {
                         $value = $attribute_value['value'];
                     }
                     $result[$id] = $value;
                 }
             }
         }
         $url_params = get_to_assoc();
         if (!empty($url_params)) {
             if (isset($url_params['id'])) {
                 $id_parts = explode('-', $url_params['id']);
                 if (sizeof($id_parts) == 2) {
                     $name = $id_parts[0];
                     $site_id = $id_parts[1];
                     $this->load->model('model_sites');
                     $site = $this->model_sites->get_records(array('client_id' => $user['client_id'], 'site_id' => $site_id));
                     if (!empty($site)) {
                         if (isset($site[0]['site_attribute_values'][$name]) && !empty($site[0]['site_attribute_values'][$name])) {
                             $result['selected'] = $site[0]['site_attribute_values'][$name];
                         }
                     }
                 }
             }
         }
     }
     $data = array();
     $data['any'] = json_encode($result);
     $data['action_view'] = 'misc/any';
     $this->load->view('layouts/blank', $data);
 }