Example #1
0
 public function authenticate(array $credentials)
 {
     list($username, $password) = $credentials;
     $user = $this->model->getByNameOrEmail($username);
     if (!$user) {
         throw new AuthenticationException('User not found.', self::IDENTITY_NOT_FOUND);
     }
     if (!$this->passwordStrategy->matchPassword($user, $password)) {
         throw new AuthenticationException('Invalid password.', self::INVALID_CREDENTIAL);
     }
     return new Identity($user->getId(), $this->model->getRoles($user));
 }
Example #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($input->hasOption('password') && $input->getOption('password') === NULL) {
         $output->writeln('<error>Please enable interactive mode to set password.</error>');
         return 1;
     }
     if ($input->hasOption('password') && $input->getOption('generate-password')) {
         $output->writeln('<error>Cannot set and generate password at once.</error>');
         return 1;
     }
     if (!$input->hasOption('password') && !$input->getOption('generate-password')) {
         $output->writeln('<error>Cannot create user without password.</error>');
         return 1;
     }
     $name = $input->getArgument('name');
     if ($this->model->getByNameOrEmail($name)) {
         $output->writeln('<error>User with same name already exists.</error>');
         return 1;
     }
     $email = $input->getArgument('email');
     if (!Validators::is($email, 'email')) {
         $output->writeln('<error>Invalid email</error>');
         return 1;
     }
     if ($this->model->getByNameOrEmail($email)) {
         $output->writeln('<error>User with same email already exists.</error>');
         return 1;
     }
     $printPassword = FALSE;
     if ($input->getOption('password') !== NULL) {
         $password = $input->getOption('password');
     } elseif ($this->getOption('generate-password')) {
         $password = Strings::random();
         $printPassword = TRUE;
     }
     $roles = $input->getOption('role');
     $this->factory->create($name, $email, $password, $roles);
     if ($printPassword) {
         $verbosity = $output->getVerbosity();
         $output->setVerbosity(OutputInterface::VERBOSITY_NORMAL);
         $output->write('<info>');
         $output->write($password, OutputInterface::OUTPUT_RAW);
         $output->writeln('</info>');
         $output->setVerbosity($verbosity);
     }
 }