本文整理汇总了PHP中FOS\UserBundle\Model\UserManagerInterface::createUser方法的典型用法代码示例。如果您正苦于以下问题:PHP UserManagerInterface::createUser方法的具体用法?PHP UserManagerInterface::createUser怎么用?PHP UserManagerInterface::createUser使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FOS\UserBundle\Model\UserManagerInterface
的用法示例。
在下文中一共展示了UserManagerInterface::createUser方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* Creates a user and returns it.
*
* @param string $username
* @param string $password
* @param string $email
* @param bool $active
* @param bool $superadmin
*
* @return \FOS\UserBundle\Model\UserInterface
*/
public function create($username, $password, $email, $active, $superadmin)
{
$discriminator = $this->discriminator;
switch ($this->type) {
case 'staff':
$class = 'Truckee\\MatchBundle\\Entity\\Staff';
break;
case 'admin':
$class = 'Truckee\\MatchBundle\\Entity\\Admin';
break;
case 'volunteer':
$class = 'Truckee\\MatchBundle\\Entity\\Volunteer';
break;
default:
break;
}
$discriminator->setClass($class);
$user = $this->userManager->createUser();
$user->setUsername($username);
$user->setFirstname($this->firstname);
$user->setLastname($this->lastname);
$user->setEmail($email);
$user->setPlainPassword($password);
$user->setEnabled((bool) $active);
$this->userManager->updateUser($user, true);
return $user;
}
示例2: create
public function create()
{
/** @var User $user */
$user = $this->userManager->createUser();
$user->setPlainPassword(md5(rand(1000000, 9999999), false));
$user->setEnabled(true);
return $user;
}
示例3: createUserFromResponse
/**
* Create user from response
*
* @param UserResponseInterface $response
*
* @return User
*/
private function createUserFromResponse(UserResponseInterface $response)
{
/** @var User $user User */
$user = $this->userManager->createUser();
$user->setUsername($response->getUsername())->setFullName($response->getRealName())->setEmail($response->getEmail())->setEnabled(true)->setPlainPassword(uniqid())->setFacebookId($response->getUsername())->setFacebookAccessToken($response->getAccessToken());
$this->eventDispatcher->dispatch(AppEvents::FACEBOOK_USER_CONNECTED, new FacebookUserConnectedEvent($user));
$this->userManager->updateUser($user);
return $user;
}
示例4: create
/**
* Creates a user and returns it.
*
* @param string $username
* @param string $password
* @param string $email
* @param Boolean $active
* @param Boolean $superadmin
* @return \FOS\UserBundle\Model\UserInterface
*/
public function create($username, $password, $email, $active, $superadmin)
{
$user = $this->userManager->createUser();
$user->setUsername($username);
$user->setEmail($email);
$user->setPlainPassword($password);
$user->setEnabled((bool) $active);
$user->setSuperAdmin((bool) $superadmin);
$this->userManager->updateUser($user);
return $user;
}
示例5: create
/**
* Creates a user and returns it.
*
* @param string $email
* @param string $password
* @param string $fullname
* @param string $institution
* @param bool $active
* @param bool $superadmin
*
* @return User
*/
public function create($email, $password, $fullname, $institution, $active, $superadmin)
{
$user = $this->userManager->createUser();
$user->setEmail($email);
$user->setPlainPassword($password);
$user->setFullname($fullname);
$user->setInstitution($institution);
$user->setEnabled($active);
$user->setSuperAdmin($superadmin);
$this->userManager->updateUser($user);
return $user;
}
示例6: registerUser
/**
* @param $email
* @param $password
* @return \FOS\UserBundle\Model\UserInterface
* @throws ValidationException
*/
public function registerUser($email, $password)
{
$user = $this->userManager->createUser();
$user->setUsername($email);
$user->setEmail($email);
$user->setPlainPassword($password);
$user->setEnabled(true);
$errors = $this->validator->validate($user, null, array('registration'));
if ($errors->count() > 0) {
throw new ValidationException($errors);
}
$this->userManager->updateUser($user);
return UserDTO::withEntity($user);
}
示例7: create
/**
* Creates a user and returns it.
*
* @param string $username
* @param string $password
* @param string $email
* @param Boolean $active
* @param Boolean $superadmin
*
* @return \FOS\UserBundle\Model\UserInterface
*/
public function create($username, $password, $email, $active, $superadmin, $company, $legalSituation, $phoneNumber, $url)
{
$user = $this->userManager->createUser();
$user->setUsername($username);
$user->setEmail($email);
$user->setPlainPassword($password);
$user->setEnabled((bool) $active);
$user->setSuperAdmin((bool) $superadmin);
$user->setCompany($company);
$user->setLegalSituation($legalSituation);
$user->setPhoneNumber($phoneNumber);
$user->setUrl($url);
$this->userManager->updateUser($user);
return $user;
}
示例8: create
/**
* Creates a user and returns it.
*
* @param string $username
* @param string $password
* @param string $email
* @param string $name
* @param string $lastName
* @param bool $active
* @param bool $superadmin
*
* @return \FOS\UserBundle\Model\UserInterface
*/
public function create($username, $password, $email, $name, $lastName, $active, $superadmin, $changePassword)
{
$user = $this->userManager->createUser();
$user->setUsername($username);
$user->setEmail($email);
$user->setPlainPassword($password);
$user->setName($name);
$user->setLastName($lastName);
$user->setEnabled((bool) $active);
$user->setSuperAdmin((bool) $superadmin);
if ((bool) $changePassword) {
$user->setPasswordExpireAt(new \DateTime());
}
$this->userManager->updateUser($user);
return $user;
}
示例9: fixAnonymousUser
/**
* Fixes the user, Drupal does not provide a hook for anonymous user
*/
public function fixAnonymousUser()
{
global $user;
if (!$user || $user->uid != 0) {
return;
}
$user = $this->userManager->createUser()->fromDrupalUser($user);
}
示例10: createUserFromResponse
/**
* Create user from response
*
* @param UserResponseInterface $response
*
* @return User
*/
private function createUserFromResponse(UserResponseInterface $response)
{
$email = $response->getEmail() ?: $response->getUsername() . '@example.com';
/** @var User $user */
$user = $this->userManager->createUser();
$user->setEmail($email);
$user->setUsername($response->getNickname());
$user->setEnabled(true);
$user->setPlainPassword(uniqid());
$user->setGithubId($response->getUsername());
// Move to separate listener
if (in_array($response->getUsername(), $this->adminGitHubIds)) {
$user->addRole('ROLE_ADMIN');
}
$this->userManager->updateUser($user);
return $user;
}
示例11: create
/**
* Creates a user and returns it.
*
* @param string $username
* @param string $password
* @param string $email
* @param Boolean $active
* @param Boolean $superadmin
* @param array $userproperties
*
* @return \FOS\UserBundle\Model\UserInterface
*/
public function create($username, $password, $email, $active, $superadmin, $userproperties = null)
{
$user = $this->userManager->createUser();
$user->setUsername($username);
$user->setEmail($email);
$user->setPlainPassword($password);
$user->setEnabled((bool) $active);
$user->setSuperAdmin((bool) $superadmin);
if (!is_null($userproperties) && is_array($userproperties) && count($userproperties) > 0) {
foreach ($userproperties as $method => $value) {
if (method_exists($user, $method)) {
$user->{$method}($value);
}
}
}
$this->userManager->updateUser($user);
return $user;
}
示例12: process
/**
* @param \Hatimeria\ExtJSBundle\Parameter\ParameterBag $params
* @param mixed $user
* @return \Hatimeria\ExtJSBundle\Response\Form
*/
public function process($params, $user = null)
{
$validationGroup = 'Profile';
if (null === $user) {
$validationGroup = 'Registration';
$user = $this->um->createUser();
}
$options = array('data_class' => $this->userClass, 'validation_groups' => array($validationGroup));
$type = new UserFormType();
$type->setExtend($this->extensionCollector->getExtensions());
$form = $this->formFactory->create($type, $user, $options);
$form->bind($params->all());
$result = new Form($form);
if ($result->isValid()) {
$this->um->updateUser($user);
return $user;
}
return $result;
}
示例13: createPrincipal
/**
* Creates a new principal.
*
* This method receives a full path for the new principal. The mkCol object
* contains any additional webdav properties specified during the creation
* of the principal.
*
* @param string $path
* @param MkCol $mkCol
*/
public function createPrincipal($path, MkCol $mkCol)
{
// create new user
$username = str_replace('principal/', '', $path);
$user = $this->user_manager->createUser();
$user->setUsername($username);
$user->setForename($username);
$this->_em->persist($user);
$this->_em->flush();
}
示例14: loadUserByOAuthUserResponse
/**
* {@inheritDoc}
*/
public function loadUserByOAuthUserResponse(UserResponseInterface $response)
{
$userInfo = $this->getUserInfo($response);
$service = $response->getResourceOwner()->getName();
$user = $this->userManager->findUserBy(array("{$service}Id" => $userInfo['id']));
if ($user instanceof PersonInterface) {
$user = parent::loadUserByOAuthUserResponse($response);
$serviceName = $response->getResourceOwner()->getName();
$setter = 'set' . ucfirst($serviceName) . 'AccessToken';
$user->{$setter}($response->getAccessToken());
return $user;
}
$userInfo = $this->checkEmail($service, $userInfo);
$user = $this->userManager->createUser();
$this->setUserInfo($user, $userInfo, $service);
if ($userInfo['first_name']) {
$user->setFirstName($userInfo['first_name']);
}
if ($userInfo['family_name']) {
$user->setSurname($userInfo['family_name']);
}
if ($service === 'facebook') {
$this->setFacebookData($user, $response->getResponse());
}
$username = Uuid::uuid4()->toString();
if (!UsernameValidator::isUsernameValid($username)) {
$username = UsernameValidator::getValidUsername();
}
$availableUsername = $this->userManager->getNextAvailableUsername($username, 10, Uuid::uuid4()->toString());
$user->setUsername($availableUsername);
$user->setEmail($userInfo['email']);
$user->setPassword('');
$user->setEnabled(true);
$this->userManager->updateCanonicalFields($user);
/** @var ValidatorInterface $validator */
$validator = $this->container->get('validator');
/** @var ConstraintViolationList $errors */
$errors = $validator->validate($user, ['LoginCidadaoProfile']);
if (count($errors) > 0) {
foreach ($errors as $error) {
if ($error->getPropertyPath() === 'email' && method_exists($error, 'getConstraint') && $error->getConstraint() instanceof UniqueEntity) {
throw new DuplicateEmailException($service);
}
}
}
$form = $this->formFactory->createForm();
$form->setData($user);
$request = $this->container->get('request');
$eventResponse = new RedirectResponse('/');
$event = new FormEvent($form, $request);
$this->dispatcher->dispatch(FOSUserEvents::REGISTRATION_SUCCESS, $event);
$this->userManager->updateUser($user);
$this->dispatcher->dispatch(FOSUserEvents::REGISTRATION_COMPLETED, new FilterUserResponseEvent($user, $request, $eventResponse));
return $user;
}
示例15: create
/**
* Creates a new Resource from the given parameters.
*
* @param FormInterface $form
*
* @return Resource
*/
public function create(FormInterface $form)
{
$formData = $form->getData();
/** @var UserEntity $user */
$user = $this->userManager->createUser();
$user->setUsername($formData['username']);
$user->setEmail($formData['email']);
$user->setPlainPassword($formData['password']);
$user->setEnabled(true);
$this->userManager->updateUser($user);
return $this->createResourceFromUser($user);
}