Пример #1
0
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $services = $serviceLocator->getServiceLocator();
     $user = $services->get('AuthenticationService')->getUser();
     $fieldset = new UserInfoFieldset();
     $imageEntity = new UserImage();
     $imageEntity->setUser($user);
     $strategy = new FileUploadStrategy($imageEntity);
     $hydrator = new EntityHydrator();
     $hydrator->addStrategy('image', $strategy);
     $fieldset->setHydrator($hydrator);
     return $fieldset;
 }
Пример #2
0
 /**
  * {@inheritdoc}
  *
  *
  * @see \Zend\Authentication\Adapter\AdapterInterface::authenticate()
  */
 public function authenticate()
 {
     $hybridAuth = $this->getHybridAuth();
     /* @var $adapter \Hybrid_Provider_Model */
     $adapter = $hybridAuth->authenticate($this->_provider);
     $userProfile = $adapter->getUserProfile();
     $email = isset($userProfile->emailVerified) && !empty($userProfile->emailVerified) ? $userProfile->emailVerified : $userProfile->email;
     $forceSave = false;
     $user = $this->getRepository()->findByProfileIdentifier($userProfile->identifier);
     if (!$user) {
         $forceSave = true;
         $user = $this->getRepository()->create();
     }
     $currentInfo = $user->getProfile();
     $newInfo = (array) $userProfile;
     if ($forceSave || $currentInfo != $newInfo) {
         /*  */
         $dm = $this->getRepository()->getDocumentManager();
         if ('' == $user->getInfo()->email) {
             $user->getInfo()->email = $email;
         }
         $user->getInfo()->firstName = $userProfile->firstName;
         $user->getInfo()->lastName = $userProfile->lastName;
         $user->getInfo()->birthDay = $userProfile->birthDay;
         $user->getInfo()->birthMonth = $userProfile->birthMonth;
         $user->getInfo()->birthYear = $userProfile->birthYear;
         $user->getInfo()->postalcode = $userProfile->zip;
         $user->getInfo()->city = $userProfile->city;
         $user->getInfo()->street = $userProfile->address;
         $user->getInfo()->phone = $userProfile->phone;
         $user->getInfo()->gender = $userProfile->gender;
         $user->setLogin($email);
         $user->setProfile($newInfo);
         $dm->persist($user);
         // make sure all ids are generated and user exists in database.
         $dm->flush();
         /*
          * This must be after flush because a newly created user has no id!
          */
         if ($forceSave || !$user->getInfo()->image && $userProfile->photoURL) {
             // get user image
             if ('' != $userProfile->photoURL) {
                 $client = new \Zend\Http\Client($userProfile->photoURL, array('sslverifypeer' => false));
                 $response = $client->send();
                 $file = new GridFSFile();
                 $file->setBytes($response->getBody());
                 $userImage = new UserImage();
                 $userImage->setName($userProfile->lastName . $userProfile->firstName);
                 $userImage->setType($response->getHeaders()->get('Content-Type')->getFieldValue());
                 $userImage->setUser($user);
                 $userImage->setFile($file);
                 $user->getInfo()->setImage($userImage);
                 $dm->persist($userImage);
                 //$this->getRepository()->store($user->info);
             }
             // We have to flush again
             $dm->flush();
         }
     }
     return new Result(Result::SUCCESS, $user->getId(), array('firstLogin' => $forceSave, 'user' => $user));
 }