예제 #1
0
 /**
  * Sends an identity cookie.
  * This method is used when [[enableAutoLogin]] is true.
  * It saves [[id]], [[IdentityInterface::getAuthKey()|auth key]], and the duration of cookie-based login
  * information in the cookie.
  * @param IdentityInterface $identity
  * @param integer $duration number of seconds that the user can remain in logged-in status.
  * @see loginByCookie()
  */
 protected function sendIdentityCookie($identity, $duration)
 {
     $cookie = new Cookie($this->identityCookie);
     $cookie->value = json_encode([$identity->getId(), $duration], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
     $cookie->expire = time() + $duration;
     Yii::$app->getResponse()->getCookies()->add($cookie);
 }
 /**
  * Update relations between Identity entity and Contact Device entity
  *
  * @param IdentityInterface $model
  */
 protected function updateIdentityContactDeviceRelations($model)
 {
     foreach ($model->getContactDevices() as $identity_contact_device) {
         if (is_null($identity_contact_device->getId())) {
             $contact_device = $this->container->get('asf_contact.contact_device.manager')->createTypedInstance($identity_contact_device->getContactDevice()->getType());
             $contact_device->setType($identity_contact_device->getContactDevice()->getType())->setLabel($identity_contact_device->getContactDevice()->getLabel())->setValue($identity_contact_device->getContactDevice()->getValue());
             $identity_contact_device->setContactDevice($contact_device);
         }
     }
     $contact_devices = array();
     $form_identity_contact_devices = $model->getContactDevices();
     foreach ($form_identity_contact_devices as $identity_contact_device) {
         if (!isset($contact_devices[$identity_contact_device->getContactDevice()->getId()])) {
             $contact_devices[$identity_contact_device->getContactDevice()->getId()] = 1;
         } else {
             $model->removeAddress($identity_contact_device);
         }
     }
     // Detecte relations removed
     $relations = $this->container->get('asf_contact.identity_contact_device.manager')->getRepository()->findBy(array('identity' => $model->getId()));
     foreach ($relations as $relation) {
         $found = false;
         foreach ($model->getContactDevices() as $identity_contact_device) {
             if ($relation->getContactDevice()->getId() == $identity_contact_device->getContactDevice()->getId()) {
                 $found = true;
             }
         }
         if (false === $found) {
             $this->container->get('asf_contact.identity.manager')->getEntityManager()->remove($relation);
         }
     }
     // Detect new relations
     foreach ($model->getContactDevices() as $identity_contact_devices) {
         $found = false;
         foreach ($relations as $relation) {
             if ($relation->getContactDevice()->getId() == $identity_contact_devices->getContactDevice()->getId()) {
                 $found = true;
             }
         }
         if (false === $found) {
             $identity_contact_devices->setIdentity($model);
             $this->container->get('asf_contact.identity.manager')->getEntityManager()->persist($identity_contact_devices);
         }
     }
 }