Updates a user
public updateUser ( FOS\UserBundle\Model\UserInterface $user ) : void | ||
$user | FOS\UserBundle\Model\UserInterface | |
리턴 | void |
/** * 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; }
/** * @param UserInterface $user */ protected function onSuccess(UserInterface $user) { if ($this->getNewPassword() != "") { $user->setPlainPassword($this->getNewPassword()); } $this->userManager->updateUser($user); }
/** * Updates the given user object. * * @param DataEvent $event */ public function updateObject(DataEvent $event) { $object = $event->getData(); if ($object instanceof UserInterface) { $this->userManager->updateUser($object); $this->eventDispatcher->dispatch(Events::POST_UPDATE, $event); $event->stopPropagation(); } }
/** * 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); } }
/** * 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; }
public function closeAccount(Response $response) { $user = $this->securityContext->getToken()->getUser(); $user->setEnabled(false); $this->userManager->updateUser($user); $cookieHandler = new CookieClearingLogoutHandler($this->request->cookies->all()); $cookieHandler->logout($this->request, $response, $this->securityContext->getToken()); $sessionHandler = new SessionLogoutHandler(); $sessionHandler->logout($this->request, $response, $this->securityContext->getToken()); $this->securityContext->setToken(null); }
/** * 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; }
/** * 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->setName($this->name); $user->setSurname($this->surname); $user->setEmail($email); $user->setPlainPassword($password); $user->setEnabled((bool) $active); $this->userManager->updateUser($user, true); return $user; }
/** * {@inheritDoc} */ public function loadUserByOAuthUserResponse(UserResponseInterface $response) { $username = $response->getUsername(); $user = $this->userManager->findUserBy(array('githubId' => $username)); if (!$user) { throw new AccountNotLinkedException(sprintf('No user with github username "%s" was found.', $username)); } if (!$user->getGithubToken()) { $user->setGithubToken($response->getAccessToken()); $this->userManager->updateUser($user); } return $user; }
protected function onSuccess() { if ($this->confirmation) { $user->setEnabled(false); $this->mailer->sendConfirmationEmailMessage($this->user); } else { $user->setConfirmationToken(null); $user->setEnabled(true); } $user->setRoles(array('ROLE_ADMIN')); $user->setPermissions(array('VIEW', 'EDIT', 'CREATE', 'DELETE')); $this->userManager->updateUser($this->user, true); }
/** * Creates a user and returns it. * * @param string $username * @param string $password * @param string $email * @param Boolean $active * @param Boolean $superadmin * @param string $firstName * @param string $lastName * @param integer $phoneNumber * * @return \AppBundle\Entity\Users */ public function create($username, $password, $email, $active, $superadmin, $firstName, $lastName, $phoneNumber) { $user = new Users(); $user->setUsername($username); $user->setEmail($email); $user->setPlainPassword($password); $user->setEnabled((bool) $active); $user->setFirstName($firstName); $user->setLastName($lastName); $user->setPhoneNumber($phoneNumber); $user->setSuperAdmin((bool) $superadmin); $this->userManager->updateUser($user); return $user; }
/** * {@inheritDoc} */ public function connect($user, UserResponseInterface $response) { $property = $this->getProperty($response); $setter = 'set' . ucfirst($property); if (!method_exists($user, $setter)) { throw new \RuntimeException(sprintf("Class '%s' should have a method '%s'.", get_class($user), $setter)); } $username = $response->getUsername(); if (null !== ($previousUser = $this->userManager->findUserBy(array($property => $username)))) { $previousUser->{$setter}(null); $this->userManager->updateUser($previousUser); } $user->{$setter}($username); $this->userManager->updateUser($user); }
public function unlock(User $user, $username, $password) { $user->setUsername($username); $user->setPlainPassword($password); $user->setUnlockToken(null); $errors = $this->validator->validate($user, ['Registration']); if ($errors->count() === 0) { try { $this->userManager->updateUser($user); } catch (\Exception $e) { throw new Exception($e->getMessage()); } return true; } return $errors; }
/** * 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; }
/** * Persists, updates or delete data return by the controller if applicable. * * @param GetResponseForControllerResultEvent $event */ public function onKernelView(GetResponseForControllerResultEvent $event) { $user = $event->getControllerResult(); if (!$user instanceof UserInterface) { return; } switch ($event->getRequest()->getMethod()) { case Request::METHOD_POST: case Request::METHOD_PUT: $this->userManager->updateUser($user, false); break; case Request::METHOD_DELETE: $this->userManager->deleteUser($user); $event->setControllerResult(null); break; } }
/** * 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; }
/** * Demotes the given user. * * @param string $username */ public function demote($username) { $user = $this->userManager->findUserByUsername($username); if (!$user) { throw new \InvalidArgumentException(sprintf('User identified by "%s" username does not exist.', $username)); } $user->setSuperAdmin(false); $this->userManager->updateUser($user); }
/** * @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; }
/** * On user login * * @param InteractiveLoginEvent $event Event */ public function onSecurityInteractiveLogin(InteractiveLoginEvent $event) { /** * @var User $user */ $user = $event->getAuthenticationToken()->getUser(); $referralService = $this->container->get('stfalcon_event.referral.service'); if ($this->request->cookies->has(ReferralService::REFERRAL_CODE)) { $referralCode = $this->request->cookies->get(ReferralService::REFERRAL_CODE); //check self referral code if ($referralService->getReferralCode($user) !== $referralCode) { $userReferral = $this->userManager->findUserBy(['referralCode' => $referralCode]); if ($userReferral) { $user->setUserReferral($userReferral); } $this->userManager->updateUser($user); } } }
/** * Removes role from the given user. * * @param string $username * @param string $role * * @return Boolean true if role was removed, false if user didn't have the role */ public function removeRole($username, $role) { $user = $this->findUserByUsernameOrThrowException($username); if (!$user->hasRole($role)) { return false; } $user->removeRole($role); $this->userManager->updateUser($user); return true; }
/** * {@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; }
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; }
/** * @param UserInterface $user */ protected function onSuccess(UserInterface $user) { // Disabling user password registration // $user->setPlainPassword($this->getNewPassword()); $user->setConfirmationToken(null); $user->setPasswordRequestedAt(null); $user->setEnabled(true); $this->userManager->updateUser($user); // getting DB user $dbUser = $this->em->getRepository('SpiritDevDBoxUserBundle:User')->findOneByUsername($user->getUsername()); // Updating LDAP Password $this->ldap->ldapUpdatePassword($dbUser, $this->getNewPassword()); }
/** * Creates a user and returns it. * * @param string $username * @param string $password * @param string $email * @param string $locale * @param Boolean $active * @param Boolean $superadmin * * @return \FOS\UserBundle\Model\UserInterface */ public function create($username, $password, $email, $locale, $active, $superadmin) { $user = $this->userManager->createUser(); $user->setUsername($username); $user->setEmail($email); $user->setLocale($locale); $user->setPlainPassword($password); $user->setEnabled((bool) $active); $user->setSuperAdmin((bool) $superadmin); $this->userManager->updateUser($user); /* $userProfile = new UserProfile(); $userProfile->setUser($user); $em = $this->getDoctrine()->getManager(); $em->persist($userProfile); $em->flush(); $user->setProfile($userProfile); $this->userManager->updateUser($user); */ return $user; }
/** * Removes role from the given user. * * @param string $username * @param string $role * * @return Boolean true if role was removed, false if user didn't have the role */ public function removeRole($username, $role) { $user = $this->userManager->findUserByUsername($username); if (!$user) { throw new \InvalidArgumentException(sprintf('User identified by "%s" username does not exist.', $username)); } if (!$user->hasRole($role)) { return false; } $user->removeRole($role); $this->userManager->updateUser($user); return true; }
/** * Persists the resource to the storage engine. * * @param \Hal\Resource $resource * * @throws NotFoundHttpException if no user with the given id could be found. * * @return null */ public function update(Resource $resource) { $data = $resource->toArray(); $user = $this->userManager->findUserByUsername($data['username']); if (!$user) { $errorMessage = $this->translator->trans('error.user_not_found', array('%username%' => $data['username'])); throw new NotFoundHttpException($errorMessage); } $user->setUsername($data['username']); $user->setEmail($data['email']); $user->setPlainPassword($data['password']); $user->setEnabled(true); $this->userManager->updateUser($user); }
/** * @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); }
/** * {@inheritDoc} */ public function connect(UserInterface $user, UserResponseInterface $response) { if (!$user instanceof User) { throw new UnsupportedUserException(sprintf('Expected an instance of FOS\\UserBundle\\Model\\User, but got "%s".', get_class($user))); } $property = $this->getProperty($response); if (!$this->accessor->isWritable($user, $property)) { throw new \RuntimeException(sprintf("Class '%s' must have defined setter method for property: '%s'.", get_class($user), $property)); } $username = $response->getUsername(); if (null !== ($previousUser = $this->userManager->findUserBy(array($property => $username)))) { $this->accessor->setValue($previousUser, $property, null); $this->userManager->updateUser($previousUser); } $this->accessor->setValue($user, $property, $username); $this->userManager->updateUser($user); }
/** * @param User $user */ private function refreshToken($user) { $req = new FormRequest(Request::METHOD_POST, "/" . $this->tenant . "/oauth2/token", "https://login.windows.net"); $req->setFields(array("client_id" => $this->clientId, "client_secret" => $this->clientSecret, "grant_type" => "refresh_token", "refresh_token" => $user->getAzureRenewAccessToken(), "resource" => "https://graph.windows.net")); $res = new Response(); $client = new Curl(); $client->setTimeout(20000); $client->send($req, $res); if ($res->getStatusCode() == 200) { $data = json_decode($res->getContent()); $user->setAzureAccessToken($data->access_token); $user->setAzureRenewAccessToken($data->refresh_token); $this->users->updateUser($user); $this->accessToken = $data->access_token; } else { $this->token->getToken()->setAuthenticated(false); throw new AccountExpiredException("Link with Office 365 has expired"); } }
/** * @param UserInterface $user */ protected function onSuccess(UserInterface $user) { $this->userManager->updateUser($user); }