Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>here is my code which work 100% :</p> <pre><code>class Auth extends MX_Controller { public function __construct() { parent::__construct(); $this-&gt;template-&gt;set_layout('login'); } //social login public function social($provider) { try{ $this-&gt;load-&gt;library('HybridAuthLib'); $this-&gt;load-&gt;model('auth_model'); $serviceEnabled = $this-&gt;hybridauthlib-&gt;serviceEnabled($provider); if ($serviceEnabled) { $this-&gt;service = $this-&gt;hybridauthlib-&gt;authenticate($provider); if ($this-&gt;service-&gt;isUserConnected()) { $user_profile = $this-&gt;service-&gt;getUserProfile(); if($this-&gt;auth_model-&gt;count_user_by_uid($user_profile-&gt;identifier) === 0) { $this-&gt;session-&gt;set_flashdata('message','You Dont have account.. Create one.'); redirect('/users/register','refresh'); } else { $dump_data = $this-&gt;auth_model-&gt;get_by(array('provider_uid'=&gt;$user_profile-&gt;identifier)); $user = $this-&gt;ion_auth-&gt;user($dump_data-&gt;user_id)-&gt;row(); $session_data = array( 'identity' =&gt; $user-&gt;{$this-&gt;config-&gt;item('identity', 'ion_auth')}, 'username' =&gt; $user-&gt;username, 'email' =&gt; $user-&gt;email, 'user_id' =&gt; $user-&gt;id, //everyone likes to overwrite id so we'll use user_id 'old_last_login' =&gt; $user-&gt;last_login ); $this-&gt;ion_auth-&gt;update_last_login($user-&gt;id); $this-&gt;ion_auth-&gt;clear_login_attempts($this-&gt;config-&gt;item('identity', 'ion_auth')); $this-&gt;session-&gt;set_userdata($session_data); if ($this-&gt;config-&gt;item('remember_users', 'ion_auth')) { $this-&gt;ion_auth-&gt;remember_user($user-&gt;id); } $this-&gt;ion_auth-&gt;trigger_events(array('post_login', 'post_login_successful')); $this-&gt;ion_auth-&gt;set_message('login_successful'); redirect('/','refresh'); } } else // Cannot authenticate user { $this-&gt;session-&gt;set_flashdata('message','Cannot authenticate user'); redirect('/users/auth/login/','refresh'); } } else // This service is not enabled. { $this-&gt;session-&gt;set_flashdata('message','This providers is not enabled.'); redirect('/users/auth/login/','refresh'); } } catch(Exception $e) { $error = 'Unexpected error'; switch($e-&gt;getCode()) { case 0 : $error = 'Unspecified error.'; break; case 1 : $error = 'Hybriauth configuration error.'; break; case 2 : $error = 'Provider not properly configured.'; break; case 3 : $error = 'Unknown or disabled provider.'; break; case 4 : $error = 'Missing provider application credentials.'; break; case 5 : log_message('debug', 'controllers.HAuth.login: Authentification failed. The user has canceled the authentication or the provider refused the connection.'); //redirect(); if (isset($service)) { $service-&gt;logout(); } $error = 'User has cancelled the authentication or the provider refused the connection.'; break; case 6 : $error = 'User profile request failed. Most likely the user is not connected to the provider and he should to authenticate again.'; break; case 7 : $error = 'User not connected to the provider.'; break; } if (isset($this-&gt;service)) { $this-&gt;service-&gt;logout(); } log_message('error', 'controllers.HAuth.login: '.$error); $this-&gt;session-&gt;set_flashdata('message', $error); redirect('/users/auth/login/', 'refresh'); } } public function endpoint() { log_message('debug', 'controllers.HAuth.endpoint called.'); log_message('info', 'controllers.HAuth.endpoint: $_REQUEST: '.print_r($_REQUEST, TRUE)); if ($_SERVER['REQUEST_METHOD'] === 'GET') { log_message('debug', 'controllers.HAuth.endpoint: the request method is GET, copying REQUEST array into GET array.'); $_GET = $_REQUEST; } log_message('debug', 'controllers.HAuth.endpoint: loading the original HybridAuth endpoint script.'); require_once ADDONPATH.'/users/third_party/hybridauth/index.php'; //ADDONPATH is my modules path } } </code></pre> <p>i hope that you can find it useful. am using the ion_auth for the main login system. the auth_model is a small model which check if the user has enabled this provider with name or not, since i want the user to have the same data even if he use another social network to login with ..</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload