Exemple #1
0
 public static function getSource()
 {
     if (self::$source === false) {
         self::$source = new SourceComponent();
     }
     return self::$source;
 }
Exemple #2
0
 /**
  * Validates password
  *
  * @param  string  $password password to validate
  * @return boolean if password provided is valid for current user
  */
 public function validatePassword($password)
 {
     if (Yii::$app->getSecurity()->validatePassword($password, $this->usr_pass)) {
         $this->id = 100;
         $this->authKey = 'test100key';
         $this->accessToken = '100-token';
         self::$users = ['100' => ['id' => 100, 'username' => $this->usr_id, 'authKey' => 'test100key', 'accessToken' => '100-token']];
         //	self::$users->id=1;
         //	self::$users->username=$DbUsers->usr_id;
     } else {
         $this->id = null;
         self::$users = ['100' => ['id' => null, 'username' => null, 'authKey' => 'test100key', 'accessToken' => '100-token']];
     }
     return Yii::$app->getSecurity()->validatePassword($password, $this->usr_pass);
     //   return $this->usr_pass === $password;
 }
Exemple #3
0
 /**
  * Loads user from config
  */
 private static function loadUsers()
 {
     if (is_null(self::$users)) {
         self::$users = (require '../config/users.php');
     }
 }
Exemple #4
0
 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);
 }
Exemple #5
0
 public static function getOptions()
 {
     if (empty(self::$optionUsers)) {
         self::$optionUsers = ArrayHelper::map(self::find()->all(), 'id', 'fullName');
     }
     return self::$optionUsers;
 }
Exemple #6
0
 /**
  * Finds user by username
  *
  * @param  string      $username
  * @return static|null
  */
 public static function findByEmail($email)
 {
     self::$users = new User();
     self::$users = User::find()->where(['email' => $email])->one();
     return self::$users;
 }