Skip to content

Commit

Permalink
Merge pull request #45 from codebendercc/minor-wording-and-improvements
Browse files Browse the repository at this point in the history
Minor wording and improvements
  • Loading branch information
spiliot committed Apr 8, 2016
2 parents 58a8c1d + 7925983 commit 53b5e2f
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 14 deletions.
5 changes: 4 additions & 1 deletion Symfony/src/AppBundle/Controller/DashboardController.php
Expand Up @@ -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));
}
}
18 changes: 11 additions & 7 deletions Symfony/src/AppBundle/Controller/RegisterController.php
Expand Up @@ -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));
Expand Down
25 changes: 25 additions & 0 deletions Symfony/src/AppBundle/Controller/UpdateTierController.php
@@ -0,0 +1,25 @@
<?php
namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class UpdateTierController extends Controller
{
/**
* @Route("/update_tier/{owner}", name="update_tier")
*/
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) {
$user->setTier($data["tier"]);
}
$entityManager->flush();
return new Response();
}
}
4 changes: 3 additions & 1 deletion Symfony/src/AppBundle/Entity/User.php
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion Symfony/src/AppBundle/Resources/views/Dashboard/index.html.twig
Expand Up @@ -15,7 +15,17 @@
{% if tier != null %}
Your current tier is {{ tier.tierName }}.
{% endif %}
</h3><br>
</h3>
<select id="changeTier" onChange="tierValueChanged()">
<option value="0" disabled selected hidden>
Change your tier
</option>
{% for curtier in tiers %}
<option value="{{ curtier.id }}" >
{{ curtier.tierName }}
</option>
{% endfor %}
</select><br><br>
<div class="table-responsive">
<table class="table table-condensed table-striped table-hover table-bordered">
<tbody>
Expand Down Expand Up @@ -89,6 +99,7 @@
{% block javascripts %}
<script src="{{ asset('//cdnjs.cloudflare.com/ajax/libs/lightbox2/2.8.2/js/lightbox.min.js') }}"></script>
<script src="{{ asset('//cdnjs.cloudflare.com/ajax/libs/clipboard.js/1.5.8/clipboard.min.js') }}"></script>
{% include 'AppBundle:Dashboard:js.html.twig' %}
<script type="text/javascript">
$(document).ready(function ($) {
new Clipboard('.btn');
Expand Down
14 changes: 14 additions & 0 deletions Symfony/src/AppBundle/Resources/views/Dashboard/js.html.twig
@@ -0,0 +1,14 @@
<script>
function tierValueChanged() {
$.ajax({
type: "POST",
url: "{{ path('update_tier', {'owner': user.id }) }}",
data: {
'tier': $("#changeTier").val()
}
}).done(function () {
$("#changeTier").val(0);
location.reload();
});
}
</script>
10 changes: 9 additions & 1 deletion Symfony/src/AppBundle/Resources/views/Register/index.html.twig
Expand Up @@ -47,10 +47,14 @@
</div>
<p class="help-block">Please confirm password</p>
</div>
<div id="differentPasswordAlert" class="alert alert-danger alert-dismissible"
style="" role="alert">
Passwords do not match!
</div>
<br>
<div class="control-group">
<div class="controls">
<button class="btn btn-lg btn-primary btn-block" type="submit"
<button id="registerButton" class="btn btn-lg btn-primary btn-block" type="submit"
name="register-button">Register
</button>
</div>
Expand All @@ -63,3 +67,7 @@
</div>
</div>
{% endblock %}

{% block javascripts %}
{% include 'AppBundle:Register:js.html.twig' %}
{% endblock %}
17 changes: 17 additions & 0 deletions Symfony/src/AppBundle/Resources/views/Register/js.html.twig
@@ -0,0 +1,17 @@
<script>
$(document).ready(function () {
$("#registerButton").prop('disabled', true);
$("#registration_password_second").keyup(checkPasswordMatch);
});
function checkPasswordMatch() {
var password = $("#registration_password_first").val();
var confirmPassword = $("#registration_password_second").val();
if (password == confirmPassword) {
$("#differentPasswordAlert").fadeOut(500);
$("#registerButton").prop('disabled', false);
return;
}
$("#registerButton").prop('disabled', true);
$("#differentPasswordAlert").show();
}
</script>
2 changes: 1 addition & 1 deletion Symfony/src/AppBundle/Resources/views/Tier/index.html.twig
Expand Up @@ -26,7 +26,7 @@
<div class="panel-body text-center">
<p class="lead" style="font-size:40px"><strong>
{% if tier.price > 0 %}
{{ tier.price|price }} <br> / month
{{ tier.price|price(2) }} <br> / month
{% else %}
FREE!
<br><br>
Expand Down
4 changes: 2 additions & 2 deletions Symfony/tests/AppBundle/Controller/RegisterControllerTest.php
Expand Up @@ -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());
}
}

0 comments on commit 53b5e2f

Please sign in to comment.