src\Controller\ForgotPasswordController.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Controller\AppController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use App\Service\ApiCalls;
  8. use App\Security\AppAuthenticator;
  9. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  10. use App\Security\PasswordRestoreAuthenticator;
  11. use Symfony\Component\HttpFoundation\JsonResponse;
  12. class ForgotPasswordController extends AppController
  13. {
  14.     
  15.     
  16.     /* 
  17.      * starting page and success on sending the link
  18.      * 
  19.      */
  20.     public function index(): Response
  21.     {
  22.         
  23.         
  24.         $textsRes $this->ApiCalls->getPasswordAssistanceText();
  25.         if($textsRes[0]["apiReturnStatus"]===1){
  26.             $this->setData('texts'$textsRes[0]);
  27.         }
  28.         
  29.         $check $this->commonCalls(['getFooter','getHomeNav','getSearch']);
  30.        
  31.         if(!$check){
  32.             return $check;
  33.         }
  34.         if($this->RedirectHandle!==NULL){
  35.             return $this->RedirectHandle;
  36.         }
  37.         
  38.         if($this->Http->isMethod('POST')){
  39.             
  40.             $res $this->ApiCalls->forgotPassword($this->Http->request->get('userid'));
  41.             
  42.             if($res[0]["apiReturnStatus"]===1){
  43.                 $this->setData('success'TRUE);
  44.                 if($res[0]["apiReturnMessage"]==="Success: password reset SMS sent"){
  45.                     $this->setData('isSms'TRUE);
  46.                 }
  47.                 else{
  48.                     $this->setData('isSms'FALSE);
  49.                 }
  50.             }
  51.             else{
  52.                 $this->setData('success'FALSE);
  53.             }
  54.             $this->setData('uiMsg'$res[0]["apiReturnMessage"]);
  55.         }
  56.         return $this->render('forgot_password/index.html.twig'$this->getData());
  57.     }
  58.     
  59.     /* 
  60.      * new password form page
  61.      * that is accessed after the link in the email is clicked
  62.      * 
  63.      */
  64.     public function restorePasswordAction(PasswordRestoreAuthenticator $PasswordRestoreAuthenticator): Response
  65.     {
  66.         
  67.         $check $this->commonCalls(['getFooter','getHomeNav','getSearch']);
  68.         
  69.         if(!$check){
  70.             return $check;
  71.         }
  72.         if($this->RedirectHandle!==NULL){
  73.             return $this->RedirectHandle;
  74.         }  
  75.         
  76.         if(!$this->Http->getSession()->get('uiError')){
  77.         }
  78.         else{
  79.             $error $this->Http->getSession()->get('uiError');
  80.             if(isset($error['message'])){
  81.                 $this->setData('uiError'$this->Http->getSession()->get('uiError')['message']); 
  82.             }
  83.             else{
  84.                 $this->setData('uiError'$this->Http->getSession()->get('uiError')); 
  85.             }
  86.             $this->Http->getSession()->remove('uiError');
  87.         }
  88.         
  89.         
  90.         return $this->render('forgot_password/restore_password_action.html.twig'$this->getData());
  91.     }
  92.     
  93.     #response after the email or phone is provided
  94.     public function resetPassword(): Response
  95.     {
  96.         
  97.         
  98.         $isMobileFlag FALSE;
  99.         if($this->Http->query->get('isMobile') && $this->Http->query->get('isMobile') === '1'){
  100.             $isMobileFlag TRUE;            
  101.         }
  102.         $res $this->ApiCalls-> passwordAssistance($this->Http->request->get('userid'));
  103.         
  104. //        var_dump($res);        
  105.         if($res[0]["apiReturnStatus"]===1){
  106.             $ajaxMsg = [ => [
  107.                 'title'=> $res[0]["title"],
  108.                 'html'=> $res[0]["html"],
  109.                 'icon'=> $res[0]["icon"],
  110.                 'footer'=> $res[0]["footer"],
  111.                 'isAdmin'=> $res[0]["isAdmin"]
  112.                 
  113.             ]];
  114.            
  115.             if($res[0]["isAdmin"]){
  116.                 $ajaxMsg['redirect'] = TRUE;
  117.                 $ajaxMsg['url'] = 'https://'.$this->mode.'.learnertrack.net/user/password.asp';
  118.                 $ajaxMsg['username'] = $res[0]["username"];
  119.                 $ajaxMsg['firstpage'] = '/user/password.asp';
  120.             }
  121.             else{
  122.                 if($isMobileFlag){
  123.                     $ajaxMsg['redirect'] = TRUE;
  124.                     $ajaxMsg['path'] = 'signin/code';
  125.                 }
  126.                 else{
  127.                     $ajaxMsg['redirect'] = TRUE;
  128.                     $ajaxMsg['path'] = 'signin';
  129.                 }
  130.             } 
  131.             $this->setData('password-restore'$ajaxMsg);
  132.         }
  133.         else{
  134. //            $msg = 'authentication failed, not authorized';
  135. //            $this->Http->getSession()->set('uiError', ['message'=>$msg]);
  136.             $ajaxMsg = [ => [
  137.                 'title'=> $res[0]["title"],
  138.                 'html'=> $res[0]["html"],
  139.                 'icon'=> $res[0]["icon"],
  140.                 'footer'=> $res[0]["footer"],
  141.                 'isAdmin'=> $res[0]["isAdmin"]
  142.             ]];
  143.                      
  144.             $this->setData('password-restore'$ajaxMsg);
  145.         }
  146.         
  147.         
  148.         return new JsonResponse($this->getData());
  149.     }
  150.     
  151.     #response after the email or phone is provided
  152.     public function resetPasswordFieldForm(): Response
  153.     {
  154.         
  155.         
  156.         if($this->Http->request->get('password')){
  157.             $password $this->Http->request->get('password');
  158.             if($this->getUser()->getEmail()){
  159.                 $res $this->ApiCalls->passwordReset($this->getUser()->getEmail(), $password);                
  160.                 $this->setData('apiResponse'$res);
  161.             }
  162.         }
  163.                  
  164.         
  165.         $ajaxMsg = [ => [
  166.             'title'=> $res[0]["title"],
  167.             'html'=> $res[0]["html"],
  168.             'icon'=> $res[0]["icon"],
  169.             'footer'=> $res[0]["footer"]                
  170.         ]];
  171.         
  172.         $this->setData('password-restore'$ajaxMsg);
  173.         
  174.         
  175.         return new JsonResponse($this->getData());
  176.     }
  177.     
  178.     
  179. }