From 22c953398ab3037acbead1ed13a15f049def3636 Mon Sep 17 00:00:00 2001 From: Alex Yao Date: Fri, 8 Apr 2016 22:40:50 +0800 Subject: [PATCH 1/5] Fix tier display --- Symfony/src/AppBundle/Resources/views/Tier/index.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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!

From d08d87c523bd18a128617284d6fc3e220ef6f81e Mon Sep 17 00:00:00 2001 From: Alex Yao Date: Fri, 8 Apr 2016 22:41:42 +0800 Subject: [PATCH 2/5] Fix display for same password and unique constraint message during registration --- .../Controller/RegisterController.php | 18 +++++++++++------- Symfony/src/AppBundle/Entity/User.php | 4 +++- .../Resources/views/Register/index.html.twig | 10 +++++++++- .../Resources/views/Register/js.html.twig | 17 +++++++++++++++++ 4 files changed, 40 insertions(+), 9 deletions(-) create mode 100644 Symfony/src/AppBundle/Resources/views/Register/js.html.twig 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/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/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..8c6b0a6 --- /dev/null +++ b/Symfony/src/AppBundle/Resources/views/Register/js.html.twig @@ -0,0 +1,17 @@ + \ No newline at end of file From 9ec43e1ce1ef62c61aee04f9ca2992ad2ed1093f Mon Sep 17 00:00:00 2001 From: Alex Yao Date: Fri, 8 Apr 2016 22:42:04 +0800 Subject: [PATCH 3/5] Allowed choosing of user tiers in dashboard page --- .../Controller/DashboardController.php | 5 +++- .../Controller/UpdateTierController.php | 25 +++++++++++++++++++ .../Resources/views/Dashboard/index.html.twig | 13 +++++++++- .../Resources/views/Dashboard/js.html.twig | 14 +++++++++++ 4 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 Symfony/src/AppBundle/Controller/UpdateTierController.php create mode 100644 Symfony/src/AppBundle/Resources/views/Dashboard/js.html.twig 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/UpdateTierController.php b/Symfony/src/AppBundle/Controller/UpdateTierController.php new file mode 100644 index 0000000..b4b576b --- /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/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' %} From 021f784fa1690ac1725b8cf4e0d6ba996e4a0350 Mon Sep 17 00:00:00 2001 From: Alex Yao Date: Fri, 8 Apr 2016 22:45:28 +0800 Subject: [PATCH 4/5] Fix sensiolabs insights issues --- Symfony/src/AppBundle/Controller/UpdateTierController.php | 2 +- Symfony/src/AppBundle/Resources/views/Register/js.html.twig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Symfony/src/AppBundle/Controller/UpdateTierController.php b/Symfony/src/AppBundle/Controller/UpdateTierController.php index b4b576b..f7ca9e6 100644 --- a/Symfony/src/AppBundle/Controller/UpdateTierController.php +++ b/Symfony/src/AppBundle/Controller/UpdateTierController.php @@ -16,7 +16,7 @@ public function updateAction(Request $request, $owner) $data = $request->request->all(); $entityManager = $this->getDoctrine()->getManager(); $user = $entityManager->getRepository('AppBundle:User')->find($owner); - if ($data["tier"] != null && $data["tier"] > 0) { + if ($data["tier"] !== null && $data["tier"] > 0) { $user->setTier($data["tier"]); } $entityManager->flush(); diff --git a/Symfony/src/AppBundle/Resources/views/Register/js.html.twig b/Symfony/src/AppBundle/Resources/views/Register/js.html.twig index 8c6b0a6..a2d69bb 100644 --- a/Symfony/src/AppBundle/Resources/views/Register/js.html.twig +++ b/Symfony/src/AppBundle/Resources/views/Register/js.html.twig @@ -14,4 +14,4 @@ $("#registerButton").prop('disabled', true); $("#differentPasswordAlert").show(); } - \ No newline at end of file + From caca7698bf82369f0394cbae4c755be4c7aaac49 Mon Sep 17 00:00:00 2001 From: Alex Yao Date: Fri, 8 Apr 2016 23:35:13 +0800 Subject: [PATCH 5/5] Fix register test --- Symfony/tests/AppBundle/Controller/RegisterControllerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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()); } }