Esempio n. 1
0
 /**
  * @param \nodge\eauth\ServiceBase $service
  * @return User
  * @throws ErrorException
  */
 public static function findByEAuth($service)
 {
     if (!$service->getIsAuthenticated()) {
         throw new ErrorException('EAuth user should be authenticated before creating identity.');
     }
     $id = $service->getServiceName() . '-' . $service->getId();
     $attributes = array('id' => $id, 'username' => $service->getAttribute('name'), 'authKey' => md5($id), 'profile' => $service->getAttributes());
     $attributes['profile']['service'] = $service->getServiceName();
     Yii::$app->getSession()->set('user-' . $id, $attributes);
     return new self($attributes);
 }
Esempio n. 2
0
 /**
  * @param \nodge\eauth\ServiceBase $service
  * @return User
  * @throws ErrorException
  */
 public static function findByEAuth($service)
 {
     if (!$service->getIsAuthenticated()) {
         throw new ErrorException('EAuth user should be authenticated before creating identity.');
     }
     $id = $service->getServiceName() . '-' . $service->getId();
     $attributes = ['id' => $id, 'steamid' => $service->getAttribute('steamid'), 'username' => $service->getAttribute('username'), 'profile_url' => $service->getAttribute('profile_url'), 'avatar' => $service->getAttribute('avatar'), 'avatar_md' => $service->getAttribute('avatar_md'), 'avatar_lg' => $service->getAttribute('avatar_lg')];
     Yii::$app->getSession()->set('user-' . $id, $attributes);
     return new self($attributes);
 }
Esempio n. 3
0
 /**
  * @param \nodge\eauth\ServiceBase $service
  * @return User
  * @throws ErrorException
  */
 public static function findByEAuth($service)
 {
     if (!$service->getIsAuthenticated()) {
         throw new ErrorException('EAuth user should be authenticated before creating identity.');
     }
     $user = self::find()->where(['eauth_service' => $service->getServiceName(), 'eauth_id' => $service->getId()])->one();
     if ($user == null) {
         // print_r($service->attributes);
         // exit;
         $username = $service->getAttribute('username');
         $username = $username ? $username : "******" . $service->getId();
         $user = new User(['username' => $username, 'password' => Yii::$app->security->generateRandomString(6), 'status' => self::STATUS_ACTIVE, 'name' => $service->getAttribute('name') ? $service->getAttribute('name') : $service->getAttribute('username'), 'email' => $service->getAttribute('email'), 'eauth_service' => (string) $service->getServiceName(), 'eauth_id' => (string) $service->getId()]);
         $user->generateAuthKey();
         $user->save();
     }
     return $user;
 }
Esempio n. 4
0
 /**
  * @param \nodge\eauth\ServiceBase $service
  * @return User
  * @throws ErrorException
  */
 public static function findByEAuth($service)
 {
     if (!$service->getIsAuthenticated()) {
         throw new ErrorException('Авторизован.');
     }
     /**
      * @var $social    UserSocial
      * @var $socialOth UserSocial
      */
     $email = $service->getAttribute('email');
     $social = UserSocial::findOne(['service' => $service->getServiceName(), 'service_id' => "{$service->getId()}"]);
     if ($social) {
         return $social->user;
     }
     $socialOth = $email ? UserSocial::findOne(['email' => $email]) : false;
     $user = User::findOne(['email' => $email]);
     if (!$user) {
         if (!$socialOth) {
             $user = new static(['username' => $service->getAttribute('name'), 'email' => $email, 'auth_key' => Yii::$app->security->generateRandomString()]);
             $user->insert(false);
         } else {
             $user = $socialOth->user;
         }
     }
     $social = new UserSocial(['service' => $service->getServiceName(), 'service_id' => $service->getId(), 'user_id' => $user->id, 'email' => $user->email]);
     $social->insert(false);
     return $user;
 }
Esempio n. 5
0
File: User.php Progetto: h11Nox/slug
 /**
  * @param \nodge\eauth\ServiceBase $service
  * @return User
  * @throws ErrorException
  */
 public static function findByEAuth($service)
 {
     if (!$service->getIsAuthenticated()) {
         throw new ErrorException('EAuth user should be authenticated before creating identity.');
     }
     $user = static::find()->where('service = :service AND service_id = :ID', [':service' => $service->getServiceName(), ':ID' => $service->getAttribute('id')])->one();
     if (!$user) {
         $photo = $service->getServiceName() === 'vkontakte' ? $service->getAttribute('photo_big') : "https://graph.facebook.com/{$service->getAttribute('id')}/picture?type=large";
         $user = new static(['username' => $service->getAttribute('name'), 'service' => $service->getServiceName(), 'service_id' => $service->getAttribute('id'), 'img' => $photo]);
         $user->save();
     }
     $id = $service->getServiceName() . '-' . $service->getId();
     $attributes = array_merge($user->getAttributes(['id', 'username', 'img', 'rating']), ['id' => $id, 'auth_key' => md5($id), 'cid' => $user->id]);
     Yii::$app->getSession()->set('user-' . $id, $attributes);
     return new self($attributes);
 }
 /**
  * Finds user by \nodge\eauth\ServiceBase eauth service.
  * 
  * @param \nodge\eauth\ServiceBase $service
  * 
  * @return object ServiceUser
  * 
  * @throws ErrorException
  */
 public static function findByEAuth($service)
 {
     if (!$service->getIsAuthenticated()) {
         throw new ErrorException('EAuth user should be authenticated before creating identity.');
     }
     $identity = static::findIdentity(['service_name' => $service->getServiceName(), 'service_user_id' => $service->getId()]);
     if ($identity instanceof \yii\web\IdentityInterface) {
         $identity->username = $service->getAttribute('username');
         $identity->access_token = $service->getAttribute('access_token');
         $identity->avatar_url = $service->getAttribute('avatar_url');
         $identity->save();
     }
     return $identity;
 }