Skip to content

Commit

Permalink
Merge pull request #2 from BAD-WOLF/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
BAD-WOLF authored Aug 11, 2023
2 parents 28eaf3b + 4eeb8e5 commit 07a1a26
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 29 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/symfony.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Symfony

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

permissions:
contents: read

jobs:
symfony-tests:
runs-on: ubuntu-latest
steps:
# To automatically get bug fixes and new Php versions for shivammathur/setup-php,
# change this to (see https://github.com/shivammathur/setup-php#bookmark-versioning):
# uses: shivammathur/setup-php@v2
- uses: shivammathur/setup-php@2cb9b829437ee246e9b3cac53555a39208ca6d28
with:
php-version: '8.2'
- uses: actions/checkout@v3
- name: Copy .env.test.local
run: php -r "file_exists('.env.test.local') || copy('.env.test', '.env.test.local');"
- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install Dependencies
run: |
composer update
composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Create Database
run: |
mkdir -p data
touch data/database.sqlite
- name: Execute tests (Unit and Feature tests) via PHPUnit
env:
DATABASE_URL: sqlite:///%kernel.project_dir%/data/database.sqlite
run: vendor/bin/phpunit
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# STUDIES
5 changes: 5 additions & 0 deletions assets/styles/global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ $primary: darken(#428bca, 20%);
background-image: url("../images_to_images/images/quadro-poster-paisagem-04-detalhes-abaixo-para-imprimir.jpg");
}

.left-end {
display: flex;
justify-content: end;
}

5 changes: 1 addition & 4 deletions assets/styles/login/app.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
.forgot {
display: flex;
justify-content: end;
}

5 changes: 3 additions & 2 deletions config/packages/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ security:
# Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used
access_control:
# - { path: ^/admin, roles: ROLE_ADMIN }
- { path: ^/home, roles: ROLE_NORMAL_USER }
- { path: ^/(new|delete), roles: ROLE_ADMIN }
- { path: ^/(edit|register/admin), roles: ROLE_NORMAL_USER }
- { path: ^/(home|show), roles: PUBLIC_ACCESS }

when@test:
security:
Expand Down
9 changes: 4 additions & 5 deletions src/Controller/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;

#[Route('/home')]
class HomeController extends AbstractController
{
#[Route('/', name: 'app_home_index', methods: ['GET'])]
#[Route(['/home', '/'], name: 'app_home_index', methods: ['GET'])]
public function index(ProdutoRepository $produtoRepository): Response
{
return $this->render('home/index.html.twig', [
Expand Down Expand Up @@ -43,15 +42,15 @@ public function new(Request $request, EntityManagerInterface $entityManager): Re
]);
}

#[Route('/{id}', name: 'app_home_show', methods: ['GET'])]
#[Route('/show/{id}', name: 'app_home_show', methods: ['GET'])]
public function show(Produto $produto): Response
{
return $this->render('home/show.html.twig', [
'produto' => $produto,
]);
}

#[Route('/{id}/edit', name: 'app_home_edit', methods: ['GET', 'POST'])]
#[Route('/edit/{id}', name: 'app_home_edit', methods: ['GET', 'POST'])]
public function edit(Request $request, Produto $produto, EntityManagerInterface $entityManager): Response
{
$form = $this->createForm(ProdutoType::class, $produto);
Expand All @@ -69,7 +68,7 @@ public function edit(Request $request, Produto $produto, EntityManagerInterface
]);
}

#[Route('/{id}', name: 'app_home_delete', methods: ['POST'])]
#[Route('/delete/{id}', name: 'app_home_delete', methods: ['POST'])]
public function delete(Request $request, Produto $produto, EntityManagerInterface $entityManager): Response
{
if ($this->isCsrfTokenValid('delete'.$produto->getId(), $request->request->get('_token'))) {
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class LoginController extends AbstractController
{
#[Route(path:['/', 'login'], name: 'app_login')]
#[Route(path: 'login', name: 'app_login')]
public function login(AuthenticationUtils $authenticationUtils): Response
{
// get the login error if there is one
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/RegistrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(EmailVerifier $emailVerifier)
$this->emailVerifier = $emailVerifier;
}

#[Route('/register', name: 'app_register')]
#[Route('/register/{role<user|admin>}', name: 'app_register')]
public function register(Request $request, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager): Response
{
$user = new User();
Expand Down
5 changes: 5 additions & 0 deletions templates/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
<html>
<head>
<meta charset="UTF-8">
{% block metas %}
<meta property="og:image" content="https://c9a5-2804-7f7-a089-afde-3735-7b0c-e6e2-d038.ngrok-free.app/build/images/quadro-poster-paisagem-04-detalhes-abaixo-para-imprimir.jpg"/>
<meta property="og:description" content="Stock Only Test: só de testa ja esta me ajudando"/>
<meta property="og:url" content="https://www.stock.com"/>
{% endblock %}
<title>{% block title %}Welcome!{% endblock %}</title>
<link rel="icon" href={{ asset('build/images/modular-symfony-development-igniti-en.png') }} type="image/png"/>
{% block stylesheets %}
Expand Down
26 changes: 20 additions & 6 deletions templates/home/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@

{% block body %}


<h1>Produto index</h1>
{% if app.user %}
<div class="mb-3 logout">
You are logged in as {{ app.user.userIdentifier }}, <a href={{ path('app_logout') }}>Logout</a>
You are logged in as {{ app.user.userIdentifier }}, <a href={{ path('app_logout') }}>Logout?</a>
</div>
{% else %}
Register to more privileges:</br>
<a href={{ path("app_login", parameters = []) }}> <button>Go to login</button> </a>
{% endif %}

<h1>Produto index</h1>

<table class="table">
<thead>
<tr>
Expand All @@ -30,8 +33,14 @@
<td>{{ produto.amount }}</td>
<td>{{ produto.datetime ? produto.datetime|date('Y-m-d H:i:s') : '' }}</td>
<td>
<a href={{ path('app_home_show', {'id': produto.id}) }}>show</a>
<a href={{ path('app_home_edit', {'id': produto.id}) }}>edit</a>
<div class="left-end">
<a href={{ path('app_home_show', {'id': produto.id}) }}> <button class="btn btn-outline-info">show</button> </a>
{% if app.user %}
{% if app.user.roles.0 in ["ROLE_NORMAL_USER", "ROLE_ADMIN"] %}
<a href={{ path('app_home_edit', {'id': produto.id}) }}> <button class="btn btn-outline-dark">edit</button> </a>
{% endif %}
{% endif %}
</div>
</td>
</tr>
{% else %}
Expand All @@ -43,7 +52,12 @@
</table>

{% if app.user %}
<a href={{ path('app_home_new') }}><button class="btn btn-outline-success-">Create new</button></a>
{% if app.user.roles.0 == "ROLE_ADMIN" %}
<a href={{ path('app_home_new') }}><button class="btn btn-outline-success-">Create new</button></a>
{% elseif app.user.roles.0 == "ROLE_NORMAL_USER" %}
you can become admin for more privileges: </br>
<a href={{ path("app_register", {'role':'admin'}) }}><button class="btn btn-outline-success">Go to admin regiser</button></a>
{% endif %}
{% endif %}

{% endblock %}
12 changes: 2 additions & 10 deletions templates/login/login.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
<div class="alert alert-danger">{{ error.messageKey|trans(error.messageData, 'security') }}</div>
{% endif %}

{% if app.user %}
<div class="mb-3">
You are logged in as {{ app.user.userIdentifier }}, <a href="{{ path('app_logout') }}">Logout</a>
</div>
{% endif %}

<h1 class="h3 mb-3 font-weight-normal">Please sign in</h1>
<label for="username">Email</label>
<input type="email" value="{{ last_username }}" name="_username" id="username" class="form-control" autocomplete="email" required autofocus>
Expand Down Expand Up @@ -52,10 +46,8 @@
</button>
</div>
</div>
<a class="btn btn-secondary" href="{{ path('app_register') }}">Register</a>
<div class="forgot">
<a class="btn btn-secondary" href="{{ path('app_forgot_password_request') }}">forgot password</a>
</div>
<a class="btn btn-secondary" href={{ path("app_register", {'role':'user'}) }}>Register</a>
<a class="{# left-end #}btn btn-secondary" href={{ path('app_forgot_password_request') }}>forgot password</a>
</form>
</div>
{% endblock %}

0 comments on commit 07a1a26

Please sign in to comment.