src/Controller/Utils/adminController.php line 268

Open in your IDE?
  1. <?php
  2. /*
  3.  * To change this license header, choose License Headers in Project Properties.
  4.  * To change this template file, choose Tools | Templates
  5.  * and open the template in the editor.
  6.  */
  7. namespace App\Controller\Utils;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  12. //use Symfony\Component\DependencyInjection\ContainerInterface;
  13. //
  14. //use Symfony\Component\HttpFoundation\Session\Session;
  15. use Symfony\Component\Form\Extension\Core\Type\TextType;
  16. //use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  17. //use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  18. //use Symfony\Component\Form\Extension\Core\Type\IntegerType;
  19. //use Symfony\Component\Form\Extension\Core\Type\DateType;
  20. //use Symfony\Component\Form\Extension\Core\Type\EmailType;
  21. //use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  22. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  23. use Symfony\Component\Form\Extension\Core\Type\FileType;
  24. use Symfony\Component\Validator\Constraints\File;
  25. //use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  26. use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
  27. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  28. use Symfony\Component\HttpFoundation\RequestStack;
  29. //use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  30. //use Symfony\Component\Finder\Finder;
  31. //use Symfony\Component\Security\Core\User\UserInterface;
  32. //use Symfony\Component\HttpFoundation\File\UploadedFile;
  33. use Doctrine\ORM\EntityManagerInterface;
  34. //use App\Bundle\Model\Utility;
  35. //use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncode;
  36. //use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  37. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  38. use Symfony\Component\HttpFoundation\RedirectResponse;
  39. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  40. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  41. //
  42. use App\Service\UtilityServices;
  43. use App\Service\PasswordServices;
  44. use App\Form\Type\UserType;
  45. //use App\Form\Type\RegistrationFormType;
  46. use App\Entity\User;
  47. //
  48. //use Ramsey\Uuid\Uuid;
  49. use Symfony\Component\Uid\Uuid;
  50. use Symfony\Component\Uid\NilUuid;
  51. //
  52. //use SunCat\MobileDetectBundle\mobiledetectlib\MobileDetect as MD;
  53. //use SunCat\MobileDetectBundle\DeviceDetector\MobileDetector;
  54. //use App\Controller\EntityManagerInterface;
  55. //use Symfony\Component\HttpKernel\Exception\HttpException;
  56. //use SunCat\MobileDetectBundle\MobileDetectBundle\MobileDetect;
  57. /**
  58.  * Description of adminController
  59.  *
  60.  * @author efaneuf2
  61.  */
  62. class adminController extends AbstractController {
  63.     private $em;
  64.     private $params;
  65.     private $mobileDetector;
  66.     private $websiterooturl;
  67.     private $requestStack;
  68.     private $baseUrl;
  69.     private $baseURLUC;
  70.     public function __construct(ParameterBagInterface $paramsEntityManagerInterface $emRequestStack $requestStackstring $projectDir) {
  71. //$this->mobileDetector = $mobileDetector;
  72.         $this->params $params;
  73.         $this->em $em;
  74. //dd($params);
  75.         $this->requestStack $requestStack;
  76.         $request $this->requestStack->getCurrentRequest();
  77.         $this->baseUrl $request->getSchemeAndHttpHost();
  78.         $this->baseURLUC strtoupper(str_replace('https://'''$this->baseUrl));
  79.         $this->websiterooturl $projectDir;
  80.     }
  81.     /**
  82.      * @Route("/admin/addUserByList", name="adduserbylist")
  83.      */
  84.     public function addUserbylist(Request $requestUserPasswordEncoderInterface $passwordEncoder) {
  85.         if (!$this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
  86.             return new RedirectResponse('/login');
  87.         }
  88.         // fetch a list file.
  89.         // Columns (comma seperated)<br>
  90.         //            1 firstname middle name,<br>                  
  91.         //            2 isTeacher (0 or 1),<br>
  92.         //            3 isDeceased (0 or 1),<br>
  93.         //            4 death date,<br>
  94.         //            5 birthday (blank if not known),<br>
  95.         $defaultData = ['message' => 'Type your message here'];
  96.         $Repository $this->getDoctrine()->getRepository(User::class);
  97.         $form $this->createFormBuilder($defaultData)
  98.                 ->add('theFilename'FileType::class, [
  99.                     'label' => 'User List (TXT file)',
  100.                     // unmapped means that this field is not associated to any entity property
  101.                     'mapped' => false,
  102.                     // make it optional so you don't have to re-upload the PDF file
  103.                     // every time you edit the Product details
  104.                     'required' => false,
  105.                     // unmapped fields can't define their validation using annotations
  106.                     // in the associated entity, so you can use the PHP constraint classes
  107.                     'constraints' => [
  108.                         new File([
  109.                             'maxSize' => '1024k',
  110.                             'mimeTypes' => [
  111.                                 'text/plain',
  112.                             ],
  113.                             'mimeTypesMessage' => 'Please upload a valid TXT document',
  114.                                 ])
  115.                     ],
  116.                 ])
  117.                 ->add('send'SubmitType::class)
  118.                 ->getForm();
  119.         $form->handleRequest($request);
  120.         if ($form->isSubmitted() && $form->isValid()) {
  121.             // this will be the special name that is moved up to the server.
  122.             // We really do not need the PC name. We are going to immeadiatly
  123.             // process this files rows anyway
  124.             $txtfile $form->get('theFilename')->getData();
  125.             if ($txtfile) {
  126.                 $path_parts pathinfo($txtfile->getClientOriginalName());
  127.                 //echo $path_parts['dirname'], "<br>";
  128.                 //echo $path_parts['basename'], "<br>";
  129.                 //echo $path_parts['extension'], "<br>";
  130.                 //echo $path_parts['filename'], "<br>";
  131.                 //echo $txtfile, "<br>";
  132.                 $handle fopen($txtfile"r");
  133.                 if ($handle) {
  134.                     while (($line fgets($handle)) !== false) {
  135.                         $cleanline trim($line);
  136.                         if ($cleanline != '') {
  137.                             $lineAr explode(","$line);
  138.                             // if sizeof the array is not 5 items, issue fail
  139.                             $sz sizeof($lineAr);
  140.                             if ($sz 5) {
  141.                                 echo "file has invalid format ($sz columns found)<br>";
  142.                                 die();
  143.                             } else {
  144.                                 //echo "Name: " . $lineAr[0] . "<br>";
  145.                                 // split name into 2 or 3 parts
  146.                                 $nmPartsAR explode(" "$lineAr[0]);
  147. //                                if (sizeof($nmPartsAR) == 2) {
  148. //                                    echo "First Name:" . $nmPartsAR[0] . "<br>";
  149. //                                    echo "Last Name:" . $nmPartsAR[1] . "<br>";
  150. //                                } elseif (sizeof($nmPartsAR) == 3) {
  151. //                                    echo "First Name:" . $nmPartsAR[0] . "<br>";
  152. //                                    echo "Middle Name:" . $nmPartsAR[1] . "<br>";
  153. //                                    echo "Last Name:" . $nmPartsAR[2] . "<br>";
  154. //                                } else {
  155. //                                    echo "Failed to split name<br>";
  156. //                                }
  157.                                 //echo "Is A Teacher:" . (($lineAr[1] == 1) ? 'YES' : 'NO') . "<br>";
  158.                                 //echo "Is Deceased:" . (($lineAr[2] == 1) ? 'YES' : 'NO') . "<br>";
  159.                                 //if ($lineAr[2] == 1) {
  160.                                 //    echo "When Died:" . $lineAr[3] . "<br>";
  161.                                 //}
  162.                                 //echo "Birthday:" . $lineAr[4] . "<br><br>";
  163.                                 // check database and see if this user is already there. If not add them
  164.                                 //$User->setRoles(['ROLE_USER']); // set the basic access always
  165.                                 if (sizeof($nmPartsAR) == 2) {
  166.                                     $SearchUser $Repository->findUserbyName(strtolower($nmPartsAR[0]), strtolower($nmPartsAR[1]));
  167.                                 } elseif (sizeof($nmPartsAR) == 3) {
  168.                                     $SearchUser $Repository->findUserbyName(strtolower($nmPartsAR[0]), strtolower($nmPartsAR[2]));
  169.                                 }
  170.                                 if ($SearchUser) {
  171.                                     //dd($SearchUser);
  172.                                     echo "This user is already in the database<hr><br>";
  173.                                 } else {
  174.                                     //echo "We need to add this user<hr><br>Adding them now<br>";
  175.                                     if (sizeof($nmPartsAR) == 2) {
  176.                                         $Repository->SetUser($nmPartsAR[0], ""$nmPartsAR[1], $lineAr[1], $lineAr[2], $lineAr[3], $passwordEncoder);
  177.                                     } elseif (sizeof($nmPartsAR) == 3) {
  178.                                         $Repository->SetUser($nmPartsAR[0], $nmPartsAR[1], $nmPartsAR[2], $lineAr[1], $lineAr[2], $lineAr[3], $passwordEncoder);
  179.                                     }
  180.                                 }
  181.                                 //echo $line."<br>";
  182.                             }
  183.                         } //else {
  184. //                            echo "Found blank line<br>";
  185. //                        }
  186.                     }
  187.                     fclose($handle);
  188.                 } else {
  189.                     // error opening the file.
  190.                     echo "ERROR<br>";
  191.                 }
  192.                 //die();
  193.             }
  194.             $Users $Repository->findAllUsersByName();
  195.             return $this->render('admin/users.html.twig', ['users' => $Users]);
  196.         }
  197.         return $this->render('admin/userFlatFileLoader.html.twig', ['form' => $form->createView()]);
  198.     }
  199.     /**
  200.      * @Route("/forgotpassword", name="forgotpassword")
  201.      */
  202.     public function forgotPassword(
  203. //SessionInterface $session,
  204.             PasswordServices $pwdgen,
  205.             //AuthorizationCheckerInterface $authChecker, 
  206.             UtilityServices $utils,
  207.             UserPasswordEncoderInterface $passwordEncoder,
  208.             Request $request) {
  209.         $User = new User();
  210.         $form $this->createForm(UserType::class, $User,
  211.                         [
  212.                             'UtilityServices' => $utils,
  213.                             'generateStrongPasswordSvc' => $pwdgen,
  214.                             'editmode' => true,
  215.                             'editlabel' => 'Add User',
  216.                             'em' => $this->get('doctrine')->getManager(),
  217.                             'formstyle' => 'long',
  218.                             'nextuserid' => 0
  219.                         ]
  220.                 )
  221.                 ->add('username'TextType::class, ['label' => 'username or email '])
  222.                 ->add('save'SubmitType::class, ['label' => 'Get New Password'])
  223.         ;
  224. //        $form->get('allowEmail')->setData(true);
  225.         $form->handleRequest($request);
  226.         if ($form->isSubmitted() && $form->isValid()) {
  227. // is the username or password registered with us
  228. // YES
  229. // generate a unique ID to send to user
  230. // save this unique ID into a column in the user account we located
  231. // create email
  232. //NO
  233. // do nothing
  234.             return $this->render('security/forgotPasswordMsgSent.html.twig');
  235.         }
  236.         return $this->render('security/forgotPassword.html.twig', ['form' => $form->createView()]);
  237.     }
  238.     /**
  239.      * @Route("/", name="homepage")
  240.      */
  241.     public function defaultScreen(Request $request): Response {
  242. // $name = $request->query->get('hello')
  243. //$mobileDetector = $this->get('mobile_detect.mobile_detector');
  244. //$mobileDetector = $md;
  245. //$mobileDetector->isMobile();
  246. //$mobileDetector->isTablet();
  247.         return $this->render('default.html.twig');
  248.     }
  249.     /**
  250.      * @Route("/about", name="about")
  251.      */
  252.     public function about(Request $request): Response {
  253.         return $this->render('about.html.twig');
  254.     }
  255.     /**
  256.      * @Route("/maintenance", name="maintenance")
  257.      */
  258.     public function maintenance(Request $request): Response {
  259.         return $this->render('maintenanceMode.html.twig');
  260.     }
  261.     /**
  262.      * @Route("/tos", name="tos")
  263.      */
  264.     public function tos(Request $request): Response {
  265.         return $this->render('TOS.html.twig', [
  266.                     'SCN' => 'SJC',
  267.                     'FCN' => 'SJC Creations',
  268.                     'WSURL' => $this->websiterooturl,
  269.                     'SWSN' => $this->baseURLUC,
  270.                     'CONTACTEMAIL' => 'summerlinearl AT gmail.com',
  271.                     'SITEALIAS' => $this->baseURLUC,
  272.                     'EFFDATE' => 'April 1st, 2020'
  273.         ]);
  274.     }
  275.     /**
  276.      * @Route("/copyright", name="copyright")
  277.      */
  278.     public function copyright(Request $request): Response {
  279.         return $this->render('copyright.html.twig', [
  280.                     'SCN' => 'SJC',
  281.                     'FCN' => 'SJC Creations',
  282.                     'WSURL' => $this->websiterooturl,
  283.                     'SWSN' => $this->baseURLUC,
  284.                     'CONTACTEMAIL' => 'summerlinearl AT gmail.com',
  285.                     'SITEALIAS' => $this->baseURLUC,
  286.                     'EFFDATE' => 'April 1st, 2020'
  287.         ]);
  288.     }
  289.     /**
  290.      * @Route("/privacy", name="privacy")
  291.      */
  292.     public function privacy(Request $request): Response {
  293.         return $this->render('privacy.html.twig', [
  294.                     'SCN' => 'SJC',
  295.                     'FCN' => 'SJC Creations',
  296.                     'WSURL' => $this->websiterooturl,
  297.                     'SWSN' => $this->baseURLUC,
  298.                     'CONTACTEMAIL' => 'summerlinearl AT gmail.com',
  299.                     'SITEALIAS' => $this->baseURLUC,
  300.                     'EFFDATE' => 'April 1st, 2020'
  301.         ]);
  302.     }
  303.     /**
  304.      * @Route("/admin/addUser", name="adduser")
  305.      */
  306.     public function addUser(
  307.             //SessionInterface $session,
  308.             PasswordServices $pwdgen,
  309.             //AuthorizationCheckerInterface $authChecker, 
  310.             UtilityServices $utils,
  311.             UserPasswordEncoderInterface $passwordEncoder,
  312.             Request $request
  313.     ) {
  314.         if (!$this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
  315.             return new RedirectResponse('/login');
  316.         }
  317.         $Repository $this->getDoctrine()->getRepository(User::class);
  318.         $User = new User();
  319.         // these 3 items are set this way by default in the User class
  320.         $User->setRoles(['ROLE_USER']); // set the basic access always
  321.         $nextUserID $Repository->getNextUserID();
  322.         //$uuid = Uuid::v4();
  323.         //$User->setId($uuid->toBase32());
  324.         //dd($User);
  325.         $form $this->createForm(UserType::class, $User,
  326.                         [
  327.                             'UtilityServices' => $utils,
  328.                             'generateStrongPasswordSvc' => $pwdgen,
  329.                             'editmode' => true,
  330.                             'editlabel' => 'Add User',
  331.                             'em' => $this->get('doctrine')->getManager(),
  332.                             'formstyle' => 'long',
  333.                             'nextuserid' => $nextUserID
  334.                         ]
  335.                 )
  336.                 ->add('password'RepeatedType::class, [
  337.                     'required' => true,
  338.                     'invalid_message' => 'The password fields must match.',
  339.                     'type' => PasswordType::class,
  340.                     'first_options' => ['label' => 'Password'],
  341.                     'second_options' => [
  342.                         'label' => 'Confirm Password']
  343.                         ]
  344.                 )
  345.                 ->add('save'SubmitType::class, ['label' => 'Save'])
  346.         ;
  347.         $form->handleRequest($request);
  348.         if ($form->isSubmitted() && $form->isValid()) {
  349.             if (!empty(trim($form->get('password')->getData()))) {
  350.                 $new_password $form->get('password')->getData();
  351.                 $User->setPassword(
  352.                         $passwordEncoder->encodePassword($User$new_password)
  353.                 );
  354.             }
  355.             //$User = $this->get('security.token_storage')->getToken()->getUser();
  356.             //$UserId = $User->getId();
  357.             $uuid Uuid::v4();
  358.             $uuid_rfc4122 $uuid->toRfc4122(); // string(36) "d9e7a184-5d5b-11ea-a62a-3499710062d0"
  359.             $uuid_binary $uuid->toBinary();  // string(16) "\xd9\xe7\xa1\x84\x5d\x5b\x11\xea\xa6\x2a\x34\x99\x71\x00\x62\xd0"
  360.             $uuid_base32 $uuid->toBase32();  // string(26) "6SWYGR8QAV27NACAHMK5RG0RPG"
  361.             //$uuid_base58 = $uuid->toBase58();  // string(22) "TuetYWNHhmuSQ3xPoVLv9M"
  362.             //dd($uuidbinday);
  363.             $User->setId($uuid_base32);
  364.             //dd($uuid_base32);
  365.             $User->setCreatedatuserid($uuid_base32);
  366.             $User->setUpdatedatuserid($uuid_base32);
  367.             $currentdate = new \DateTime('now');
  368.             $User->setCreatedate($currentdate);
  369.             $User->setModificationdate($currentdate);
  370.             $User->setRoles2(implode(","$form->get('roles')->getData()));
  371.             if (!$User->getRoles2()) {
  372.                 $User->setRoles2('ROLE_USER');
  373.             }
  374.             $this->em->persist($User);
  375.             $this->em->flush();
  376.             //$Repository = $this->getDoctrine()->getRepository(user::class);
  377.             //$Users = $Repository->findAll();
  378.             $Users $Repository->findAllUsersByName();
  379.             return $this->render('admin/users.html.twig', ['users' => $Users]);
  380.         }
  381.         return $this->render('admin/userAdd.html.twig', ['form' => $form->createView(), 'editmode' => false]);
  382.     }
  383.     /**
  384.      * @Route("/edituser/{id}", name="edituser")
  385.      */
  386.     public function editUser(
  387.             //SessionInterface $session,
  388.             PasswordServices $pwdgen,
  389.             //AuthorizationCheckerInterface $authChecker, 
  390.             UtilityServices $utils,
  391.             Request $request,
  392.             UserPasswordEncoderInterface $passwordEncoder,
  393.             $id): Response {
  394.         if (!$this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
  395.             return new RedirectResponse('/login');
  396.         }
  397.         //$currentdate = new \DateTime('now');
  398.         $Repository $this->getDoctrine()->getRepository(User::class);
  399.         // convert the 32 bit binary number in the database to the
  400.         // uuid format we normally like to see
  401.         $uuid Uuid::fromString($id);
  402.         $uuid_rfc4122 $uuid->toRfc4122(); // string(36) "d9e7a184-5d5b-11ea-a62a-3499710062d0"
  403.         $uuid_binary $uuid->toBinary();  // string(16) "\xd9\xe7\xa1\x84\x5d\x5b\x11\xea\xa6\x2a\x34\x99\x71\x00\x62\xd0"
  404.         $uuid_base32 $uuid->toBase32();  // string(26) "6SWYGR8QAV27NACAHMK5RG0RPG"
  405.         //$uuid_base58 = $uuid->toBase58();  // string(22) "TuetYWNHhmuSQ3xPoVLv9M"
  406.         //dd($uuidbinday);
  407.         // 34656139-3739-3566-6335-643834313038
  408.         // 4ea9795fc5d84108
  409.         //echo $id . "<br>";
  410.         //dd($uuid_binary);
  411.         // need to convert rfc4122 to binary to do the test
  412.         $User $Repository->find($uuid_binary);
  413.         // we need, on EDIT, to set the password fields to blank
  414.         //dd($User);
  415.         $uuid_next $Repository->getNextUserID();
  416.         //$nextUserID = $uuid_next->toBase32();
  417.         //dd($nextUserID);
  418.         $isActive $User->getIsActive();
  419.         //dd($isActive);
  420.         if (!$User) {
  421.             throw $this->createNotFoundException('No User found for ID ' $id);
  422.         }
  423.         $form $this->createForm(UserType::class, $User,
  424.                         [
  425.                             'UtilityServices' => $utils,
  426.                             'generateStrongPasswordSvc' => $pwdgen,
  427.                             'editmode' => true,
  428.                             'editlabel' => 'Add User',
  429.                             'em' => $this->get('doctrine')->getManager(),
  430.                             'formstyle' => 'long',
  431.                             'nextuserid' => $uuid_next
  432.                         ]
  433.                 )
  434.                 ->add('password2'RepeatedType::class, [
  435.                     'required' => false,
  436.                     'mapped' => false,
  437.                     'invalid_message' => 'The password fields must match.',
  438.                     'type' => PasswordType::class,
  439.                     'first_options' => [
  440.                         'label' => 'Password',
  441.                         'always_empty' => true,
  442.                         'attr' => [
  443.                             "autocomplete" => "off",
  444.                             "disabled" => "disabled",
  445.                             "style" => [
  446.                                 "background-color" => "lightgray!Important"
  447.                             ]
  448.                         ]
  449.                     ],
  450.                     'second_options' => [
  451.                         'label' => 'Confirm Password',
  452.                         'always_empty' => true,
  453.                         'attr' => [
  454.                             "autocomplete" => "off",
  455.                             "disabled" => "disabled",
  456.                             "style" => [
  457.                                 "background-color" => "lightgray!Important"
  458.                             ]
  459.                         ]
  460.                     ],
  461.                     'attr' => [
  462.                         "style" => [
  463.                             "background-color" => "lightgray!Important"
  464.                         ]
  465.                     ],
  466.                 ])
  467.                 ->add('save'SubmitType::class, array('label' => 'Save'));
  468.         // Remove the password field when editing the user
  469.         // Otherwise it must be entered each time the user is edited
  470.         // We can change the password via a special edit-user-password page
  471.         $form->remove('password');
  472.         
  473.         $form->handleRequest($request);
  474.         //$errorStr = $form->getErrors();
  475.         if ($form->isSubmitted() && $form->isValid()) {
  476.             try {
  477.                 // if the user passes in a new password, change it. Otherwise just ignore the password field
  478.                 if (!empty(trim($form->get('password2')->getData()))) {
  479.                     $new_password $form->get('password2')->getData();
  480.                     $User->setPassword(
  481.                             $passwordEncoder->encodePassword($User$new_password)
  482.                     );
  483.                 }
  484.                 $so $form->get('SignificantOtherID')->getData();
  485.                 if ($so) {
  486.                     $User->setSignificantOtherID($so->getID());
  487.                 } else {
  488.                     //$User->setSignificantOtherID(null);
  489.                 }
  490.                 //dd($User);
  491.                 $mp $form->get('mobilephone')->getData();
  492.                 if ($mp) {
  493.                     $User->setMobilephone($mp);
  494.                 } else {
  495.                     $User->setMobilephone(' ');
  496.                 }
  497.                 
  498.                 $loggedInuser $this->get('security.token_storage')->getToken()->getUser();
  499.                 $loggedinUserId $loggedInuser->getId();
  500.                 //$User->setCreatedatuserid($uuid_base32);
  501.                 $User->setUpdatedatuserid($loggedinUserId);
  502.                 $currentdate = new \DateTime('now');
  503.                 //$User->setCreatedate($currentdate);
  504.                 $User->setLasteditdate($currentdate);
  505.                 $User->setModificationdate($currentdate);
  506.                 if (!$this->get('security.authorization_checker')->isGranted('ROLE_ADMIN') AND 
  507.                         !$this->get('security.authorization_checker')->isGranted('ROLE_ASSTADMIN')) {
  508.                     if ($isActive == true) {
  509.                         $User->setIsActive(true);
  510.                     } else {
  511.                         $User->setIsActive(false);
  512.                     }
  513.                     //echo "IsActive: ".$isActive."<br><br><br>";
  514.                     //dd($User);
  515.                 }
  516.                 
  517.                 $this->em->persist($User);
  518.                 $this->em->flush();
  519.             } catch (Exception $e) {
  520.                 $error = (string) $form->getErrors(truefalse);
  521.                 $errstring var_export($this->getErrorMessages($form), true);
  522.                 return $this->render('failure.html.twig', array(
  523.                             'error' => $error,
  524.                             ' catch' => $e->getMessage(),
  525.                             'allerrors' => $errstring));
  526.             }
  527.             // submit button pressed and any validations we had have passed the test.
  528.             // it has flushed the data back to the database so insert this form entry
  529.             // so we will now show the main page displaying our new entry at the top
  530.             //$Users = $Repository->findAll();
  531.             //$Users = $Repository->findBy([], ['lastname' => 'ASC', 'firstname' => 'ASC']);
  532.             $Users $Repository->findAllUsersByName();
  533.             return $this->render('admin/users.html.twig', ['users' => $Users]);
  534.         } else if ($form->isSubmitted()) {
  535.             //submit button was pressed, but there is something wrong with the entry on the form
  536.             $errors = (string) $form->getErrors(truefalse);
  537.             $errstring var_export($this->getErrorMessages($form), true);
  538.             return $this->render('failure.html.twig', array(
  539.                         'errors' => $errors,
  540.                         'allerrors' => $errstring));
  541.         }
  542.         // Display the entry form
  543.         // this form should display all users, let us edit details on a user,
  544.         // return with which user and save the details
  545.         return $this->render('admin/userEdit.html.twig', ['user' => $User'form' => $form->createView(), 'editmode' => true]);
  546.     }
  547.     /**
  548.      * @Route("/delete/participant/{id}", name="delete_participant")
  549.      */
  550.     public function delUser(
  551.             SessionInterface $session,
  552.             PasswordServices $pwdgen,
  553.             //AuthorizationCheckerInterface $authChecker, 
  554.             UtilityServices $utils,
  555.             UserPasswordEncoderInterface $passwordEncoder,
  556.             Request $request,
  557.             $id) {
  558.         if (!$this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
  559.             return new RedirectResponse('/login');
  560.         }
  561.         $Repository $this->getDoctrine()->getRepository(User::class);
  562.         $User $Repository->find($id);
  563.         $nextUserID $Repository->getNextUserID();
  564.         if (!$User) {
  565.             throw $this createNotFoundException('No User found for ID ' $id);
  566.         }
  567.         $form $this->createForm(UserType::class, $User,
  568.                         [
  569.                             'UtilityServices' => $utils,
  570.                             'generateStrongPasswordSvc' => $pwdgen,
  571.                             'editmode' => true,
  572.                             'editlabel' => 'Add User',
  573.                             'em' => $this->get('doctrine')->getManager(),
  574.                             'formstyle' => 'long',
  575.                             'nextuserid' => $nextUserID
  576.                         ]
  577.                 )
  578.                 ->add('save'SubmitType::class, [
  579.                     'label' => 'Delete',
  580.                     'attr' => array(
  581.                         'onClick' => 'return confirm("Are you sure?");',
  582.                     )
  583.                 ])
  584.                 ->add('cancel'SubmitType::class, ['label' => 'cancel'])
  585.         ;
  586.         $form->handleRequest($request);
  587.         if ($form->isSubmitted() && $form->isValid()) {
  588.             if ($form->getClickedButton() === $form->get('cancel')) {
  589.                 return $this->redirectToRoute('listparticipants');
  590.             } else {
  591.                 $this->em->remove($User);
  592.                 $this->em->flush();
  593.                 return $this->redirectToRoute('listparticipants');
  594.             }
  595.         }
  596.         return $this->render('admin/userDel.html.twig', ['form' => $form->createView()]);
  597.     }
  598.     /**
  599.      * @Route("/finduserbyemail", name="find_user_by_email")
  600.      */
  601.     public function findUserByEmail(
  602.             SessionInterface $session,
  603.             PasswordServices $pwdgen,
  604.             //AuthorizationCheckerInterface $authChecker, 
  605.             UtilityServices $utils,
  606.             UserPasswordEncoderInterface $passwordEncoder,
  607.             Request $request,
  608.     ) {
  609.         if (!$this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
  610.             return new RedirectResponse('/login');
  611.         }
  612.         $defaultData = ['message' => 'Type your message here'];
  613.         $form $this->createFormBuilder($defaultData)
  614.                 ->add('emails'TextType::class, ['mapped' => false])
  615.                 ->add('save'SubmitType::class, ['label' => 'Find Them',])
  616.                 ->getForm();
  617.         $form->handleRequest($request);
  618.         if ($form->isSubmitted() && $form->isValid()) {
  619.             //$data = $form->getData();
  620.             $emails $form->get('emails')->getData();
  621.             $Repository $this->getDoctrine()->getRepository(User::class);
  622.             $User $Repository->findUserByEmail($emails);
  623.             return $this->render('admin/showusersemail.html.twig', ['users' => $User]);
  624.         } elseif ($form->isSubmitted() && !$form->isValid()) {
  625.             return $this->render('admin/showusersemail_failure.html.twig');
  626.         }
  627.         return $this->render('admin/finduserbyemail.html.twig', ['form' => $form->createView()]);
  628.     }
  629.     /**
  630.      * @Route("/listparticipants", name="listparticipants")
  631.      */
  632.     public function getUsers(Request $request): Response {
  633.         if (!$this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
  634.             return new RedirectResponse('/login');
  635.         }
  636.         // https://symfony.com/doc/current/doctrine.html
  637.         //$currentdate = new \DateTime('now');
  638.         $Repository $this->getDoctrine()->getRepository(User::class);
  639.         //$Users = $Repository->findBy([], ['lastname' => 'ASC', 'firstname' => 'ASC']);
  640.         $Users $Repository->findAllUsersByName();
  641.         //dd($Users);
  642.         return $this->render('admin/users.html.twig', ['users' => $Users]);
  643.     }
  644.     /**
  645.      * @Route("/listparticipantsInactiveFirst", name="listparticipants_inactive_first")
  646.      */
  647.     public function getUsersInactiveFirst(Request $request): Response {
  648.         if (!$this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
  649.             return new RedirectResponse('/login');
  650.         }
  651.         // https://symfony.com/doc/current/doctrine.html
  652.         //$currentdate = new \DateTime('now');
  653.         $Repository $this->getDoctrine()->getRepository(User::class);
  654.         //$Users = $Repository->findBy([], ['lastname' => 'ASC', 'firstname' => 'ASC']);
  655.         $Users $Repository->findAllUsersByNameInactiveFirst();
  656.         //dd($Users);
  657.         return $this->render('admin/users.html.twig', ['users' => $Users]);
  658.     }
  659.     /**
  660.      * @Route("/listparticipantsAllowEmailFirst", name="listparticipants_allow_email_first")
  661.      */
  662.     public function getUsersAllowEmailFirst(Request $request): Response {
  663.         if (!$this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
  664.             return new RedirectResponse('/login');
  665.         }
  666.         // https://symfony.com/doc/current/doctrine.html
  667.         //$currentdate = new \DateTime('now');
  668.         $Repository $this->getDoctrine()->getRepository(User::class);
  669.         //$Users = $Repository->findBy([], ['lastname' => 'ASC', 'firstname' => 'ASC']);
  670.         $Users $Repository->findAllUsersByNameAllowEmailFirst();
  671.         //dd($Users);
  672.         return $this->render('admin/users.html.twig', ['users' => $Users]);
  673.     }
  674.     /**
  675.      * @Route("/contactus", name="contactus")
  676.      */
  677.     public function contactus() {
  678.         return $this->render('security/contactus.html.twig');
  679.     }
  680.     private function getErrorMessages(\Symfony\Component\Form\Form $form) {
  681.         $errors = array();
  682.         if ($form->count() > 0) {
  683.             foreach ($form->all() as $child) {
  684.                 /**
  685.                  * @var \Symfony\Component\Form\Form $child
  686.                  */
  687.                 if (!$child->isValid()) {
  688.                     $errors[$child->getName()] = $this->getErrorMessages($child);
  689.                 }
  690.             }
  691.         } else {
  692.             /**
  693.              * @var \Symfony\Component\Form\FormError $error
  694.              */
  695.             foreach ($form->getErrors() as $key => $error) {
  696.                 $errors[] = $error->getMessage();
  697.             }
  698.         }
  699.         return $errors;
  700.     }
  701. }