本文整理匯總了PHP中app\models\Profile::socialSave方法的典型用法代碼示例。如果您正苦於以下問題:PHP Profile::socialSave方法的具體用法?PHP Profile::socialSave怎麽用?PHP Profile::socialSave使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\models\Profile
的用法示例。
在下文中一共展示了Profile::socialSave方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: findByEAuth
public static function findByEAuth($service)
{
if (!$service->getIsAuthenticated()) {
throw new ErrorException('Не можливо зареєструватися.');
}
$id = $service->getServiceName() . '-' . $service->getId();
/* echo '<pre>';
var_dump($service);die();
echo '</pre>'; */
/* if($service->getServiceName() == 'facebook'){
$email = '';
}elseif($service->getServiceName() == 'odnoklassniki'){
$email = '';
}elseif($service->getServiceName() == 'vkontakte'){
$email = $service->getAttribute('email') ? $service->getAttribute('email') : null;
} */
$attributes = array('social_id' => $id, 'username' => $service->getAttribute('name'), 'auth_key' => md5($id), 'profile' => $service->getAttributes());
$user = static::findOne(['social_id' => $id]);
if (isset($user->social_id)) {
$email = $user->email;
if ($email == '') {
$user->email = '';
$user->save(false);
}
if (strripos($email, '@site.com') !== false) {
if ($service->getServiceName() == 'odnoklassniki') {
$user->email = '';
} else {
$user->email = $service->getAttribute('email');
}
$user->save(false);
}
}
if (!isset($user->social_id)) {
$user = new User();
$user->social_id = $attributes['social_id'];
if (isset($attributes['email'])) {
$user->email = $attributes['email'];
}
$password_hash = $user->generate_password();
$user->setPassword($password_hash);
$user->role = 1;
$user->status = self::STATUS_ACTIVE;
$user->profile = json_encode($service->getAttributes());
$user->save(false);
Profile::socialSave($user, $service->getAttributes());
$user = static::findOne(['social_id' => $id]);
}
$user->profile = $service->getAttributes();
// $user->photoSoc = $service->getAttribute('photo');
self::$role = $user->role;
Yii::$app->user->login($user, 3600);
$attributes['profile']['service'] = $service->getServiceName();
Yii::$app->getSession()->set('user-' . $id, $attributes);
return new self($attributes);
}