本文整理汇总了PHP中FOS\UserBundle\Model\UserManagerInterface类的典型用法代码示例。如果您正苦于以下问题:PHP UserManagerInterface类的具体用法?PHP UserManagerInterface怎么用?PHP UserManagerInterface使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserManagerInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: techRegister
private function techRegister($form, $request, \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher, \FOS\UserBundle\Model\UserManagerInterface $userManager, $user)
{
$event = new FormEvent($form, $request);
$dispatcher->dispatch(FOSUserEvents::REGISTRATION_SUCCESS, $event);
$userManager->updateUser($user);
if (null === ($response = $event->getResponse())) {
$url = $this->container->get('router')->generate('fos_user_registration_confirmed');
$response = new RedirectResponse($url);
}
$dispatcher->dispatch(FOSUserEvents::REGISTRATION_COMPLETED, new FilterUserResponseEvent($user, $request, $response));
return $response;
}
示例2: 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;
}
示例3: postBind
public function postBind(DataEvent $event)
{
$user = $event->getForm()->getData();
if ($user instanceof UserInterface) {
$this->userManager->updateCanonicalFields($user);
}
}
示例4: __invoke
public function __invoke(Request $request)
{
if ($this->container->hasParameter('partkeepr.auth.allow_password_change') && $this->container->getParameter('partkeepr.auth.allow_password_change') === false) {
throw new PasswordChangeNotAllowedException();
}
$user = $this->userService->getUser();
if (!$request->request->has('oldpassword') && !$request->request->has('newpassword')) {
throw new \Exception('old password and new password need to be specified');
}
$FOSUser = $this->userManager->findUserByUsername($user->getUsername());
if ($FOSUser !== null) {
$encoder = $this->encoderFactory->getEncoder($FOSUser);
$encoded_pass = $encoder->encodePassword($request->request->get('oldpassword'), $FOSUser->getSalt());
if ($FOSUser->getPassword() != $encoded_pass) {
throw new OldPasswordWrongException();
}
$this->userManipulator->changePassword($user->getUsername(), $request->request->get('newpassword'));
} else {
if ($user->isLegacy()) {
if ($user->getPassword() !== md5($request->request->get('oldpassword'))) {
throw new OldPasswordWrongException();
}
$user->setNewPassword($request->request->get('newpassword'));
$this->userService->syncData($user);
} else {
throw new \Exception('Cannot change password for LDAP users');
}
}
$user->setPassword('');
$user->setNewPassword('');
return $user;
}
示例5: onSuccess
/**
* @param UserInterface $user
*/
protected function onSuccess(UserInterface $user)
{
if ($this->getNewPassword() != "") {
$user->setPlainPassword($this->getNewPassword());
}
$this->userManager->updateUser($user);
}
示例6: updateUserFields
/**
* This must be called on prePersist and preUpdate if the event is about a
* user.
*
* @param UserInterface $user
*/
protected function updateUserFields(UserInterface $user)
{
if (null === $this->userManager) {
$this->userManager = $this->container->get('fos_user.user_manager');
}
$this->userManager->updateCanonicalFields($user);
$this->userManager->updatePassword($user);
}
示例7: findUserByUsernameOrThrowException
/**
* Finds a user by his username and throws an exception if we can't find it.
*
* @param string $username
*
* @throws \InvalidArgumentException When user does not exist
*
* @return UserInterface
*/
private function findUserByUsernameOrThrowException($username)
{
$user = $this->userManager->findUserByUsername($username);
if (!$user) {
throw new \InvalidArgumentException(sprintf('User identified by "%s" username does not exist.', $username));
}
return $user;
}
示例8: deleteObject
/**
* Removes the given user object.
*
* @param DataEvent $event
*/
public function deleteObject(DataEvent $event)
{
$object = $event->getData();
if ($object instanceof UserInterface) {
$this->userManager->deleteUser($object);
$this->eventDispatcher->dispatch(Events::POST_DELETE, $event);
$event->stopPropagation();
}
}
示例9: 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;
}
示例10: getNbUnreadByUsername
public function getNbUnreadByUsername($username)
{
$nb = apc_fetch('nbm.' . $username);
if (false === $nb) {
$user = $this->userManager->findUserByUsername($username);
$nb = $this->updateNbUnread($participant);
}
return $nb;
}
示例11: onSecurityInteractiveLogin
/**
* handle user Ip log to users table, after login, with security.interactive_login kernel event.
*
* @param InteractiveLoginEvent $event
*/
public function onSecurityInteractiveLogin(InteractiveLoginEvent $event)
{
$user = $event->getAuthenticationToken()->getUser();
if ($user instanceof UserInterface) {
$ipAddress = $this->requestStack->getCurrentRequest()->server->get('REMOTE_ADDR');
$user->setLastloginClientIp($ipAddress);
$this->userManager->updateUser($user);
}
}
示例12: createModelInstance
protected function createModelInstance()
{
$message = parent::createModelInstance();
if ($to = $this->request->query->get('to')) {
if ($recipient = $this->userManager->findUserByUsername($to)) {
$message->setRecipient($recipient);
}
}
return $message;
}
示例13: reverseTransform
/**
* Transforms a username string into a UserInterface instance.
*
* @param string $value Username
*
* @return UserInterface the corresponding UserInterface instance
*
* @throws UnexpectedTypeException if the given value is not a string
*/
public function reverseTransform($value)
{
if (null === $value || '' === $value) {
return null;
}
if (!is_string($value)) {
throw new UnexpectedTypeException($value, 'string');
}
return $this->userManager->findUserByUsername($value);
}
示例14: getUserByEmailPw
/**
* @param string $email
* @param string $pw
* @return \FOS\UserBundle\Model\UserInterface|null
*/
function getUserByEmailPw($email, $pw)
{
$result = null;
if ($email && $pw) {
$user = $this->_fosUserManager->findUserByEmail($email);
if ($user && $this->isPasswordValid($user, $pw)) {
$result = $user;
}
}
return $result;
}
示例15: isValid
/**
* Checks if the passed value is valid.
*
* @param mixed $value The value that should be validated
* @param Constraint $constraint The constrain for the validation
*
* @return Boolean Whether or not the value is valid
*
* @throws UnexpectedTypeException if $value is not instance of \FOS\UserBundle\Model\UserInterface
*/
public function isValid($value, Constraint $constraint)
{
if (!$value instanceof UserInterface) {
throw new UnexpectedTypeException($value, 'FOS\\UserBundle\\Model\\UserInterface');
}
if (!$this->userManager->validateUnique($value, $constraint)) {
$this->setMessage($constraint->message, array('%property%' => $constraint->property));
return false;
}
return true;
}