public function editAction(Request $request, User $user) { $principalidentity = $user->getIdentityPrincipal(); $data = array('displayname' => $principalidentity->getDisplayname(), 'email' => $principalidentity->getEmail(), 'roles' => $user->getRoles()); $form = $this->get('form.factory')->create(new FormType\User\EditUserType()); $form->setData($data); $form->handleRequest($request); if ($form->isValid()) { $data = $form->getData(); $em = $this->getDoctrine()->getManager(); # Persisting identity principal $principalidentity->setDisplayname($data['displayname']); $principalidentity->setEmail($data['email']); $em->persist($principalidentity); # Persisting user if password changed if (!is_null($data['password'])) { $password = $data['password']; $user->setPassword($this->get('security.encoder_factory')->getEncoder($user)->encodePassword($password, $user->getSalt())); } # Persisting user roles $user->setRoles($data['roles']); $em->persist($user); $em->flush(); $this->get('session')->getFlashBag()->add('notice', 'User <i class="fa fa-user"></i> <strong>' . htmlspecialchars($user->getUsername()) . '</strong> has been updated.'); return $this->redirect($this->generateUrl('baikal_admin_user_list')); } return $this->render('BaikalAdminBundle:User:form.html.twig', array('user' => $user, 'form' => $form->createView())); }
protected function getSuccessFunction(User $user) { $that = $this; return function ($form, Calendar $calendar, $isNew) use($user, $that) { $that->get('session')->getFlashBag()->add('notice', 'Calendar <i class="fa fa-calendar"></i> <strong>' . htmlspecialchars($calendar->getDisplayname()) . '</strong> has been ' . ($isNew ? 'created' : 'updated') . '.'); return $that->redirect($this->generateUrl('baikal_admin_user_calendar_list', array('id' => $user->getId()))); }; }
public function deleteAction(User $user, Addressbook $addressbook) { $em = $this->getDoctrine()->getManager(); $em->remove($addressbook); $em->flush(); $this->get('session')->getFlashBag()->add('notice', 'Addressbook <i class="fa fa-book"></i> <strong>' . htmlspecialchars($addressbook->getDisplayname()) . '</strong> has been deleted.'); return $this->redirect($this->generateUrl('baikal_admin_user_addressbook_list', array('id' => $user->getId()))); }
public function handle($onSuccess, $onFailure, Request $request, User $user, Calendar $calendar = null) { $new = false; if (is_null($calendar)) { $calendar = new Calendar(); $calendar->setPrincipaluri($user->getIdentityPrincipal()->getUri()); $calendar->setUri(UUIDUtil::getUUID()); $new = true; } $form = $this->formfactory->create(new CalendarType(), $calendar); $form->handleRequest($request); if ($form->isValid()) { $this->em->persist($calendar); $this->em->flush(); return $onSuccess($form, $calendar, $new); } return $onFailure($form, $calendar, $new); }
public function handle($onSuccess, $onFailure, Request $request, User $user, Addressbook $addressbook = null) { $new = false; if (is_null($addressbook)) { $addressbook = new Addressbook(); $addressbook->setPrincipaluri($user->getIdentityPrincipal()->getUri()); $addressbook->setUri(UUIDUtil::getUUID()); $addressbook->setSynctoken('1'); $new = true; } $form = $this->formfactory->create(new AddressbookType(), $addressbook); $form->handleRequest($request); if ($form->isValid()) { $this->em->persist($addressbook); $this->em->flush(); return $onSuccess($form, $addressbook, $new); } return $onFailure($form, $addressbook, $new); }
public function createAndPersistUser($username, $password) { # Persisting identity principal $principalidentity = new UserPrincipal(); $principalidentity->setDisplayname(ucwords($username)); $principalidentity->setUri('principals/' . $username); $principalidentity->setEmail('*****@*****.**'); $this->entityManager->persist($principalidentity); # Persisting user $user = new User(); $user->setUsername($username); # Not setting salt; handled by the user entity $user->setPassword($this->passwordencoder->encodePassword($password, $user->getSalt())); $user->addRole('ROLE_ADMIN'); $user->addRole('ROLE_FRONTEND_USER'); $this->entityManager->persist($user); $this->entityManager->flush(); return $user; }
public function indexAction(Request $request, User $user) { return $this->render('BaikalAdminBundle:User:info.html.twig', array('nbcalendars' => count($user->getCalendars()), 'nbbooks' => count($user->getAddressbooks()), 'user' => $user)); }