Esempio n. 1
0
File: User.php Progetto: ut8ia/iwet
 /**
  * @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.');
     }
     $service_id = $service->getServiceName() . '-' . $service->getId();
     // find user auth
     $user_auth = AuthRecords::find()->where(["id" => $service_id])->one();
     if (!isset($user_auth->user_id)) {
         $attributes = $service->getAttributes();
         $nameFromService = isset($attributes['name']) ? $attributes['name'] : null;
         // add user
         $model = new User();
         $model->username = $nameFromService ? $nameFromService : $service_id;
         $model->auth_key = md5($service_id);
         $model->password_hash = "asd" . rand(0, 1045693);
         //            $model->email = "";
         $model->save();
         $user_id = $model->id;
         // add auth
         $new_auth = new AuthRecords();
         $new_auth->id = $service_id;
         $new_auth->user_id = $user_id;
         $new_auth->attributes = serialize($service->getAttributes());
         $new_auth->save();
     } else {
         $user_id = $user_auth->user_id;
     }
     return user::findIdentity($user_id);
 }
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.');
     }
     $service_id = $service->getServiceName() . '-' . $service->getId();
     // find user auth
     $user_auth = AuthRecords::find()->where(["id" => $service_id])->one();
     // make new auth record and create user
     if (!isset($user_auth->user_id)) {
         $attributes = $service->getAttributes();
         $nameFromService = isset($attributes['name']) ? $attributes['name'] : null;
         // add user
         $model = new User();
         $model->username = $nameFromService ? $nameFromService : $service_id;
         $model->auth_key = md5($service_id);
         // set default pass for direct account access
         $password = $model->generatePass();
         $model->password_hash = Yii::$app->security->generatePasswordHash($password);
         $model->save();
         $user_id = $model->id;
         // add auth
         $new_auth = new AuthRecords();
         $new_auth->id = $service_id;
         $new_auth->user_id = $user_id;
         $new_auth->attributes = serialize($service->getAttributes());
         $new_auth->save();
     } else {
         $user_id = $user_auth->user_id;
     }
     return user::findIdentity($user_id);
 }
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.');
     }
     $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);
 }