/** * Create a user with the provided username. * * @param string $username * * @return UserInterface $user */ protected function createUser($username) { if (!$this->userProvider instanceof UserFactoryInterface) { throw new AuthenticationServiceException("UserProvider must implement UserFactoryInterface to create unknown users."); } $user = $this->userProvider->createUser($username); if (!$user instanceof UserInterface) { throw new AuthenticationServiceException("The user provider must return a UserInterface object."); } return $user; }
/** * @throws AuthenticationServiceException * * @param string $username * @param array $attributes * * @return UserInterface */ protected function createUser($username, array $attributes = array()) { if (!$this->userProvider instanceof UserFactoryInterface) { throw new AuthenticationServiceException('UserProvider must implement UserFactoryInterface to create unknown users.'); } try { $user = $this->userProvider->createUser($username, $this->createdUsersRoles, $attributes); if (!$user instanceof UserInterface) { throw new AuthenticationServiceException('The user provider must create an UserInterface object.'); } } catch (\Exception $repositoryProblem) { throw new AuthenticationServiceException($repositoryProblem->getMessage(), $username, 0, $repositoryProblem); } return $user; }
/** * Creates a new User. * * @param array $data * @param bool $isOAuth * * @return UserInterface $user */ protected function createUser(array $data, UserProviderInterface $userManager) { $userIdentityfield = $this->container->getParameter('rch_jwt_user.user_identity_field'); $user = $userManager->createUser()->setUsername($data[$userIdentityfield])->setEmail($data[$userIdentityfield])->setEnabled(true)->setPlainPassword($data['password']); if (isset($data['facebook_id'])) { $user->setFacebookId($data['facebook_id']); } try { $userManager->updateUser($user); } catch (\Exception $e) { $message = $e->getMessage() ?: 'An error occured while creating the user.'; throw new UserException(422, $message, $e); } return $user; }