-
Notifications
You must be signed in to change notification settings - Fork 35
Setting fields before saving user data #38
Comments
There is one possibility to specify some User model attributes in action property attributes. But this helps only with static value, e.g. status => 1 for all new users. When you to change some attributes according to the user's social profile, for now, you can only use And another variant could be with edition of User model and using beforeSave() method. For example you already have public function actions()
{
...
'attributes' => array(
'socialCountry' => 'country',
),
...
} Than in your model: public function setSocialCountry($country)
{
$mainland = $this->mainlandByCountry($country);
$this->timezone = $mainland.'/'.$country; // here is timezone setting
$countryModel = Country::model()->findByAttributes(array('name' => $country));
$this->country_id = $countryModel ? $countryModel->primaryKey : new CDbExpression('NULL');
} so you even need no when you need, I can also add one more callback that will be called before user's model saving. |
Sorry for my late response. Thank you for such detailed explanation. Very helpful indeed, but the country value that was returned from social network was empty. It may be related to this issue. |
Is it possible to set |
@re1naldo, it should be actually called. see this function: https://github.com/SleepWalker/hoauth/blob/master/HOAuthAction.php#L440 . So all You have some more options:
|
Please correct me if I am wrong, but if I saw this line (https://github.com/SleepWalker/hoauth/blob/master/HOAuthAction.php#L463), user attribute will only be set when profile data is not empty, won't it? As Anyway, thanks for mentioning |
oh, yes. You are right, sorry.
yes. that's right too |
Ok. Thanks for the clarification. |
Is it possible to set certain fields (like timezone, country, etc.) to related User model before hoauth saves User data? For example, when user registers using Facebook account, application could retrieve various data from his Facebook account and save it to User model.
If it is possible, where should we place the code? I saw we only have 2 callbacks (i.e. hoauthAfterLogin and hoauthCheckAccess) and User model has been created when they are called.
The text was updated successfully, but these errors were encountered: