public function afterSave($insert, $changedAttributes) { if (!$insert) { $accounts = []; $accounts[$this->provider] = $this; User::assignRazz(new User(), $accounts); } parent::afterSave($insert, $changedAttributes); }
public function authenticate($client) { $attributes = $client->getUserAttributes(); $provider = $client->getId(); $clientId = $attributes['id']; $account = $this->finder->findAccountByProviderAndClientId($provider, $clientId); //var_dump($client->getAccessToken()->params['access_token']);die; if ($account === null) { $account = \Yii::createObject(['class' => Account::className(), 'provider' => $provider, 'client_id' => $clientId, 'data' => json_encode($attributes), 'token' => $client->getAccessToken()->params['access_token']]); $account->save(false); } if (null === ($user = $account->user)) { $this->action->successUrl = Url::to(['/user/registration/connect', 'account_id' => $account->id]); } else { \Yii::$app->user->login($user, $this->module->rememberFor); } }
/** * Tries to authenticate user via social network. If user has already used * this network's account, he will be logged in. Otherwise, it will try * to create new user account. * * @param ClientInterface $client */ public function authenticate(ClientInterface $client) { $account = $this->finder->findAccount()->byClient($client)->one(); if ($account === null) { $account = Account::create($client); } if ($account->user instanceof User) { if ($account->user->isBlocked) { Yii::$app->session->setFlash('danger', Yii::t('user', 'Your account has been blocked.')); $this->action->successUrl = Url::to(['/user/security/login']); } else { if ($account->user->esActivo) { Yii::$app->user->login($account->user, $this->module->rememberFor); $this->action->successUrl = Yii::$app->getUser()->getReturnUrl(); } } } else { $this->action->successUrl = $account->getConnectUrl(); } }
public function authenticate(ClientInterface $client) { $attributes = $client->getUserAttributes(); $provider = $client->getId(); $clientId = $attributes['id']; $account = $this->finder->findAccountByProviderAndClientId($provider, $clientId); if ($account === null) { $account = \Yii::createObject(['class' => Account::className(), 'provider' => $provider, 'client_id' => $clientId, 'data' => json_encode($attributes)]); $account->save(false); } if (null === ($user = $account->user)) { if ($provider == 'kd') { $this->action->successUrl = Url::to(['/user/registration/connect', 'account_id' => $account->id, 'provider' => $provider, 'username' => $attributes['username'], 'email' => $attributes['email']]); } else { $this->action->successUrl = Url::to(['/user/registration/connect', 'account_id' => $account->id]); } } else { \Yii::$app->user->login($user, $this->module->rememberFor); } }
public function searchAccountFrends() { $accounts = Account::findAll(['user_id' => Yii::$app->user->id]); $response = ''; // $curl= new Curl(); foreach ($accounts as $account) { if ($account->provider == 'vkontakte') { $params = ['user_id' => $account->client_id, 'fields' => 'nickname, domain, sex, bdate, city, country, timezone, photo_50, photo_100, photo_200_orig, has_mobile, contacts, education, online, relation, last_seen, status, can_write_private_message, can_see_all_posts, can_post, universities', 'name_case' => 'nom']; $response[$account->provider] = json_decode($this->getPost('https://api.vk.com/method/friends.get', $params), true)['response']; // var_dump($response); } if ($account->provider == 'odnoklassniki') { $o = new Odnoklassniki(); // var_dump($o);die; var_dump($o->getFrends()); die; } } return $response; }
/** * Tries to connect social account to user. * * @param ClientInterface $client */ public function connect(ClientInterface $client) { /** @var Account $account */ $account = Yii::createObject(Account::className()); $account->connectWithUser($client); $this->action->successUrl = Url::to(['/user/settings/networks']); }
/** * Tries to connect social account to user. * * @param ClientInterface $client */ public function connect(ClientInterface $client) { /** @var Account $account */ $account = Yii::createObject(Account::className()); $event = $this->getAuthEvent($account, $client); $this->trigger(self::EVENT_BEFORE_CONNECT, $event); $account->connectWithUser($client); $this->trigger(self::EVENT_AFTER_CONNECT, $event); $this->action->successUrl = Url::to(['/user/settings/networks']); }
/** * Connects social account to user. * @param ClientInterface $client * @return \yii\web\Response */ public function connect(ClientInterface $client) { $attributes = $client->getUserAttributes(); $provider = $client->getId(); $clientId = $attributes['id']; $account = $this->finder->findAccountByProviderAndClientId($provider, $clientId); if ($account === null) { $account = \Yii::createObject(['class' => Account::className(), 'provider' => $provider, 'client_id' => $clientId, 'data' => json_encode($attributes), 'user_id' => \Yii::$app->user->id]); $account->save(false); \Yii::$app->session->setFlash('success', \Yii::t('user', 'Your account has been connected')); } else { if (null == $account->user) { $account->user_id = \Yii::$app->user->id; $account->save(false); } else { \Yii::$app->session->setFlash('error', \Yii::t('user', 'This account has already been connected to another user')); } } $this->action->successUrl = Url::to(['/user/settings/networks']); }
public static function connectUser($client_id, $token, $secret, $email = null, $name = null) { $accessToken = Yii::createObject(['class' => 'yii\\authclient\\OAuthToken', 'token' => $token, 'tokenSecret' => $secret]); $client = Yii::$app->authClientCollection->getClient($client_id); $client->accessToken = $accessToken; $account = Account::createFromClient($client); $clientData = $client->userAttributes; if ($account['id'] && !$account['user_id']) { if (!$email) { throw new HttpException(401, 'Invalid user mail'); } else { $user = Yii::createObject(['class' => User::className(), 'scenario' => 'create', 'email' => $email]); if ($user->create()) { $account->link('user', $user); } else { self::error($user); } } } if (!$account->user->profile->name) { if ($client->id == 'facebook' && isset($clientData['first_name']) && isset($clientData['last_name'])) { $account->user->profile->name = $clientData['first_name'] . ' ' . $clientData['last_name']; } elseif ($client->id == 'twitter' && isset($clientData['name'])) { $account->user->profile->name = $clientData['name']; } elseif ($name) { $account->user->profile->name = $name; } $account->user->profile->save(); } return $account->user; }
/** * @return \yii\db\ActiveQuery */ public function getAccounts() { return $this->hasMany(Account::className(), ['user_id' => 'id']); }