public function validate($value, Constraint $constraint)
 {
     if ($value != "") {
         if (0 === preg_match("#^[0-9]*\$#", $value)) {
             $this->context->addViolation($constraint->message);
         } else {
             /*
              * Test if the user name really exists.
              */
             $facebook = new FacebookPictureFinder($value);
             try {
                 $facebook->getPictureUrl();
             } catch (\Exception $e) {
                 $this->context->addViolation($constraint->message);
             }
         }
     }
 }
示例#2
0
 /**
  * @param RZ\Roadiz\Core\Entities\User $user
  */
 private function updateProfileImage(User $user)
 {
     if ($user->getFacebookName() != '') {
         try {
             $facebook = new FacebookPictureFinder($user->getFacebookName());
             $url = $facebook->getPictureUrl();
             $user->setPictureUrl($url);
         } catch (\Exception $e) {
             $url = "http://www.gravatar.com/avatar/" . md5(strtolower(trim($user->getEmail()))) . "?d=identicon&s=200";
             $user->setPictureUrl($url);
             throw new FacebookUsernameNotFoundException($this->getTranslator()->trans('user.facebook_name.%name%._does_not_exist', ['%name%' => $user->getFacebookName()]), 1);
         }
     } else {
         $url = "http://www.gravatar.com/avatar/" . md5(strtolower(trim($user->getEmail()))) . "?d=identicon&s=200";
         $user->setPictureUrl($url);
     }
 }
示例#3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->questionHelper = $this->getHelperSet()->get('question');
     $this->entityManager = $this->getHelperSet()->get('em')->getEntityManager();
     $text = "";
     $name = $input->getArgument('username');
     if ($name) {
         $user = $this->entityManager->getRepository('RZ\\Roadiz\\Core\\Entities\\User')->findOneBy(['username' => $name]);
         if ($user !== null) {
             if ($input->getOption('enable')) {
                 if ($user !== null && $user->setEnabled(true)) {
                     $this->entityManager->flush();
                     $text = '<info>User enabled…</info>' . PHP_EOL;
                 } else {
                     $text = '<error>Requested user is not setup yet…</error>' . PHP_EOL;
                 }
             } elseif ($input->getOption('disable')) {
                 if ($user !== null && $user->setEnabled(false)) {
                     $this->entityManager->flush();
                     $text = '<info>User disabled…</info>' . PHP_EOL;
                 } else {
                     $text = '<error>Requested user is not setup yet…</error>' . PHP_EOL;
                 }
             } elseif ($input->getOption('delete')) {
                 $confirmation = new ConfirmationQuestion('<question>Do you really want to delete user “' . $user->getUsername() . '”?</question>', false);
                 if ($user !== null && $this->questionHelper->ask($input, $output, $confirmation)) {
                     $this->entityManager->remove($user);
                     $this->entityManager->flush();
                     $text = '<info>User deleted…</info>' . PHP_EOL;
                 } else {
                     $text = '<error>Requested user is not setup yet…</error>' . PHP_EOL;
                 }
             } elseif ($input->getOption('picture')) {
                 if ($user !== null) {
                     $facebook = new FacebookPictureFinder($user->getFacebookName());
                     if (false !== ($url = $facebook->getPictureUrl())) {
                         $user->setPictureUrl($url);
                         $this->entityManager->flush();
                         $text = '<info>User profile pciture updated…</info>' . PHP_EOL;
                     }
                 } else {
                     $text = '<error>Requested user is not setup yet…</error>' . PHP_EOL;
                 }
             } elseif ($input->getOption('regenerate')) {
                 if ($user !== null && $this->questionHelper->askConfirmation($output, '<question>Do you really want to regenerate user “' . $user->getUsername() . '” password?</question> : ', false)) {
                     $passwordGenerator = new PasswordGenerator();
                     $user->setPlainPassword($passwordGenerator->generatePassword(12));
                     $user->getHandler()->encodePassword();
                     $this->entityManager->flush();
                     $text = '<info>User password regenerated…</info>' . PHP_EOL;
                     $text .= 'Password: <info>' . $user->getPlainPassword() . '</info>' . PHP_EOL;
                 } else {
                     $text = '<error>Requested user is not setup yet…</error>' . PHP_EOL;
                 }
             } elseif ($input->getOption('add-roles') && $user !== null) {
                 $text = '<info>Adding roles to ' . $user->getUsername() . '</info>' . PHP_EOL;
                 foreach ($input->getOption('add-roles') as $role) {
                     $user->addRole(RolesBag::get($role));
                     $text .= '<info>Role: ' . $role . '</info>' . PHP_EOL;
                 }
                 $this->entityManager->flush();
             } else {
                 $text = '<info>' . $user . '</info>' . PHP_EOL;
             }
         } else {
             if ($input->getOption('create')) {
                 $this->executeUserCreation($name, $input, $output);
             } else {
                 $text = '<error>User “' . $name . '” does not exist… use --create to add a new user.</error>' . PHP_EOL;
             }
         }
     } else {
         $text = '<info>Installed users…</info>' . PHP_EOL;
         $users = $this->entityManager->getRepository('RZ\\Roadiz\\Core\\Entities\\User')->findAll();
         if (count($users) > 0) {
             $text .= ' | ' . PHP_EOL;
             foreach ($users as $user) {
                 $text .= ' |_ ' . $user->getUsername() . ' — <info>' . ($user->isEnabled() ? 'enabled' : 'disabled') . '</info>' . ' — <comment>' . implode(', ', $user->getRoles()) . '</comment>' . PHP_EOL;
             }
         } else {
             $text = '<info>No available users</info>' . PHP_EOL;
         }
     }
     $output->writeln($text);
 }
示例#4
0
 /**
  * @param RZ\Roadiz\Core\Entities\User $user
  */
 private function updateProfileImage(User $user)
 {
     if ($user->getFacebookName() != '') {
         try {
             $facebook = new FacebookPictureFinder($user->getFacebookName());
             $url = $facebook->getPictureUrl();
             $user->setPictureUrl($url);
         } catch (\Exception $e) {
             $user->setPictureUrl(static::getGravatarUrl($user->getEmail()));
         }
     } else {
         $user->setPictureUrl(static::getGravatarUrl($user->getEmail()));
     }
 }