src/Auth/LoginController.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Auth;
  3. use App\Entity\Person;
  4. use App\Entity\User;
  5. use App\Form\LoginForm;
  6. use App\Handlers\SMSSenderHandler;
  7. use App\Messages\SMSMessage;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\Messenger\MessageBusInterface;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  14. class LoginController extends AbstractController
  15. {
  16.     /**
  17.      * @Route("/sign_in", name="security_signin")
  18.      * @param AuthenticationUtils $authenticationUtils
  19.      * @return Response
  20.      */
  21.     public function loginAction(AuthenticationUtils $authenticationUtils): Response
  22.     {
  23.         // if ($this->getUser()) {
  24.         //     return $this->redirectToRoute('target_path');
  25.         // }
  26.         // get the login error if there is one
  27.         $error $authenticationUtils->getLastAuthenticationError();
  28.         // last username entered by the user
  29.         $lastUsername $authenticationUtils->getLastUsername();
  30.         return $this->render('security/login.html.twig', ['last_username' => $lastUsername'error' => $error]);
  31.     }
  32.     /**
  33.      * @Route("/logout", name="logout")
  34.      */
  35.     public function logoutAction(){
  36. //        throw new \Exception("Something went terribly Wrong",Response::HTTP_INTERNAL_SERVER_ERROR, null);
  37.     }
  38.     /**
  39.      * @Route("/end", name="no_mans_land")
  40.      */
  41.     public function endLand() {
  42. //        throw new \Exception("Something went terribly Wrong",Response::HTTP_INTERNAL_SERVER_ERROR, null);
  43.         return $this->render('registration/no_mans_land.html.twig',[]);
  44.     }
  45.     /**
  46.      * @Route("/sign_in/queue_sms", name="queue")
  47.      */
  48.     public function queueSMS(MessageBusInterface $messageBus): Response
  49.     {
  50.         $messageBus->dispatch(new SMSMessage(523142));
  51.         return new Response('awesome');
  52.     }
  53.     /**
  54.      * @Route("/user")
  55.      */
  56.     public function insertAction(){
  57.         $user = new User();
  58.         $person = new Person();
  59.         $person->setFirstName('Hilary');
  60.         $person->setSecondName('Njiru');
  61.         $person->setSirName('Ngari');
  62.         $person->setCreatedAt(new \DateTime());
  63.         $person->setCreatedBy(null);
  64.         $person->setNationalId("9090903");
  65.         $person->setDateOfBirth(new \DateTime("1980-01-01"));
  66.         $person->setGender("Male");
  67.         $person->setPhoneNumber("0728167911");
  68.         $user->setRoles(['ROLE_USER']);
  69.         $user->setUsername('hilary');
  70.         $user->setPlainPassword('mirage');
  71.         $user->setCreatedAt(new \DateTime());
  72.         $user->setPerson($person);
  73.         $user->setEmail('hilary.nn@gmail.com');
  74.         $em  $this->getDoctrine()->getManager();
  75.         $em->persist($person);
  76.         $em->persist($user);
  77.         $em->flush();
  78.     }
  79.     /**
  80.      * @Route("/user2")
  81.      */
  82.     public function insert2Action(){
  83.         $user = new User();
  84.         $person = new Person();
  85.         $person->setFirstName('Samuel');
  86.         $person->setSecondName('Muturi');
  87.         $person->setSirName('Njuguna');
  88.         $person->setCreatedAt(new \DateTime());
  89.         $person->setCreatedBy(null);
  90.         $person->setNationalId("27787431");
  91.         $person->setDateOfBirth(new \DateTime("1990-01-01"));
  92.         $person->setGender("Male");
  93.         $person->setPhoneNumber("0716308459");
  94.         $user->setRoles(['ROLE_USER']);
  95.         $user->setUsername('samuel');
  96.         $user->setPlainPassword('mirage');
  97.         $user->setCreatedAt(new \DateTime());
  98.         $user->setPerson($person);
  99.         $user->setEmail('samnjuguna07@@gmail.com');
  100.         $em  $this->getDoctrine()->getManager();
  101.         $em->persist($person);
  102.         $em->persist($user);
  103.         $em->flush();
  104.     }
  105. }