Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Úkol 2 - Jan Suchánek #17

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
10 changes: 9 additions & 1 deletion app/Resources/views/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@
<a href="{{ path("homepage") }}">Domů</a>
</li>
</ul>
<p class="navbar-text navbar-right">
{% if user is defined and user %}
<a href="{{ path("user_edit") }}" class="navbar-link">{{ user.username }}</a>
| <a href="{{ path("user_logout") }}" class="navbar-link">Odhlásit</a>
{% else %}
<a href="{{ path("user_login") }}" class="navbar-link">Přihlásit</a>
| <a href="{{ path("user_registration") }}" class="navbar-link">Registrovat</a>
{% endif %}
</p>
</div>
<!-- /.navbar-collapse -->
</div>
Expand All @@ -59,7 +68,6 @@
<div class="row">

<div class="col-md-3">
<p class="lead">Menu</p>
{% include "components/menu.html.twig" %}
</div>

Expand Down
1 change: 1 addition & 0 deletions app/Resources/views/category/detail.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
<div class="row">
{% include 'components/list.html.twig' %}
</div>
{% include ":components:paginator.html.twig" %}
{% endblock %}

33 changes: 18 additions & 15 deletions app/Resources/views/components/menu.html.twig
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
<div class="list-group">
{% if category is defined %}
{% if category.topCategory != category.parentCategory and category.topCategory != category and category.topCategory != null %}
<a href="{{ path("category_detail", {"slug": category.topCategory.slug }) }}" class="list-group-item">{{ category.topCategory.menuTitle }}</a>
{% if categories is defined or category is defined%}
<p class="lead">Menu</p>
<div class="list-group">
{% if category is defined %}
{% if category.topCategory != category.parentCategory and category.topCategory != category and category.topCategory != null %}
<a href="{{ path("category_detail", {"slug": category.topCategory.slug }) }}" class="list-group-item">{{ category.topCategory.menuTitle }}</a>
{% endif %}
{% if category.parentCategory != null %}
<a href="{{ path("category_detail", {"slug": category.parentCategory.slug }) }}" class="list-group-item">{{ category.parentCategory.menuTitle }}</a>
{% endif %}
<a href="{{ path("category_detail", {"slug": category.slug }) }}" class="list-group-item"><strong>{{ category.menuTitle }}</strong></a>
{% endif %}
{% if categories is defined %}
{% for category in categories %}
<a href="{{ path("category_detail", {"slug": category.slug }) }}" class="list-group-item">{{ category.menuTitle }}</a>
{% endfor %}
{% endif %}
{% if category.parentCategory != null %}
<a href="{{ path("category_detail", {"slug": category.parentCategory.slug }) }}" class="list-group-item">{{ category.parentCategory.menuTitle }}</a>
{% endif %}
<a href="{{ path("category_detail", {"slug": category.slug }) }}" class="list-group-item"><strong>{{ category.menuTitle }}</strong></a>
{% endif %}
{% if categories is defined %}
{% for category in categories %}
<a href="{{ path("category_detail", {"slug": category.slug }) }}" class="list-group-item">{{ category.menuTitle }}</a>
{% endfor %}
{% endif %}
</div>
</div>
{% endif %}
21 changes: 21 additions & 0 deletions app/Resources/views/components/paginator.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<nav aria-label="Page navigation">
<ul class="pagination">
{% if currentPage > 1 %}
<li>
<a href="{{ path(app.request.attributes.get('_route'), app.request.attributes.get('_route_params')|merge({"page": currentPage - 1 })) }}" aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
</a>
</li>
{% endif %}
{% for page in pageRange %}
<li><a href="{{ path(app.request.attributes.get('_route'), app.request.attributes.get('_route_params')|merge({"page": page })) }}" {% if page == currentPage %} class="active"{% endif %}>{{ page }}</a></li>
{% endfor %}
{% if currentPage < totalPages %}
<li>
<a href="{{ path(app.request.attributes.get('_route'), app.request.attributes.get('_route_params')|merge({"page": currentPage + 1 })) }}" aria-label="Next">
<span aria-hidden="true">&raquo;</span>
</a>
</li>
{% endif %}
</ul>
</nav>
76 changes: 0 additions & 76 deletions app/Resources/views/default/index.html.twig

This file was deleted.

1 change: 1 addition & 0 deletions app/Resources/views/homepage/homepage.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
<div class="row">
{% include 'components/list.html.twig' %}
</div>
{% include ":components:paginator.html.twig" %}
{% endblock %}

5 changes: 0 additions & 5 deletions app/Resources/views/product/detail.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

{% block body %}
<ol class="breadcrumb">
<li>
<a href="{{ path("category_detail", {"slug": product.firstCategory.slug}) }}">
{{ product.firstCategory.title }}
</a>
</li>
<li class="active">{{ product.title }}</li>
</ol>
<h1> {{ product.title }}</h1>
Expand Down
31 changes: 31 additions & 0 deletions app/Resources/views/user/login.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{% extends 'base.html.twig' %}

{% block body %}
{% if error %}
<div class="alert alert-danger" role="alert">
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
<span class="sr-only">Error:</span>
{{ error.messageKey|trans(error.messageData, 'security') }}
</div>
{% endif %}


<form action="{{ path('user_login') }}" method="post" class="form-signin">
<label for="inputEmail" class="sr-only">E-mail</label>
<input type="email" id="inputEmail" class="form-control" placeholder="E-mail" name="_username" value="{{ last_username }}" required autofocus>
<label for="inputPassword" class="sr-only">Heslo</label>
<input type="password" id="inputPassword" class="form-control" placeholder="Heslo" name="_password" required>
<input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}"/>
<div class="checkbox">
<label>
<input type="checkbox" value="remember-me"> Zapamatovat
</label>
</div>
{#
If you want to control the URL the user is redirected to on success (more details below)
<input type="hidden" name="_target_path" value="/account" />
#}
<button class="btn btn-lg btn-primary btn-block" type="submit">Přihlásit</button>
</form>
{% endblock %}

11 changes: 11 additions & 0 deletions app/Resources/views/user/registration.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends 'base.html.twig' %}

{% block body %}
{{ form_start(form) }}
{{ form_row(form.username) }}
{{ form_row(form.plainPassword.first) }}
{{ form_row(form.plainPassword.second) }}
<br />
<button class="btn btn-lg btn-primary btn-block" type="submit">Registrovat!</button>
{{ form_end(form) }}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends 'base.html.twig' %}

{% block body %}
<h1>Hello {{ who }}!</h1>
Hello {{ user.username }}
{% endblock %}
14 changes: 14 additions & 0 deletions app/Resources/views/user/user_edit.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% extends 'base.html.twig' %}

{% block body %}
<h1>Adresa uživatele</h1>
{{ form_start(form) }}
{{ form_row(form.firstName) }}
{{ form_row(form.surName) }}
{{ form_row(form.street) }}
{{ form_row(form.city) }}
{{ form_row(form.zip) }}
<br />
<button class="btn btn-lg btn-primary btn-block" type="submit">Upravit</button>
{{ form_end(form) }}
{% endblock %}
35 changes: 19 additions & 16 deletions app/config/security.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
# To get started with security, check out the documentation:
# http://symfony.com/doc/current/book/security.html
security:
encoders:
AppBundle\Entity\User:
algorithm: bcrypt
cost: 13 #cost is 13 by default, just so you know why and how to set it

# http://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers
providers:
in_memory:
memory: ~
database_users:
entity: { class: AppBundle:User, property: username }

firewalls:
# disables authentication for assets and the profiler, adapt it according to your needs
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
secured_area:
pattern: ^/

main:
anonymous: ~
# activate different ways to authenticate
anonymous: true

# http_basic: ~
# http://symfony.com/doc/current/book/security.html#a-configuring-how-your-users-will-authenticate
form_login:
check_path: user_login
login_path: user_login
csrf_token_generator: security.csrf.token_manager
default_target_path: /

# form_login: ~
# http://symfony.com/doc/current/cookbook/security/form_login_setup.html
logout:
# The route name the user can go to in order to logout
path: user_logout
# The name of the route to redirect to after logging out
target: homepage
45 changes: 42 additions & 3 deletions app/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,45 @@ parameters:
# parameter_name: value

services:
# service_name:
# class: AppBundle\Directory\ClassName
# arguments: ["@another_service_name", "plain_value", "%parameter_name%"]
app.controller.category_controller:
class: AppBundle\Controller\CategoryController
autowire: true

app.controller.homepage_controller:
class: AppBundle\Controller\HomepageController
autowire: true

app.controller.product_controller:
class: AppBundle\Controller\ProductController
autowire: true

app.controller.user_controller:
class: AppBundle\Controller\UserController
autowire: true

app.facade.category_facade:
class: AppBundle\Facade\CategoryFacade
autowire: true

app.facade.product_facade:
class: AppBundle\Facade\ProductFacade
autowire: true

app.facade.user_facade:
class: AppBundle\Facade\UserFacade
autowire: true

app.repository.category_repository:
class: AppBundle\Repository\CategoryRepository
factory: ['@doctrine.orm.default_entity_manager', getRepository]
arguments: ['AppBundle\Entity\Category']

app.repository.product_repository:
class: AppBundle\Repository\ProductRepository
factory: ['@doctrine.orm.default_entity_manager', getRepository]
arguments: ['AppBundle\Entity\Product']

encoder:
class: Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder
arguments:
- 13
13 changes: 8 additions & 5 deletions bin/symfony_requirements
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ echo '> Checking Symfony requirements:'.PHP_EOL.' ';

$messages = array();
foreach ($symfonyRequirements->getRequirements() as $req) {
/** @var $req Requirement */
if ($helpText = get_error_message($req, $lineSize)) {
echo_style('red', 'E');
$messages['error'][] = $helpText;
Expand Down Expand Up @@ -121,10 +120,14 @@ function echo_block($style, $title, $message)

echo PHP_EOL.PHP_EOL;

echo_style($style, str_repeat(' ', $width).PHP_EOL);
echo_style($style, str_pad(' ['.$title.']', $width, ' ', STR_PAD_RIGHT).PHP_EOL);
echo_style($style, str_pad($message, $width, ' ', STR_PAD_RIGHT).PHP_EOL);
echo_style($style, str_repeat(' ', $width).PHP_EOL);
echo_style($style, str_repeat(' ', $width));
echo PHP_EOL;
echo_style($style, str_pad(' ['.$title.']', $width, ' ', STR_PAD_RIGHT));
echo PHP_EOL;
echo_style($style, $message);
echo PHP_EOL;
echo_style($style, str_repeat(' ', $width));
echo PHP_EOL;
}

function has_color_support()
Expand Down
Loading