Thank you, My biggest problem now is A) lack of time, I developed my user system for one app and its still pretty tight to that app, meaning If I moved it all to another app I would get a shitload of tiny errors like missing variables etc. So I have to clear all this outh.
I updated the method workOnUser in DefaultController
Now if a Yii user is already logged in, the provider is connected to that user.
This way a user can have multiple provider accounts connected to the same yii-user.
public function workOnUser($provider,$provideruser){
$social = Social::model()->find("provider='".$provider."' AND provideruser='".$provideruser."'");
if ( $social ){
$user = User::model()->find("id=".$social->yiiuser);
return $user;
}else{ // no user is connected to that provideruser,
$social = new Social; // a new relation will be needed
$social->provider = $provider; // what provider
$social->provideruser = $provideruser; // the unique user
// if a yii-user is already logged in add the provideruser to that account
if ( !Yii::app()->user->isGuest ){
$social->yiiuser = Yii::app()->user->id;
$user = User::model()->findByPk(Yii::app()->user->id);
}else{
// we want to create a new user
$user = new User;
$user->username = $provideruser;
if ( $user->save() ){ //we get an user id
$social->yiiuser = $user->id;
}
}
if($social->save())
return $user;
}
}
And sample code to put on the profile view to show the providers that is connected to that user and allow him to connect more:
<h4> By connecting a social provider to your account you can use it to login<h4>
<?php $socials = Social::model()->findAll('yiiuser='.$model->id);
if($socials){
echo "<h5>You have currently connected your account with:</h5>";
foreach($socials as $social){
echo "* <b>".$social->provider."</b><br/>";
}
}
$this->widget('LoginWidget');//displays the possible providers
?>
I put a check for that in the updateStatus method in Yiiauth component (inside the module).
So if you run $this->updateStatus($provider,$status); it will check if $provider is in that array you showed, if it is it will set the user status to $status. So you do not have to worry about that.
The array for providers you would like to use, is set in the config, how to configure it is shown on the hybridauth info page. i strongly recommend to read that:)
The second line is error because of the first error, and I dont know why that line would give you an error if the login works, that same Yii::app()->controller->module->config is ran on login to… hmm
Ah, It didnt work for me either first, I found I had typo.
At approximately line 145
public function updateStatus($provider,$status){
$this->newAuth();
//Change to
public function updateStatus($provider,$status){
$hybridauth = $this->newAuth();