Esempio n. 1
0
 /**
  * Handle a POST from user edit or first user creation.
  *
  * @param Request $request
  * @param Form    $form      A Symfony form
  * @param boolean $firstuser If this is a first user set up
  *
  * @return Entity\Users|false
  */
 private function validateUserForm(Request $request, Form $form, $firstuser = false)
 {
     $form->submit($request->get($form->getName()));
     if (!$form->isValid()) {
         return false;
     }
     $userEntity = new Entity\Users($form->getData());
     $userEntity->setUsername($this->app['slugify']->slugify($userEntity->getUsername()));
     if (!$firstuser) {
         $userEntity->setRoles($this->users()->filterManipulatableRoles($userEntity->getId(), $userEntity->getRoles()));
     }
     if ($this->getRepository('Bolt\\Storage\\Entity\\Users')->save($userEntity)) {
         $this->flashes()->success(Trans::__('page.edit-users.message.user-saved', ['%user%' => $userEntity->getDisplayname()]));
         $this->notifyUserSave($request, $userEntity->getDisplayname(), $userEntity->getEmail(), $firstuser);
     } else {
         $this->flashes()->error(Trans::__('page.edit-users.message.saving-user', ['%user%' => $userEntity->getDisplayname()]));
     }
     return $userEntity;
 }