Пример #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $container = $this->getContainer();
     $em = $container->get('doctrine')->getManager();
     $txt = file_get_contents('/var/www/teva/current/Teva2.csv');
     $array1 = explode("\n", $txt);
     foreach ($array1 as $val) {
         $array2 = explode(',', $val);
         //			$output->writeln($array2[4]);
         $user = $em->getRepository('LearningMainBundle:User')->findOneByUsername($array2[4]);
         if (!$user) {
             $fio = explode(' ', $array2[2]);
             if (isset($fio[2]) && $fio[2] && $fio[2] != '') {
                 $surname = $fio[2];
             } else {
                 $surname = '';
             }
             $pass = $this->generatePassword();
             if (strripos($array2[0], 'МП') !== false) {
                 $roles = 'ROLE_MEDREP;ROLE_NOTDEFAULT;';
             } elseif (strripos($array2[0], 'РМ') !== false) {
                 $roles = 'ROLE_MEDREP_ADMIN;ROLE_NOTDEFAULT;';
             } else {
                 $roles = '';
             }
             $user = new User();
             $city = $em->getRepository('LearningMainBundle:City')->find($array2[1]);
             $user->setUsername($array2[4]);
             $user->setCity($city);
             $user->setLastName($fio[0]);
             $user->setFirstName($fio[1]);
             $user->setSurName($surname);
             $user->setEnabled(true);
             $user->setPassword($pass);
             $user->setRoles($roles);
             $user->setEmailConfirmed(true);
             $em->persist($user);
             $em->flush($user);
             $em->refresh($user);
             $container->get('email.service')->send($user->getUsername(), array('LearningMainBundle:Email:registration.html.twig', array('user' => $user, 'password_orig' => $user->getPassword())), 'Благодарим за регистрацию на нашем портале!');
             $txt = "INSERT `user` SET username='******'4']}', city_id={$array2['1']} , lastName = '{$fio['0']}', firstName='{$fio['1']}', surName='{$surname}', password='******', roles='{$roles}';";
             $output->writeln($txt);
         }
     }
 }
Пример #2
0
 /**
  * Показывает регистрационную форму если HTTP-метод GET. Обрабатывает форму если HTTP-метод POST
  *
  * @Route("/register", name = "register")
  * @Template("LearningMainBundle:Auth:registration.html.twig");
  */
 public function registerAction(Request $request)
 {
     if ($this->get('security.context')->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
         return $this->redirect($this->generateUrl('_index'));
     }
     $em = $this->getDoctrine()->getManager();
     $user = new User();
     $referer = false;
     if ($request->query->get('refer')) {
         $array = unserialize(base64_decode(base64_decode(base64_decode(base64_decode($request->query->get('refer'))))));
         $user->setLastName($array['lastName']);
         $user->setFirstName($array['firstName']);
         $user->setSurName($array['surName']);
         $user->setCity($this->getDoctrine()->getRepository('LearningMainBundle:City')->findOneById($array['city']));
         $user->setBirthdate($array['birthDay']);
         $user->setJob($array['job']);
         $user->setUsername($array['username']);
         $user->setHashEvrika($array['hash']);
         $user->setGraduateYear($array['graduateYear']);
         if ($this->remoteAuthAction($array['hash'])) {
             return $this->redirect($this->generateUrl('_index'));
         }
         $theme = $this->container->getParameter('theme');
         if ($theme == 'roh') {
             if (isset($array['specialization'])) {
                 $user->addSpecialization($this->getDoctrine()->getRepository('LearningMainBundle:Specialization')->findOneById($array['specialization']));
             }
         } else {
             $user->addSpecialty($this->getDoctrine()->getRepository('LearningMainBundle:Specialty')->findOneById($array['specialty']));
             if ($array['specialty2'] != '' && $array['specialty2'] != NULL) {
                 $user->addSpecialty($this->getDoctrine()->getRepository('LearningMainBundle:Specialty')->findOneById($array['specialty2']));
             }
         }
         $user->setUniversity($this->getDoctrine()->getRepository('LearningMainBundle:University')->findOneById($array['university']));
         $referer = true;
     }
     $form = $this->createForm(new RegisterType($em), $user);
     if ($request->isMethod('POST')) {
         $form->submit($request);
         if ($form->isValid()) {
             if ($this->getDoctrine()->getRepository('LearningMainBundle:User')->findOneByUsername($user->getUsername()) != null) {
                 #throw new \UnexpectedValueException('Пользователь с таким email уже существует');
                 $form->addError(new formError('Пользователь с таким email уже существует'));
             } else {
                 try {
                     # установка шифрованного пароля
                     //$factory       = $this->get('security.encoder_factory');
                     //$encoder       = $factory->getEncoder($user);
                     $password_orig = $user->getPassword();
                     //$password      = $encoder->encodePassword($password_orig, $user->getSalt());
                     //$user->setPassword($password);
                     $user->setHash($this->calculateHash($user));
                     $em->persist($user);
                     $em->flush();
                     $em->refresh($user);
                     $this->resetToken($user);
                     # уведомление пользователя о регистрации
                     $this->get('email.service')->send($user->getUsername(), array('LearningMainBundle:Email:registration.html.twig', array('user' => $user, 'password_orig' => $password_orig)), 'Благодарим за регистрацию на нашем портале!');
                     # уведомление администраторов о регистрации
                     $this->get('email.service')->send($this->container->getParameter('manager_emails'), array('LearningMainBundle:Email:registration_notice.html.twig', array('user' => $user)), 'Зарегистрировался новый пользователь');
                     return $this->redirect($this->generateUrl('edit_profile'));
                 } catch (\UnexpectedValueException $e) {
                     $formError = new FormError($e->getMessage());
                     $form->addError($formError);
                 }
             }
             $user = $form->getData();
         }
     }
     return array('registration_form' => $form->createView(), 'title' => 'Регистрация', 'referer' => $referer);
 }