示例#1
0
 protected function startup()
 {
     parent::startup();
     $this->user->getStorage()->setNamespace('user');
     if ($this->user->isLoggedIn()) {
         $this->me = $this->userFacade->find($this->user->getId());
     }
 }
示例#2
0
 public function createUser($nick, $email, $password)
 {
     $user = new \User();
     $hash = password_hash($password, PASSWORD_BCRYPT);
     $user->setNick($nick)->setEmail($email)->setPassword($hash);
     $this->dm->persist($user);
     $token = new \RegistrationToken(sha1($user->getEmail() . time()));
     $token->setUser($user);
     $this->dm->persist($token);
     try {
         $this->dm->flush($user, ['safe' => TRUE]);
     } catch (\MongoCursorException $e) {
         if (strpos($e->getMessage(), $nick) !== false) {
             throw new \ExistingUserException(sprintf('User with nick %s already exists ', $nick));
         } elseif (strpos($e->getMessage(), $email) !== false) {
             throw new \ExistingUserException(sprintf('User with email %s already exists ', $email));
         }
     }
 }
示例#3
0
 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     $output->writeln('creating new user...');
     $dialog = new Console\Helper\DialogHelper();
     $nick = $input->getArgument('nick');
     $email = $input->getArgument('email');
     $password = $input->getArgument('password');
     if ($nick === NULL) {
         $nick = $dialog->ask($output, '<question>please provide nick for the new user: </question>', NULL);
         if ($nick === NULL) {
             $output->writeln('<error>you have to provide nick. aborting.</error>');
             return;
         }
         $password = $dialog->ask($output, '<question>please provide password for the user ' . $nick . ': </question>', NULL);
         if ($password === NULL) {
             $output->writeln('<error>you have to provide password. aborting.</error>');
             return;
         }
     }
     if ($email === NULL) {
         $email = $dialog->ask($output, '<question>please provide email for the new user: </question>', NULL);
         if ($email === NULL) {
             $output->writeln('<error>you have to provide email. aborting.</error>');
             return;
         }
     }
     if ($nick !== NULL and $password === NULL) {
         $password = $dialog->ask($output, '<question>please provide password for the user ' . $nick . ': </question>', NULL);
         if ($password === NULL) {
             $output->writeln('<error>you have to provide password. aborting.</error>');
             return;
         }
     }
     $this->userFacade->createUser($nick, $email, $password);
     $output->writeln('<info>user ' . $nick . ' succesfully created</info>');
 }