diff --git a/Symfony/src/AppBundle/Controller/DashboardController.php b/Symfony/src/AppBundle/Controller/DashboardController.php index cbc605a..1ec243d 100644 --- a/Symfony/src/AppBundle/Controller/DashboardController.php +++ b/Symfony/src/AppBundle/Controller/DashboardController.php @@ -19,8 +19,11 @@ public function showAction($messages = []) $tier = $this->getDoctrine() ->getRepository('AppBundle:Tier') ->find($user->getTier()); + $tiers = $this->getDoctrine() + ->getRepository('AppBundle:Tier') + ->findAll(); return $this->render('AppBundle:Dashboard:index.html.twig', - array('user' => $user, 'firmwares' => $firmwares, 'tier' => $tier, 'messages' => $messages)); + array('user' => $user, 'firmwares' => $firmwares, 'tier' => $tier, 'tiers' => $tiers, 'messages' => $messages)); } } diff --git a/Symfony/src/AppBundle/Controller/RegisterController.php b/Symfony/src/AppBundle/Controller/RegisterController.php index 8824593..077a49d 100644 --- a/Symfony/src/AppBundle/Controller/RegisterController.php +++ b/Symfony/src/AppBundle/Controller/RegisterController.php @@ -22,13 +22,17 @@ public function registerAction(Request $request) if ($form->isSubmitted() && $form->isValid() && count($errors) == 0) { $password = $this->get('security.password_encoder')->encodePassword($user, $user->getPassword()); $user->setPassword($password)->setSuccessfulFlashCount(0)->setTotalFlashCount(0)->setTier(0); - $entityManager = $this->getDoctrine()->getManager(); - $entityManager->persist($user); - $entityManager->flush(); - $token = new UsernamePasswordToken($user, null, 'login', $user->getRoles()); - $this->get('security.token_storage')->setToken($token); - $messages = ["You have been registered!"]; - return $this->forward('AppBundle:Dashboard:show', array('messages' => $messages)); + try { + $entityManager = $this->getDoctrine()->getManager(); + $entityManager->persist($user); + $entityManager->flush(); + $token = new UsernamePasswordToken($user, null, 'login', $user->getRoles()); + $this->get('security.token_storage')->setToken($token); + $messages = ["You have been registered!"]; + return $this->forward('AppBundle:Dashboard:show', array('messages' => $messages)); + } catch(\Exception $e){ + $errors = $e; + } } return $this->render('AppBundle:Register:index.html.twig', array('form' => $form->createView(), 'errors' => $errors)); diff --git a/Symfony/src/AppBundle/Controller/UpdateTierController.php b/Symfony/src/AppBundle/Controller/UpdateTierController.php new file mode 100644 index 0000000..f7ca9e6 --- /dev/null +++ b/Symfony/src/AppBundle/Controller/UpdateTierController.php @@ -0,0 +1,25 @@ +request->all(); + $entityManager = $this->getDoctrine()->getManager(); + $user = $entityManager->getRepository('AppBundle:User')->find($owner); + if ($data["tier"] !== null && $data["tier"] > 0) { + $user->setTier($data["tier"]); + } + $entityManager->flush(); + return new Response(); + } +} diff --git a/Symfony/src/AppBundle/Entity/User.php b/Symfony/src/AppBundle/Entity/User.php index 0d5bdbb..ddaaba1 100644 --- a/Symfony/src/AppBundle/Entity/User.php +++ b/Symfony/src/AppBundle/Entity/User.php @@ -6,12 +6,14 @@ use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Validator\Constraints as Assert; use Doctrine\Common\Collections\ArrayCollection; +use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; /** * User * * @ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository") - * + * @UniqueEntity(fields="email", message="Email is already in use") + * @UniqueEntity(fields="username", message="Username is already in use") * @SuppressWarnings(PHPMD.ShortVariable) */ class User implements UserInterface, \Serializable diff --git a/Symfony/src/AppBundle/Resources/views/Dashboard/index.html.twig b/Symfony/src/AppBundle/Resources/views/Dashboard/index.html.twig index 06cb543..7f59e75 100644 --- a/Symfony/src/AppBundle/Resources/views/Dashboard/index.html.twig +++ b/Symfony/src/AppBundle/Resources/views/Dashboard/index.html.twig @@ -15,7 +15,17 @@ {% if tier != null %} Your current tier is {{ tier.tierName }}. {% endif %} -
+ +

@@ -89,6 +99,7 @@ {% block javascripts %} + {% include 'AppBundle:Dashboard:js.html.twig' %} diff --git a/Symfony/src/AppBundle/Resources/views/Register/index.html.twig b/Symfony/src/AppBundle/Resources/views/Register/index.html.twig index 0654b21..c4637f2 100644 --- a/Symfony/src/AppBundle/Resources/views/Register/index.html.twig +++ b/Symfony/src/AppBundle/Resources/views/Register/index.html.twig @@ -47,10 +47,14 @@

Please confirm password

+
-
@@ -63,3 +67,7 @@
{% endblock %} + +{% block javascripts %} + {% include 'AppBundle:Register:js.html.twig' %} +{% endblock %} diff --git a/Symfony/src/AppBundle/Resources/views/Register/js.html.twig b/Symfony/src/AppBundle/Resources/views/Register/js.html.twig new file mode 100644 index 0000000..a2d69bb --- /dev/null +++ b/Symfony/src/AppBundle/Resources/views/Register/js.html.twig @@ -0,0 +1,17 @@ + diff --git a/Symfony/src/AppBundle/Resources/views/Tier/index.html.twig b/Symfony/src/AppBundle/Resources/views/Tier/index.html.twig index b048ef2..e4b6b7f 100644 --- a/Symfony/src/AppBundle/Resources/views/Tier/index.html.twig +++ b/Symfony/src/AppBundle/Resources/views/Tier/index.html.twig @@ -26,7 +26,7 @@

{% if tier.price > 0 %} - {{ tier.price|price }}
/ month + {{ tier.price|price(2) }}
/ month {% else %} FREE!

diff --git a/Symfony/tests/AppBundle/Controller/RegisterControllerTest.php b/Symfony/tests/AppBundle/Controller/RegisterControllerTest.php index af33669..2fc6fc4 100644 --- a/Symfony/tests/AppBundle/Controller/RegisterControllerTest.php +++ b/Symfony/tests/AppBundle/Controller/RegisterControllerTest.php @@ -28,7 +28,7 @@ public function testRegisterProcess() $this->assertEquals(200, $client->getResponse()->getStatusCode()); $crawler = $client->submit($form); - $this->assertEquals(500, $client->getResponse()->getStatusCode()); - $this->assertContains("Duplicate entry 'alexyao999'", $crawler->text()); + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertContains("is already in use", $crawler->text()); } }