Esempio n. 1
0
 public function newMemberAction(Request $request)
 {
     $surname = $this->onlyString($request->request->get('surname'));
     $name = $this->onlyString($request->request->get('name'));
     $secondname = $this->onlyString($request->request->get('secondname'));
     $login = $this->onlyNumeralAndString($request->request->get('login'));
     $password = $this->hidePass($this->onlyNumeralAndString($request->request->get('password')));
     $familyId = $this->get('session')->get('fmId');
     if ($surname && $name && $secondname && $login && $password && $familyId) {
         $em = $this->getDoctrine()->getEntityManager();
         $query = $em->createQuery('SELECT m.memberId FROM AcmeEcoBundle:Member m WHERE m.login = :login
               AND m.isDeleted = false')->setParameter('login', $login);
         $exist = $query->getResult();
         if (!$exist) {
             $family = $this->getDoctrine()->getRepository('AcmeEcoBundle:Family')->find($familyId);
             $member = new Member();
             $member->setName($name);
             $member->setSurname($surname);
             $member->setSecondname($secondname);
             $member->setPassword($password);
             $member->setLogin($login);
             $member->setFamily($family);
             $member->setIsDeleted(false);
             $em = $this->getDoctrine()->getEntityManager();
             $em->persist($member);
             $em->flush();
             return new Response('Ok!');
         } else {
             return new Response('Login already exist!');
         }
     } else {
         return new Response('Bad inputs!');
     }
 }
Esempio n. 2
0
 public function registrationAction(Request $request)
 {
     $surname = $this->onlyString($request->request->get('surname'));
     $name = $this->onlyString($request->request->get('name'));
     $secondname = $this->onlyString($request->request->get('secondname'));
     $password = $this->hidePass($this->onlyNumeralAndString($request->request->get('password')));
     $login = $this->onlyNumeralAndString($request->request->get('login'));
     if ($surname && $name && $secondname && $password && $login) {
         //  Проверка на совпадение логина (логин должен быть уникален!)
         $em = $this->getDoctrine()->getEntityManager();
         $query = $em->createQuery('SELECT m.memberId
               FROM AcmeEcoBundle:Member m
               WHERE m.login = :login
               AND m.isDeleted = false')->setParameter('login', $login);
         //  Если логин оригинальный, регистрируем нового пользователя
         $exist = $query->getResult();
         if (!$exist) {
             $family = new Family();
             $family->setFamilyName($surname);
             $member = new Member();
             $member->setName($name);
             $member->setSurname($surname);
             $member->setSecondname($secondname);
             $member->setPassword($password);
             $member->setLogin($login);
             $member->setFamily($family);
             $member->setIsDeleted(false);
             $em = $this->getDoctrine()->getEntityManager();
             $em->persist($family);
             $em->persist($member);
             $em->flush();
             // Очищаем переменные сессиии старых пользователей
             $this->get('session')->set('memId', null);
             $this->get('session')->set('fmId', null);
             // Создаем переменную личного идентификатора memId в сессии
             $memberId = $member->getMemberId();
             $familyId = $family->getFamilyId();
             $this->get('session')->set('memId', $member->getMemberId());
             $this->get('session')->set('fmId', $family->getFamilyId());
             setcookie('memberId', $memberId, null, '/web/index.php');
             setcookie('familyId', $familyId, null, '/web/index.php');
             return new Response('Ok!');
         } else {
             return new Response('Login already exist!');
         }
     } else {
         return new Response('Bad!');
     }
 }