src/Controller/ING/MainController.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Controller\ING;
  3. use App\Controller\BaseController;
  4. use Doctrine\DBAL\Connection;
  5. use Empire\Core\Core;
  6. use Empire\Core\Login;
  7. use Empire\Core\News;
  8. use Empire\Core\Password;
  9. use Exception;
  10. use Symfony\Component\HttpFoundation\RedirectResponse;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. use Symfony\Component\Mailer\MailerInterface;
  15. class MainController extends BaseController
  16. {
  17.     /**
  18.      * @Route("/")
  19.      */
  20.     public function main() {
  21.         return $this->render('ins/main.twig', [
  22.             'title' => 'Home',
  23.             'gejs' => ['ajax'],
  24.             'news' => News::getLatestNews(),
  25.         ]);
  26.     }
  27.     /**
  28.      * @Route("/login", name="login")
  29.      * @return Response
  30.      */
  31.     public function login(Request $request) {
  32.         $redirectUrl $request->query->get('returnUrl');
  33.         if(null === Core::user()) {
  34.             if(is_null($redirectUrl)){
  35.                 return $this->render('login.twig', ['gejs' => ['ajax']]);
  36.             } else {
  37.                 $client $request->query->get('client');
  38.                 return $this->render('login.twig', ['redirectUrl' => $redirectUrl'client' => $client'gejs' => ['ajax']]);
  39.             }
  40.         } else {
  41.             if(is_null($redirectUrl)){
  42.                 return $this->redirect('/irms');
  43.             } else {
  44.                 return $this->redirect($redirectUrl);
  45.             }
  46.         }
  47.     }
  48.     /**
  49.      * @Route("/logout")
  50.      * @return RedirectResponse
  51.      */
  52.     public function logout() {
  53.         Login::logout();
  54.         $this->addFlash('success''You have been logged out.');
  55.         return $this->redirect('/');
  56.     }
  57.     /**
  58.      * @Route("/lostpass", name="lostpass", methods={"GET"})
  59.      * @return Response
  60.      */
  61.     public function lostpass() {
  62.         return $this->render('lostpass.twig', ['gejs' => ['ajax']]);
  63.     }
  64.     /**
  65.      * @Route("/lostpass", methods={"POST"}, name="ing_lostpass_post")
  66.      */
  67.     public function lostpass_post(Request $requestMailerInterface $mailer) {
  68.         $reset Password::resetInitial($request->request->get('handle'''), $request->server->get('REMOTE_ADDR'), $mailer$this);
  69.         if($reset) {
  70.             return $this->redirect('/');
  71.         } else {
  72.             return $this->redirect('/lostpass');
  73.         }
  74.     }
  75.     /**
  76.      * @Route("/lostpass/{token}/{id}/{signature}", methods={"GET"})
  77.      * @param $token
  78.      * @param $id
  79.      * @param $signature
  80.      * @return Response
  81.      */
  82.     public function lostpass2 ($token$id$signature) {
  83.         try {
  84.             if(Password::checkToken($token$id$signature)) {
  85.                 return $this->render('lostpass2.twig', ['gejs' => ['ajax']]);
  86.             } else {
  87.                 $this->addFlash('error''Link is invalid.');
  88.                 return $this->render('lostpass.twig', ['gejs' => ['ajax']]);
  89.             }
  90.         } catch (Exception $e) {
  91.             $this->addFlash('error'$e->getMessage());
  92.             return $this->render('lostpass.twig', ['gejs' => ['ajax']]);
  93.         }
  94.     }
  95.     /**
  96.      * @Route("/lostpass/{token}/{id}/{signature}", methods={"POST"})
  97.      * @param Request $request
  98.      * @param $token
  99.      * @param $id
  100.      * @param $signature
  101.      * @return Response
  102.      */
  103.     public function lostpass2_post(Request $request$token$id$signature) {
  104.         $passwords = [$request->request->get('password'), $request->request->get('password2')];
  105.         if ($passwords[0] !== $passwords[1]) {
  106.             $this->addFlash('error''Your passwords do not match. Try again.');
  107.             return $this->render('lostpass2.twig', ['gejs' => ['ajax']]);
  108.         }
  109.         try {
  110.             $reset Password::resetFinal(null$passwords, [$token$id$signature]);
  111.             if($reset) {
  112.                 $this->addFlash('success''Your password has been reset, you may now log in using your new password.');
  113.                 return $this->redirect('/irms');
  114.             } else {
  115.                 $this->addFlash('error''An error occurrred reseetting your password.');
  116.                 return $this->redirect('/irms/%token/$id/$signature');
  117.             }
  118.         } catch (Exception $e) {
  119.             $this->addFlash('error'$e->getMessage());
  120.             return $this->render('lostpass2.twig', ['gejs' => ['ajax']]);
  121.         }
  122.     }
  123. }