can register user now

This commit is contained in:
gnieark 2020-01-02 22:27:51 +01:00
parent 4e4ae007c4
commit c311f3a88e
3 changed files with 31 additions and 3 deletions

View File

@ -21,4 +21,4 @@ register:
users: users:
path: /users path: /users
controller: App\Controller\SecurityController::showUserManagePage controller: App\Controller\SecurityController::showUserManagePage
methods: GET methods: GET|POST

View File

@ -112,16 +112,43 @@ class SecurityController extends AbstractController
->add('save', SubmitType::class,[]) ->add('save', SubmitType::class,[])
->getForm(); ->getForm();
} }
public function showUserManagePage()
public function showUserManagePage(Request $request, UserPasswordEncoderInterface $passwordEncoder)
{ {
$formCreateUser = $this->getformCreateUser();
$formCreateUser->handleRequest($request);
if ($formCreateUser->isSubmitted() && $formCreateUser->isValid()) {
$userValues = $formCreateUser->getData();
$user = new User();
$user ->setEmail($userValues ["email"])
->setPassword( $passwordEncoder->encodePassword($user,$userValues ["password"]) )
->setDisplayName( $userValues ["display_name"] )
->setActive(true)
->setRoles(array( $userValues["roles"] ));
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($user);
$entityManager->flush();
//empty the form
$formCreateUser = $this->getformCreateUser();
}
$users = $this->getDoctrine() $users = $this->getDoctrine()
->getRepository(User::class) ->getRepository(User::class)
->findAll(); ->findAll();
$menus = new Menus(); $menus = new Menus();
return $this->render('security/listUsers.html.twig', [ return $this->render('security/listUsers.html.twig', [
"menus" => $menus->getMenus( $this->getUser() ), "menus" => $menus->getMenus( $this->getUser() ),
"users" => $users, "users" => $users,
"formCreateUser" => $this->getformCreateUser()->createView() "formCreateUser" => $formCreateUser->createView()
]); ]);
} }

View File

@ -7,6 +7,7 @@
<article id="FormCreateUser"> <article id="FormCreateUser">
<h2>Create a new user</h2> <h2>Create a new user</h2>
{{ form(formCreateUser) }} {{ form(formCreateUser) }}
<p>{{ form_errors(formCreateUser) }}</p>
</article> </article>
<article> <article>