Advertisement
Guest User

takie tam

a guest
Nov 15th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.74 KB | None | 0 0
  1. <?php
  2.  
  3. namespace registerBundle\Controller;
  4. use Symfony\Component\HttpFoundation\Session\Session;
  5. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  6. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use loginBundle\Entity\Player;
  9.  
  10.  
  11. class DefaultController extends Controller
  12. {
  13.  
  14.  
  15.     /**
  16.      * @Route("/{locale}/register", name="register");
  17.      * @Route("/{locale}/edit");
  18.      */
  19.     public function indexAction($locale)
  20.     {
  21.  
  22.         $session = $this->getRequest()->getSession();
  23.         $user = $session->get('userSession');
  24.         $info = null;
  25.         if ($user == null) {
  26.             $info = "Create new account";
  27.  
  28.             if ($locale == 'pl')
  29.                 return $this->render('default/pl/register.html.twig', array('information' => $info, 'user' => $user));
  30.             else
  31.                 return $this->render('default/register.html.twig',
  32.                     array('user' => $user, 'info' => $info));
  33.         } else {
  34.             $info = "Edit you account";
  35.  
  36.  
  37.             if ($locale == 'pl')
  38.                 return $this->render('default/pl/register.html.twig', array('information' => $info, 'user' => $user));
  39.             else
  40.                 return $this->render('default/register.html.twig',
  41.                     array('user' => $user, 'info' => $info));
  42.  
  43.         }
  44.  
  45.  
  46.     }
  47.  
  48.     /**
  49.      * @Route("/{locale}/register/complete", name="registerWelcome")
  50.      */
  51.     public function registerAction(Request $request, $locale)
  52.     {
  53.         $info = null;
  54.  
  55.    
  56.  
  57.         if ($request->getMethod() == 'POST') {
  58.             $session = $this->getRequest()->getSession();
  59.             $userSession = $session->get('userSession');
  60.  
  61.  
  62.             $login = $request->get('user');
  63.             $password = $request->get('password');
  64.             $passwordd = $request->get('password2');
  65.             $email = $request->get('email');
  66.  
  67.             if ($password == $passwordd) {
  68.  
  69.                 $em = $this->getDoctrine()->getManager();
  70.                 $repository = $em->getRepository('loginBundle:Player');
  71.  
  72.  
  73.                 $userExist = null;//$repository->findOneBy(array('login' => $login));
  74.         if($userSession)
  75.         {
  76.                 $userExist = $this->getDoctrine()
  77.                     ->getRepository('loginBundle:Player')
  78.                     ->findOneBy(array('login' => $userSession));
  79.  
  80.         }
  81.         else
  82.         {
  83.         $userExist = $this->getDoctrine()
  84.                     ->getRepository('loginBundle:Player')
  85.                     ->findOneBy(array('login' => $login));
  86.  
  87.         }
  88.  
  89.                 if ($userExist == null) {
  90.                     $p = new Player ();
  91.                     $p->setLogin($login);
  92.                     $p->setPassword(sha1($password));
  93.                     $p->setEmail($email);
  94.                     $p->setCoins(2000);
  95.                     $em = $this->getDoctrine()->getManager();
  96.                    
  97.                     $em->persist($p);
  98.                     $em->flush();
  99.                     //  echo "Registration complete! " . $im;
  100.                     return $this->render('default/pl/index.html.twig');
  101.                 } else {
  102.         if($userSession)
  103.         {
  104.         $userExist->setPassword(sha1($password));
  105.         $userExist->setEmail($email);
  106.         $em->flush();
  107.         $info ="Changed";
  108.         }else $info = "User exist!";  }
  109.             } else {$info = "passwords not match";}
  110.         } else {$info = "Error";}
  111.  
  112.         if ($locale == 'pl')
  113.             return $this->render('default/pl/register.html.twig', array( 'user'=> $userSession, 'information'=> $info, 'info' => 'Sprobuj ponownie'));
  114.         else
  115.             return $this->render('default/register.html.twig', array( 'user'=> $userSession,'information'=> $info, 'info' => 'Try again'));
  116.  
  117.     }
  118.  
  119.            
  120.  
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement