Advertisement
VladimirsBudkins

CI session trouble

Feb 28th, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.15 KB | None | 0 0
  1. //login controller
  2. public function login() {
  3.         $provider = $this->uri->rsegment(3);
  4.         $lang = $this->uri->rsegment(4) ? : $this->lang->default;
  5.         if (!$provider || !$this->hybridauthlib->providerEnabled($provider)) {
  6.             $this->_set_404(TRUE);
  7.         } else {
  8.             $instance = $this->_authorize($provider);
  9.             if ($instance) {
  10.                 $user_profile = $instance->getUserProfile();
  11.                 $token = $instance->getAccessToken();
  12.                 $user_data = array(
  13.                     'lang' => $lang,
  14.                     'social_id' => $user_profile->identifier,
  15.                     'social' => strtolower($provider),
  16.                     'photo' => $user_profile->photoURL,
  17.                     'email' => $user_profile->email,
  18.                     'username' => $user_profile->displayName,
  19.                     'first_name' => $user_profile->firstName,
  20.                     'last_name' => $user_profile->lastName,
  21.                     'token' => $token['access_token'],
  22.                 );
  23.                 $this->hybridauthlib->authorize_user($user_data);
  24.         //there setup flash data
  25.                 //$this->session->set_flashdata('success', 'Авторизация успешна');;
  26.                 redirect($lang . '/'. strtolower($provider));
  27.             } else {
  28.                 //$this->session->set_flashdata('error', 'Произошала ошибка авторизации');
  29.                 //redirect($lang . '/auth/login');
  30.             }
  31.         }
  32.        
  33.     }
  34.  
  35. //hybrid auth authorize
  36. public function authorize_user($user_data) {
  37.         $newdata = array(
  38.             'social_data' => array(
  39.                 'username' => $user_data['username'],
  40.                 'email' => $user_data['email'],
  41.                 'logged_in' => TRUE,
  42.                 'social' => $user_data['social'],
  43.                 'photo' => $user_data['photo'],
  44.                 'token' => $user_data['token'],
  45.                 'social_id' => $user_data['social_id'],
  46.             )
  47.         );
  48.     //setup social accaunt
  49.         $this->session->set_userdata($newdata);
  50.        
  51.         $this->save_user($user_data);
  52.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement