src/Controller/ING/MainController.php line 67

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