Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //login controller
- public function login() {
- $provider = $this->uri->rsegment(3);
- $lang = $this->uri->rsegment(4) ? : $this->lang->default;
- if (!$provider || !$this->hybridauthlib->providerEnabled($provider)) {
- $this->_set_404(TRUE);
- } else {
- $instance = $this->_authorize($provider);
- if ($instance) {
- $user_profile = $instance->getUserProfile();
- $token = $instance->getAccessToken();
- $user_data = array(
- 'lang' => $lang,
- 'social_id' => $user_profile->identifier,
- 'social' => strtolower($provider),
- 'photo' => $user_profile->photoURL,
- 'email' => $user_profile->email,
- 'username' => $user_profile->displayName,
- 'first_name' => $user_profile->firstName,
- 'last_name' => $user_profile->lastName,
- 'token' => $token['access_token'],
- );
- $this->hybridauthlib->authorize_user($user_data);
- //there setup flash data
- //$this->session->set_flashdata('success', 'Авторизация успешна');;
- redirect($lang . '/'. strtolower($provider));
- } else {
- //$this->session->set_flashdata('error', 'Произошала ошибка авторизации');
- //redirect($lang . '/auth/login');
- }
- }
- }
- //hybrid auth authorize
- public function authorize_user($user_data) {
- $newdata = array(
- 'social_data' => array(
- 'username' => $user_data['username'],
- 'email' => $user_data['email'],
- 'logged_in' => TRUE,
- 'social' => $user_data['social'],
- 'photo' => $user_data['photo'],
- 'token' => $user_data['token'],
- 'social_id' => $user_data['social_id'],
- )
- );
- //setup social accaunt
- $this->session->set_userdata($newdata);
- $this->save_user($user_data);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement