Skip to content

Commit

Permalink
Merge pull request #1 from BAD-WOLF/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
BAD-WOLF authored Aug 9, 2023
2 parents 553f620 + 0dd21e3 commit 28eaf3b
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ APP_SECRET=915aa68d9139b44e91cf5839bea51b5a
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
#
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
DATABASE_URL="mysql://@127.0.0.1:3306/test?charset=utf8mb4"
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
# DATABASE_URL="mysql://@127.0.0.1:3306/test?charset=utf8mb4"
DATABASE_URL="mysql://matheu:senha1234J!@127.0.0.1:3306/test?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
# DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=15&charset=utf8"
###< doctrine/doctrine-bundle ###

Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions config/packages/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ security:
path: app_logout
# where to redirect after logout
# target: app_any_route

user_checker: App\Security\CustomAuthLogin
# activate different ways to authenticate
# https://symfony.com/doc/current/security.html#the-firewall

Expand All @@ -36,7 +36,7 @@ security:
# Note: Only the *first* access control that matches will be used
access_control:
# - { path: ^/admin, roles: ROLE_ADMIN }
# - { path: ^/home, roles: ROLE_USER }
- { path: ^/home, roles: ROLE_NORMAL_USER }

when@test:
security:
Expand Down
1 change: 0 additions & 1 deletion src/Controller/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;

#[IsGranted("ROLE_USER")]
#[Route('/home')]
class HomeController extends AbstractController
{
Expand Down
32 changes: 32 additions & 0 deletions src/Controller/RegistrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Entity\User;
use App\Form\RegistrationFormType;
use App\Form\ReverifyType;
use App\Repository\UserRepository;
use App\Security\EmailVerifier;
use Doctrine\ORM\EntityManagerInterface;
Expand Down Expand Up @@ -94,4 +95,35 @@ public function verifyUserEmail(Request $request, TranslatorInterface $translato

return $this->redirectToRoute('app_login');
}

#[Route("/send-reverify", "app_reverify")]
public function reverify(Request $request, UserRepository $userRepository) {
if ($this->getUser()) {
return $this->redirectToRoute("app_home_index");
}

$form = $this->createForm(ReverifyType::class);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$user = $userRepository->findOneBy(["email" => $form->get("email")->getData()]);
if ($user) {
$this->emailVerifier->sendEmailConfirmation(
"app_verify_email",
$user,
(new TemplatedEmail())
->from(new Address("matheusviaira160@gmail.com"))
->to($user->getEmail())
->subject("Matheus Vieira")
->htmlTemplate('registration/confirmation_email.html.twig')
);
return $this->redirectToRoute("app_login");
} else {
$this->addFlash("error", "Incorrect Email");
}
}
return $this->render("registration/reverify.html.twig", [
"reverifyForm" => $form
]);
}
}
2 changes: 1 addition & 1 deletion src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
$roles[] = '';

return array_unique($roles);
}
Expand Down
39 changes: 39 additions & 0 deletions src/Form/ReverifyType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\NotBlank;

class ReverifyType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('email', EmailType::class, [
"label" => "email",
"attr" => [
"autocomplete" => "email",
"placeholder" => "Sey me your email ..."
],
"constraints" => [
new NotBlank([
"message" => "You have sey me your email"
])
]
])
->add("submit", SubmitType::class)
;
}

public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
// Configure your form options here
]);
}
}
29 changes: 29 additions & 0 deletions src/Security/CustomAuthLogin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
namespace App\Security;

use App\Entity\User;
use Symfony\Component\Security\Core\Exception\CustomUserMessageAccountStatusException;
use Symfony\Component\Security\Core\User\UserCheckerInterface;
use Symfony\Component\Security\Core\User\UserInterface;

class CustomAuthLogin implements UserCheckerInterface {
public function checkPreAuth(UserInterface $user)
{
if (!$user instanceof User) {
return;
}
if (!$user->isVerified()) {
throw new CustomUserMessageAccountStatusException("Quase lá, verifique seu email para ativar a sua conta!!");
}
}
public function checkPostAuth(UserInterface $user)
{
if (!$user instanceof User) {
return;
}
if (!$user->isVerified()) {
throw new CustomUserMessageAccountStatusException("Quase lá, verifique seu email para ativar a sua conta!!");
}
}
}
?>
18 changes: 14 additions & 4 deletions templates/home/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
{% block title %}Produto index{% endblock %}

{% block body %}

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

<h1>Produto index</h1>

<table class="table">
Expand All @@ -23,8 +30,8 @@
<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>
<a href={{ path('app_home_show', {'id': produto.id}) }}>show</a>
<a href={{ path('app_home_edit', {'id': produto.id}) }}>edit</a>
</td>
</tr>
{% else %}
Expand All @@ -33,7 +40,10 @@
</tr>
{% endfor %}
</tbody>
</table>
</table>

{% if app.user %}
<a href={{ path('app_home_new') }}><button class="btn btn-outline-success-">Create new</button></a>
{% endif %}

<a href="{{ path('app_home_new') }}">Create new</a>
{% endblock %}
4 changes: 3 additions & 1 deletion templates/registration/register.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
{{ form_row(registrationForm.submit) }}
</div>
</div>
<a class="forgot btn btn-secondary" href={{ path("app_login") }}>Return to login</a>
<a class="btn btn-outline-success" href={{ path("app_login") }}>Return to login</a>
<a class="forgot btn btn-outline-secondary" href={{ path("app_reverify", parameters = []) }}>Reques a new verification email</a>
{{ form_end(registrationForm) }}

</div>
{% endblock %}
5 changes: 5 additions & 0 deletions templates/registration/reverify.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% extends 'base.html.twig' %}

{% block body %}
{{ form(reverifyForm) }}
{% endblock %}

0 comments on commit 28eaf3b

Please sign in to comment.