Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Controller;
- use App\Entity\User;
- use App\Form\UserType;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\Routing\Annotation\Route;
- use Symfony\Bundle\FrameworkBundle\Controller\Controller;
- use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
- use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
- class AuthController extends Controller
- {
- /**
- * @Route("/auth", name="auth")
- */
- public function index()
- {
- return $this->render('auth/index.html.twig', [
- 'controller_name' => 'AuthController',
- ]);
- }
- /**
- * @Route("/login", name="login")
- */
- public function login(Request $request, AuthenticationUtils $authenticationUtils)
- {
- $username = $authenticationUtils->getLastUsername();
- $error = $authenticationUtils->getLastAuthenticationError();
- return $this->render('auth/login.html.twig', [
- 'username' => $username,
- 'error' => $error
- ]);
- }
- /**
- * @Route("/register", name="register")
- */
- public function register(Request $request, UserPasswordEncoderInterface $passwordEncoder)
- {
- $user = new User();
- $form = $this->createForm(UserType::class, $user);
- $form->handleRequest($request);
- if ($form->isSubmitted() && $form->isValid())
- {
- $password = $passwordEncoder->encodePassword($user, $user->getPassword());
- $user->setPassword($password);
- $auth = $this->getDoctrine()->getManager();
- $auth->persist($user);
- $auth->flush();
- return $this->redirectToRoute('driver_index');
- }
- return $this->render('auth/register.html.twig', [
- 'form' => $form->createView(),
- ]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement