minor updates

This commit is contained in:
tracer 2021-06-13 13:23:56 +02:00
parent e2f82a9b4a
commit 59d3663cab
40 changed files with 1632 additions and 575 deletions

View File

@ -1,12 +0,0 @@
/*
* Welcome to your app's main JavaScript file!
*
* We recommend including the built version of this JavaScript file
* (and its CSS file) in your base layout (base.html.twig).
*/
// any CSS you import will output into a single css file (app.css in this case)
import './styles/app.css';
// start the Stimulus application
import './bootstrap';

View File

@ -19,12 +19,14 @@
"symfony/flex": "^1.3.1", "symfony/flex": "^1.3.1",
"symfony/framework-bundle": "5.3.*", "symfony/framework-bundle": "5.3.*",
"symfony/mailer": "5.3.*", "symfony/mailer": "5.3.*",
"symfony/monolog-bundle": "^3.7",
"symfony/proxy-manager-bridge": "5.3.*", "symfony/proxy-manager-bridge": "5.3.*",
"symfony/security-bundle": "5.3.*", "symfony/security-bundle": "5.3.*",
"symfony/twig-bundle": "^5.2", "symfony/twig-bundle": "^5.2",
"symfony/validator": "5.3.*", "symfony/validator": "5.3.*",
"symfony/webpack-encore-bundle": "^1.11", "symfony/webpack-encore-bundle": "^1.11",
"symfony/yaml": "5.3.*", "symfony/yaml": "5.3.*",
"symfonycasts/reset-password-bundle": "^1.8",
"symfonycasts/verify-email-bundle": "^1.5", "symfonycasts/verify-email-bundle": "^1.5",
"twig/extra-bundle": "^2.12|^3.0", "twig/extra-bundle": "^2.12|^3.0",
"twig/intl-extra": "^3.3", "twig/intl-extra": "^3.3",

313
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "8933f3ecbe9471974eca76a88ea9b2a4", "content-hash": "34381deb043c87393a1f92bbeab2aaff",
"packages": [ "packages": [
{ {
"name": "composer/package-versions-deprecated", "name": "composer/package-versions-deprecated",
@ -1949,6 +1949,102 @@
], ],
"time": "2021-02-25T21:54:58+00:00" "time": "2021-02-25T21:54:58+00:00"
}, },
{
"name": "monolog/monolog",
"version": "2.2.0",
"source": {
"type": "git",
"url": "https://github.com/Seldaek/monolog.git",
"reference": "1cb1cde8e8dd0f70cc0fe51354a59acad9302084"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Seldaek/monolog/zipball/1cb1cde8e8dd0f70cc0fe51354a59acad9302084",
"reference": "1cb1cde8e8dd0f70cc0fe51354a59acad9302084",
"shasum": ""
},
"require": {
"php": ">=7.2",
"psr/log": "^1.0.1"
},
"provide": {
"psr/log-implementation": "1.0.0"
},
"require-dev": {
"aws/aws-sdk-php": "^2.4.9 || ^3.0",
"doctrine/couchdb": "~1.0@dev",
"elasticsearch/elasticsearch": "^7",
"graylog2/gelf-php": "^1.4.2",
"mongodb/mongodb": "^1.8",
"php-amqplib/php-amqplib": "~2.4",
"php-console/php-console": "^3.1.3",
"phpspec/prophecy": "^1.6.1",
"phpstan/phpstan": "^0.12.59",
"phpunit/phpunit": "^8.5",
"predis/predis": "^1.1",
"rollbar/rollbar": "^1.3",
"ruflin/elastica": ">=0.90 <7.0.1",
"swiftmailer/swiftmailer": "^5.3|^6.0"
},
"suggest": {
"aws/aws-sdk-php": "Allow sending log messages to AWS services like DynamoDB",
"doctrine/couchdb": "Allow sending log messages to a CouchDB server",
"elasticsearch/elasticsearch": "Allow sending log messages to an Elasticsearch server via official client",
"ext-amqp": "Allow sending log messages to an AMQP server (1.0+ required)",
"ext-mbstring": "Allow to work properly with unicode symbols",
"ext-mongodb": "Allow sending log messages to a MongoDB server (via driver)",
"graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server",
"mongodb/mongodb": "Allow sending log messages to a MongoDB server (via library)",
"php-amqplib/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib",
"php-console/php-console": "Allow sending log messages to Google Chrome",
"rollbar/rollbar": "Allow sending log messages to Rollbar",
"ruflin/elastica": "Allow sending log messages to an Elastic Search server"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "2.x-dev"
}
},
"autoload": {
"psr-4": {
"Monolog\\": "src/Monolog"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jordi Boggiano",
"email": "j.boggiano@seld.be",
"homepage": "https://seld.be"
}
],
"description": "Sends your logs to files, sockets, inboxes, databases and various web services",
"homepage": "https://github.com/Seldaek/monolog",
"keywords": [
"log",
"logging",
"psr-3"
],
"support": {
"issues": "https://github.com/Seldaek/monolog/issues",
"source": "https://github.com/Seldaek/monolog/tree/2.2.0"
},
"funding": [
{
"url": "https://github.com/Seldaek",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/monolog/monolog",
"type": "tidelift"
}
],
"time": "2020-12-14T13:15:25+00:00"
},
{ {
"name": "nikic/php-parser", "name": "nikic/php-parser",
"version": "v4.10.5", "version": "v4.10.5",
@ -4183,6 +4279,170 @@
], ],
"time": "2021-05-26T17:43:10+00:00" "time": "2021-05-26T17:43:10+00:00"
}, },
{
"name": "symfony/monolog-bridge",
"version": "v5.3.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/monolog-bridge.git",
"reference": "84841557874df015ef2843aa16ac63d09f97c7b9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/monolog-bridge/zipball/84841557874df015ef2843aa16ac63d09f97c7b9",
"reference": "84841557874df015ef2843aa16ac63d09f97c7b9",
"shasum": ""
},
"require": {
"monolog/monolog": "^1.25.1|^2",
"php": ">=7.2.5",
"symfony/deprecation-contracts": "^2.1",
"symfony/http-kernel": "^5.3",
"symfony/service-contracts": "^1.1|^2"
},
"conflict": {
"symfony/console": "<4.4",
"symfony/http-foundation": "<5.3"
},
"require-dev": {
"symfony/console": "^4.4|^5.0",
"symfony/http-client": "^4.4|^5.0",
"symfony/mailer": "^4.4|^5.0",
"symfony/messenger": "^4.4|^5.0",
"symfony/mime": "^4.4|^5.0",
"symfony/security-core": "^4.4|^5.0",
"symfony/var-dumper": "^4.4|^5.0"
},
"suggest": {
"symfony/console": "For the possibility to show log messages in console commands depending on verbosity settings.",
"symfony/http-kernel": "For using the debugging handlers together with the response life cycle of the HTTP kernel.",
"symfony/var-dumper": "For using the debugging handlers like the console handler or the log server handler."
},
"type": "symfony-bridge",
"autoload": {
"psr-4": {
"Symfony\\Bridge\\Monolog\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Provides integration for Monolog with various Symfony components",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/monolog-bridge/tree/v5.3.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2021-05-26T17:43:10+00:00"
},
{
"name": "symfony/monolog-bundle",
"version": "v3.7.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/monolog-bundle.git",
"reference": "4054b2e940a25195ae15f0a49ab0c51718922eb4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/monolog-bundle/zipball/4054b2e940a25195ae15f0a49ab0c51718922eb4",
"reference": "4054b2e940a25195ae15f0a49ab0c51718922eb4",
"shasum": ""
},
"require": {
"monolog/monolog": "~1.22 || ~2.0",
"php": ">=7.1.3",
"symfony/config": "~4.4 || ^5.0",
"symfony/dependency-injection": "^4.4 || ^5.0",
"symfony/http-kernel": "~4.4 || ^5.0",
"symfony/monolog-bridge": "~4.4 || ^5.0"
},
"require-dev": {
"symfony/console": "~4.4 || ^5.0",
"symfony/phpunit-bridge": "^5.1",
"symfony/yaml": "~4.4 || ^5.0"
},
"type": "symfony-bundle",
"extra": {
"branch-alias": {
"dev-master": "3.x-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Bundle\\MonologBundle\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony MonologBundle",
"homepage": "https://symfony.com",
"keywords": [
"log",
"logging"
],
"support": {
"issues": "https://github.com/symfony/monolog-bundle/issues",
"source": "https://github.com/symfony/monolog-bundle/tree/v3.7.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2021-03-31T07:20:47+00:00"
},
{ {
"name": "symfony/options-resolver", "name": "symfony/options-resolver",
"version": "v5.3.0", "version": "v5.3.0",
@ -6904,6 +7164,57 @@
], ],
"time": "2021-05-26T17:43:10+00:00" "time": "2021-05-26T17:43:10+00:00"
}, },
{
"name": "symfonycasts/reset-password-bundle",
"version": "v1.8.0",
"source": {
"type": "git",
"url": "https://github.com/SymfonyCasts/reset-password-bundle.git",
"reference": "a41cceff06039e586619b1505af05f77b22b41b5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/SymfonyCasts/reset-password-bundle/zipball/a41cceff06039e586619b1505af05f77b22b41b5",
"reference": "a41cceff06039e586619b1505af05f77b22b41b5",
"shasum": ""
},
"require": {
"php": ">=7.2.5",
"symfony/config": "^4.4 | ^5.0",
"symfony/dependency-injection": "^4.4 | ^5.0",
"symfony/deprecation-contracts": "^2.2",
"symfony/http-kernel": "^4.4 | ^5.0"
},
"conflict": {
"doctrine/orm": "<2.7",
"symfony/framework-bundle": "<4.4",
"symfony/http-foundation": "<4.4"
},
"require-dev": {
"doctrine/doctrine-bundle": "^2.0.3",
"doctrine/orm": "^2.7",
"friendsofphp/php-cs-fixer": "^3.0",
"symfony/framework-bundle": "^4.4 | ^5.0",
"symfony/phpunit-bridge": "^5.0",
"vimeo/psalm": "^4.3"
},
"type": "symfony-bundle",
"autoload": {
"psr-4": {
"SymfonyCasts\\Bundle\\ResetPassword\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Symfony bundle that adds password reset functionality.",
"support": {
"issues": "https://github.com/SymfonyCasts/reset-password-bundle/issues",
"source": "https://github.com/SymfonyCasts/reset-password-bundle/tree/v1.8.0"
},
"time": "2021-05-05T18:21:50+00:00"
},
{ {
"name": "symfonycasts/verify-email-bundle", "name": "symfonycasts/verify-email-bundle",
"version": "v1.5.0", "version": "v1.5.0",

View File

@ -13,4 +13,6 @@ return [
SymfonyCasts\Bundle\VerifyEmail\SymfonyCastsVerifyEmailBundle::class => ['all' => true], SymfonyCasts\Bundle\VerifyEmail\SymfonyCastsVerifyEmailBundle::class => ['all' => true],
Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true], Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true],
Knp\Bundle\TimeBundle\KnpTimeBundle::class => ['all' => true], Knp\Bundle\TimeBundle\KnpTimeBundle::class => ['all' => true],
SymfonyCasts\Bundle\ResetPassword\SymfonyCastsResetPasswordBundle::class => ['all' => true],
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
]; ];

View File

@ -0,0 +1,19 @@
monolog:
handlers:
main:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
channels: ["!event"]
# uncomment to get logging in your browser
# you may have to allow bigger header sizes in your Web server configuration
#firephp:
# type: firephp
# level: info
#chromephp:
# type: chromephp
# level: info
console:
type: console
process_psr_3_messages: false
channels: ["!event", "!doctrine", "!console"]

View File

@ -7,9 +7,10 @@ framework:
# Enables session support. Note that the session will ONLY be started if you read or write from it. # Enables session support. Note that the session will ONLY be started if you read or write from it.
# Remove or comment this section to explicitly disable session support. # Remove or comment this section to explicitly disable session support.
session: session:
handler_id: null enabled: true
cookie_secure: auto handler_id: Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler
cookie_samesite: lax cookie_secure: 'auto'
cookie_samesite: 'lax'
#esi: true #esi: true
#fragments: true #fragments: true

View File

@ -0,0 +1,8 @@
# As of Symfony 5.1, deprecations are logged in the dedicated "deprecation" channel when it exists
#monolog:
# channels: [deprecation]
# handlers:
# deprecation:
# type: stream
# channels: [deprecation]
# path: php://stderr

View File

@ -0,0 +1,17 @@
monolog:
handlers:
main:
type: fingers_crossed
action_level: error
handler: nested
excluded_http_codes: [404, 405]
buffer_size: 50 # How many messages should be saved? Prevent memory leaks
nested:
type: stream
path: php://stderr
level: debug
formatter: monolog.formatter.json
console:
type: console
process_psr_3_messages: false
channels: ["!event", "!doctrine"]

View File

@ -0,0 +1,2 @@
symfonycasts_reset_password:
request_password_repository: App\Repository\ResetPasswordRequestRepository

View File

@ -0,0 +1,12 @@
monolog:
handlers:
main:
type: fingers_crossed
action_level: error
handler: nested
excluded_http_codes: [404, 405]
channels: ["!event"]
nested:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug

View File

@ -1,2 +1,3 @@
twig: twig:
default_path: '%kernel.project_dir%/templates' default_path: '%kernel.project_dir%/templates'
form_themes: ['bootstrap_4_layout.html.twig']

View File

@ -27,5 +27,9 @@ services:
resource: '../src/Controller/' resource: '../src/Controller/'
tags: ['controller.service_arguments'] tags: ['controller.service_arguments']
Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler:
arguments:
- '%env(DATABASE_URL)%'
# add more service definitions when explicit configuration is needed # add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones # please note that last definitions always *replace* previous ones

View File

@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210609175005 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE reset_password_request (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, selector VARCHAR(20) NOT NULL, hashed_token VARCHAR(100) NOT NULL, requested_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', expires_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_7CE748AA76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE reset_password_request ADD CONSTRAINT FK_7CE748AA76ED395 FOREIGN KEY (user_id) REFERENCES user (id)');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP TABLE reset_password_request');
}
}

View File

@ -2,8 +2,11 @@
"devDependencies": { "devDependencies": {
"@symfony/stimulus-bridge": "^2.0.0", "@symfony/stimulus-bridge": "^2.0.0",
"@symfony/webpack-encore": "^1.0.0", "@symfony/webpack-encore": "^1.0.0",
"bootstrap": "^5.0.1",
"core-js": "^3.0.0", "core-js": "^3.0.0",
"file-loader": "^6.0.0", "file-loader": "^6.0.0",
"jquery": "^3.6.0",
"popper.js": "^1.16.1",
"regenerator-runtime": "^0.13.2", "regenerator-runtime": "^0.13.2",
"sass": "^1.34.0", "sass": "^1.34.0",
"sass-loader": "^11.0.0", "sass-loader": "^11.0.0",
@ -21,7 +24,8 @@
"dependencies": { "dependencies": {
"@fortawesome/fontawesome-free": "^5.15.3", "@fortawesome/fontawesome-free": "^5.15.3",
"@popperjs/core": "^2.9.2", "@popperjs/core": "^2.9.2",
"bootstrap": "^5.0.1", "copy-webpack-plugin": "^9.0.0",
"copy-webpack-plugin": "^9.0.0" "webpack": "^5.38.1"
} },
"peerDependencies": {}
} }

View File

@ -0,0 +1,176 @@
<?php
namespace App\Controller;
use App\Entity\User;
use App\Form\ChangePasswordFormType;
use App\Form\ResetPasswordRequestFormType;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Address;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use SymfonyCasts\Bundle\ResetPassword\Controller\ResetPasswordControllerTrait;
use SymfonyCasts\Bundle\ResetPassword\Exception\ResetPasswordExceptionInterface;
use SymfonyCasts\Bundle\ResetPassword\ResetPasswordHelperInterface;
/**
* Class ResetPasswordController
* @package App\Controller
*/
#[Route('/reset-password')]
class ResetPasswordController extends AbstractController
{
use ResetPasswordControllerTrait;
private $resetPasswordHelper;
public function __construct(ResetPasswordHelperInterface $resetPasswordHelper)
{
$this->resetPasswordHelper = $resetPasswordHelper;
}
/**
* Display & process form to request a password reset.
*/
#[Route('', name: 'app_forgot_password_request')]
public function request(Request $request, MailerInterface $mailer): Response
{
$form = $this->createForm(ResetPasswordRequestFormType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
return $this->processSendingPasswordResetEmail(
$form->get('email')->getData(),
$mailer
);
}
return $this->render('security/request.html.twig', [
'requestForm' => $form->createView(),
]);
}
/**
* Confirmation page after a user has requested a password reset.
*/
#[Route('/check-email', name: 'app_check_email')]
public function checkEmail(): Response
{
// Generate a fake token if the user does not exist or someone hit this page directly.
// This prevents exposing whether or not a user was found with the given email address or not
if (null === ($resetToken = $this->getTokenObjectFromSession())) {
$resetToken = $this->resetPasswordHelper->generateFakeResetToken();
}
return $this->render('security/check_email.html.twig', [
'resetToken' => $resetToken,
]);
}
/**
* Validates and process the reset URL that the user clicked in their email.
*/
#[Route('/reset/{token}', name: 'app_reset_password')]
public function reset(Request $request, UserPasswordEncoderInterface $passwordEncoder, string $token = null): Response
{
if ($token) {
// We store the token in session and remove it from the URL, to avoid the URL being
// loaded in a browser and potentially leaking the token to 3rd party JavaScript.
$this->storeTokenInSession($token);
return $this->redirectToRoute('app_reset_password');
}
$token = $this->getTokenFromSession();
if ($token === null) {
throw $this->createNotFoundException('No reset password token found in the URL or in the session.');
}
try {
$user = $this->resetPasswordHelper->validateTokenAndFetchUser($token);
} catch (ResetPasswordExceptionInterface $e) {
$this->addFlash('reset_password_error', sprintf(
'There was a problem validating your reset request - %s',
$e->getReason()
));
return $this->redirectToRoute('app_forgot_password_request');
}
// The token is valid; allow the user to change their password.
$form = $this->createForm(ChangePasswordFormType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// A password reset token should be used only once, remove it.
$this->resetPasswordHelper->removeResetRequest($token);
// Encode the plain password, and set it.
$encodedPassword = $passwordEncoder->encodePassword(
$user,
$form->get('plainPassword')->getData()
);
$user->setPassword($encodedPassword);
$this->getDoctrine()->getManager()->flush();
// The session is cleaned up after the password has been changed.
$this->cleanSessionAfterReset();
return $this->redirectToRoute('blogs');
}
return $this->render('security/reset.html.twig', [
'resetForm' => $form->createView(),
]);
}
private function processSendingPasswordResetEmail(string $emailFormData, MailerInterface $mailer): RedirectResponse
{
$user = $this->getDoctrine()->getRepository(User::class)->findOneBy([
'email' => $emailFormData,
]);
// Do not reveal whether a user account was found or not.
if (!$user) {
return $this->redirectToRoute('app_check_email');
}
try {
$resetToken = $this->resetPasswordHelper->generateResetToken($user);
} catch (ResetPasswordExceptionInterface $e) {
// If you want to tell the user why a reset email was not sent, uncomment
// the lines below and change the redirect to 'app_forgot_password_request'.
// Caution: This may reveal if a user is registered or not.
//
// $this->addFlash('reset_password_error', sprintf(
// 'There was a problem handling your password reset request - %s',
// $e->getReason()
// ));
return $this->redirectToRoute('app_check_email');
}
$email = (new TemplatedEmail())
->from(new Address('tracer@24unix.net', '24unix.net'))
->to($user->getEmail())
->subject('Your password reset request')
->htmlTemplate('security/email.html.twig')
->context([
'resetToken' => $resetToken,
])
;
$mailer->send($email);
// Store the token object in session for retrieval in check-email route.
$this->setTokenObjectInSession($resetToken);
return $this->redirectToRoute('app_check_email');
}
}

View File

@ -2,35 +2,42 @@
namespace App\Controller; namespace App\Controller;
use App\Entity\User;
use App\Form\RegistrationFormType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
/**
* Class SecurityController
* @package App\Controller
*/
class SecurityController extends AbstractController class SecurityController extends AbstractController
{ {
/** /**
* @Route("/login", name="app_login") * @Route("/login", name="app_login")
*/ */
public function login(AuthenticationUtils $authenticationUtils): Response public function login( AuthenticationUtils $authenticationUtils): Response
{ {
// if ($this->getUser()) { // if ($this->getUser()) {
// return $this->redirectToRoute('target_path'); // return $this->redirectToRoute('target_path');
// } // }
// get the login error if there is one // get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError(); $error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user // last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername(); $lastUsername = $authenticationUtils->getLastUsername();
return $this->render('security/login.html.twig', ['last_username' => $lastUsername, 'error' => $error]); return $this->render('security/login.html.twig', ['last_username' => $lastUsername, 'error' => $error]);
} }
/** /**
* @Route("/logout", name="app_logout") * @Route("/logout", name="app_logout")
*/ */
public function logout() public function logout()
{ {
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.'); throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
} }
} }

View File

@ -0,0 +1,18 @@
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class UserController extends AbstractController
{
#[Route('/user', name: 'user')]
public function index(): Response
{
return $this->render('user/index.html.twig', [
'controller_name' => 'UserController',
]);
}
}

View File

@ -15,266 +15,266 @@ use App\Repository\SectionRepository;
*/ */
class Blog class Blog
{ {
/** /**
* @ORM\Id * @ORM\Id
* @ORM\GeneratedValue * @ORM\GeneratedValue
* @ORM\Column(type="integer") * @ORM\Column(type="integer")
*/ */
private $id; private $id;
/** /**
* @ORM\Column(type="string", length=255) * @ORM\Column(type="string", length=255)
*/ */
private ?string $title; private ?string $title;
/** /**
* @ORM\Column(type="text", nullable=true) * @ORM\Column(type="text", nullable=true)
*/ */
private ?string $teaser; private ?string $teaser;
/** /**
* @ORM\Column(type="string", length=255, nullable=true) * @ORM\Column(type="string", length=255, nullable=true)
*/ */
private ?string $teaserImage; private ?string $teaserImage;
/** /**
* @ORM\Column(type="text") * @ORM\Column(type="text")
*/ */
private ?string $content; private ?string $content;
/** /**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="blogs") * @ORM\ManyToOne(targetEntity=User::class, inversedBy="blogs")
* @ORM\JoinColumn(nullable=false) * @ORM\JoinColumn(nullable=false)
*/ */
private ?User $author; private ?User $author;
/** /**
* @ORM\ManyToMany(targetEntity=Section::class, inversedBy="blogs") * @ORM\ManyToMany(targetEntity=Section::class, inversedBy="blogs")
*/ */
private $section; private $section;
/** /**
* @ORM\Column(type="datetime") * @ORM\Column(type="datetime")
*/ */
private ?\DateTimeInterface $createdAt; private ?\DateTimeInterface $createdAt;
/** /**
* @ORM\Column(type="datetime", nullable=true) * @ORM\Column(type="datetime", nullable=true)
*/ */
private ?\DateTimeInterface $editedAt; private ?\DateTimeInterface $editedAt;
/** /**
* @ORM\ManyToOne(targetEntity=User::class) * @ORM\ManyToOne(targetEntity=User::class)
*/ */
private ?User $editedBy; private ?User $editedBy;
/** /**
* @ORM\Column(type="string", length=255, nullable=true) * @ORM\Column(type="string", length=255, nullable=true)
*/ */
private ?string $editReason; private ?string $editReason;
/** /**
* @ORM\OneToMany(targetEntity=Comment::class, mappedBy="blog") * @ORM\OneToMany(targetEntity=Comment::class, mappedBy="blog")
*/ */
private $comments; private $comments;
/** /**
* @ORM\Column(type="string", length=255) * @ORM\Column(type="string", length=255)
*/ */
private $slug; private $slug;
#[Pure] #[Pure]
public function __construct() public function __construct()
{ {
$this->section = new ArrayCollection(); $this->section = new ArrayCollection();
$this->comments = new ArrayCollection(); $this->comments = new ArrayCollection();
} }
/** /**
* @return null|string * @return null|string
*/ */
public function __toString() public function __toString()
{ {
return $this->title; return $this->title;
} }
public function getId(): ?int public function getId(): ?int
{ {
return $this->id; return $this->id;
} }
public function getTitle(): ?string public function getTitle(): ?string
{ {
return $this->title; return $this->title;
} }
public function setTitle(string $title): self public function setTitle(string $title): self
{ {
$this->title = $title; $this->title = $title;
return $this; return $this;
} }
public function getTeaser(): ?string public function getTeaser(): ?string
{ {
return $this->teaser; return $this->teaser;
} }
public function setTeaser(?string $teaser): self public function setTeaser(?string $teaser): self
{ {
$this->teaser = $teaser; $this->teaser = $teaser;
return $this; return $this;
} }
public function getTeaserImage(): ?string public function getTeaserImage(): ?string
{ {
return $this->teaserImage; return $this->teaserImage;
} }
public function setTeaserImage(?string $teaserImage): self public function setTeaserImage(?string $teaserImage): self
{ {
$this->teaserImage = $teaserImage; $this->teaserImage = $teaserImage;
return $this; return $this;
} }
public function getContent(): ?string public function getContent(): ?string
{ {
return $this->content; return $this->content;
} }
public function setContent(string $content): self public function setContent(string $content): self
{ {
$this->content = $content; $this->content = $content;
return $this; return $this;
} }
public function getAuthor(): ?User public function getAuthor(): ?User
{ {
return $this->author; return $this->author;
} }
public function setAuthor(?User $author): self public function setAuthor(?User $author): self
{ {
$this->author = $author; $this->author = $author;
return $this; return $this;
} }
/** /**
* @return Collection|Section[] * @return Collection|Section[]
*/ */
public function getSection(): Collection public function getSection(): Collection
{ {
return $this->section; return $this->section;
} }
public function addSection(Section $section): self public function addSection(Section $section): self
{ {
if (!$this->section->contains($section)) { if (!$this->section->contains($section)) {
$this->section[] = $section; $this->section[] = $section;
} }
return $this; return $this;
} }
public function removeSection(Section $section): self public function removeSection(Section $section): self
{ {
$this->section->removeElement($section); $this->section->removeElement($section);
return $this; return $this;
} }
public function getCreatedAt(): ?\DateTimeInterface public function getCreatedAt(): ?\DateTimeInterface
{ {
return $this->createdAt; return $this->createdAt;
} }
public function setCreatedAt(\DateTimeInterface $createdAt): self public function setCreatedAt(\DateTimeInterface $createdAt): self
{ {
$this->createdAt = $createdAt; $this->createdAt = $createdAt;
return $this; return $this;
} }
public function getEditedAt(): ?\DateTimeInterface public function getEditedAt(): ?\DateTimeInterface
{ {
return $this->editedAt; return $this->editedAt;
} }
public function setEditedAt(?\DateTimeInterface $editedAt): self public function setEditedAt(?\DateTimeInterface $editedAt): self
{ {
$this->editedAt = $editedAt; $this->editedAt = $editedAt;
return $this; return $this;
} }
public function getEditedBy(): ?User public function getEditedBy(): ?User
{ {
return $this->editedBy; return $this->editedBy;
} }
public function setEditedBy(?User $editedBy): self public function setEditedBy(?User $editedBy): self
{ {
$this->editedBy = $editedBy; $this->editedBy = $editedBy;
return $this; return $this;
} }
public function getEditReason(): ?string public function getEditReason(): ?string
{ {
return $this->editReason; return $this->editReason;
} }
public function setEditReason(?string $editReason): self public function setEditReason(?string $editReason): self
{ {
$this->editReason = $editReason; $this->editReason = $editReason;
return $this; return $this;
} }
/** /**
* @return Collection|Comment[] * @return Collection|Comment[]
*/ */
public function getComments(): Collection public function getComments(): Collection
{ {
return $this->comments; return $this->comments;
} }
public function addComment(Comment $comment): self public function addComment(Comment $comment): self
{ {
if (!$this->comments->contains($comment)) { if (!$this->comments->contains($comment)) {
$this->comments[] = $comment; $this->comments[] = $comment;
$comment->setBlog($this); $comment->setBlog($this);
} }
return $this; return $this;
} }
public function removeComment(Comment $comment): self public function removeComment(Comment $comment): self
{ {
if ($this->comments->removeElement($comment)) { if ($this->comments->removeElement($comment)) {
// set the owning side to null (unless already changed) // set the owning side to null (unless already changed)
if ($comment->getBlog() === $this) { if ($comment->getBlog() === $this) {
$comment->setBlog(null); $comment->setBlog(null);
} }
} }
return $this; return $this;
} }
public function getSlug(): ?string public function getSlug(): ?string
{ {
return $this->slug; return $this->slug;
} }
public function setSlug(string $slug): self public function setSlug(string $slug): self
{ {
$this->slug = $slug; $this->slug = $slug;
return $this; return $this;
} }
} }

View File

@ -0,0 +1,45 @@
<?php
namespace App\Entity;
use App\Repository\ResetPasswordRequestRepository;
use Doctrine\ORM\Mapping as ORM;
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordRequestInterface;
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordRequestTrait;
/**
* @ORM\Entity(repositoryClass=ResetPasswordRequestRepository::class)
*/
class ResetPasswordRequest implements ResetPasswordRequestInterface
{
use ResetPasswordRequestTrait;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=User::class)
* @ORM\JoinColumn(nullable=false)
*/
private $user;
public function __construct(object $user, \DateTimeInterface $expiresAt, string $selector, string $hashedToken)
{
$this->user = $user;
$this->initialize($expiresAt, $selector, $hashedToken);
}
public function getId(): ?int
{
return $this->id;
}
public function getUser(): object
{
return $this->user;
}
}

View File

@ -8,13 +8,16 @@ use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use JetBrains\PhpStorm\Pure; use JetBrains\PhpStorm\Pure;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\UserInterface;
/** /**
* @ORM\Entity(repositoryClass=UserRepository::class) * @ORM\Entity(repositoryClass=UserRepository::class)
* @UniqueEntity(fields={"username"}, message="There is already an account with this username") * @UniqueEntity(fields={"username"}, message="There is already an account with this username")
* @ORM\HasLifecycleCallbacks
* @method string getUserIdentifier()
*/ */
class User implements UserInterface class User implements UserInterface, PasswordAuthenticatedUserInterface
{ {
/** /**
* @ORM\Id * @ORM\Id
@ -74,26 +77,26 @@ class User implements UserInterface
*/ */
private $comments; private $comments;
/** /**
* @ORM\Column(type="boolean") * @ORM\Column(type="boolean")
*/ */
private $isVerified = false; private $isVerified = false;
#[Pure] public function __construct() #[Pure] public function __construct()
{ {
$this->blogs = new ArrayCollection(); $this->blogs = new ArrayCollection();
$this->comments = new ArrayCollection(); $this->comments = new ArrayCollection();
} }
public function __toString() public function __toString()
{ {
return $this->username; return $this->username;
} }
public function getId(): ?int public function getId(): ?int
{ {
return $this->id; return $this->id;
} }
/** /**
* A visual identifier that represents this user. * A visual identifier that represents this user.
@ -101,50 +104,50 @@ class User implements UserInterface
* @see UserInterface * @see UserInterface
*/ */
public function getUsername(): string public function getUsername(): string
{ {
return (string)$this->username; return (string)$this->username;
} }
public function setUsername(string $username): self public function setUsername(string $username): self
{ {
$this->username = $username; $this->username = $username;
return $this; return $this;
} }
/** /**
* @see UserInterface * @see UserInterface
*/ */
public function getRoles(): array public function getRoles(): array
{ {
$roles = $this->roles; $roles = $this->roles;
// guarantee every user at least has ROLE_USER // guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER'; $roles[] = 'ROLE_USER';
return array_unique($roles); return array_unique($roles);
} }
public function setRoles(array $roles): self public function setRoles(array $roles): self
{ {
$this->roles = $roles; $this->roles = $roles;
return $this; return $this;
} }
/** /**
* @see UserInterface * @see UserInterface
*/ */
public function getPassword(): string public function getPassword(): string
{ {
return $this->password; return $this->password;
} }
public function setPassword(string $password): self public function setPassword(string $password): self
{ {
$this->password = $password; $this->password = $password;
return $this; return $this;
} }
/** /**
* Returning a salt is only needed, if you are not using a modern * Returning a salt is only needed, if you are not using a modern
@ -153,148 +156,164 @@ class User implements UserInterface
* @see UserInterface * @see UserInterface
*/ */
public function getSalt(): ?string public function getSalt(): ?string
{ {
return null; return null;
} }
/** /**
* @see UserInterface * @see UserInterface
*/ */
public function eraseCredentials() public function eraseCredentials()
{ {
// If you store any temporary, sensitive data on the user, clear it here // If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null; // $this->plainPassword = null;
} }
public function getFirstName(): ?string public function getFirstName(): ?string
{ {
return $this->firstName; return $this->firstName;
} }
public function setFirstName(?string $firstName): self public function setFirstName(?string $firstName): self
{ {
$this->firstName = $firstName; $this->firstName = $firstName;
return $this; return $this;
} }
public function getLastName(): ?string public function getLastName(): ?string
{ {
return $this->lastName; return $this->lastName;
} }
public function setLastName(?string $lastName): self public function setLastName(?string $lastName): self
{ {
$this->lastName = $lastName; $this->lastName = $lastName;
return $this; return $this;
} }
public function getEmail(): ?string public function getEmail(): ?string
{ {
return $this->email; return $this->email;
} }
public function setEmail(string $email): self public function setEmail(string $email): self
{ {
$this->email = $email; $this->email = $email;
return $this; return $this;
} }
public function getCreatedAt(): ?\DateTimeInterface public function getCreatedAt(): ?\DateTimeInterface
{ {
return $this->createdAt; return $this->createdAt;
} }
public function setCreatedAt(\DateTimeInterface $createdAt): self public function setCreatedAt(\DateTimeInterface $createdAt): self
{ {
$this->createdAt = $createdAt; $this->createdAt = $createdAt;
return $this; return $this;
} }
public function getLastLoginAt(): ?\DateTimeInterface public function getLastLoginAt(): ?\DateTimeInterface
{ {
return $this->lastLoginAt; return $this->lastLoginAt;
} }
public function setLastLoginAt(?\DateTimeInterface $lastLoginAt): self public function setLastLoginAt(?\DateTimeInterface $lastLoginAt): self
{ {
$this->lastLoginAt = $lastLoginAt; $this->lastLoginAt = $lastLoginAt;
return $this; return $this;
} }
/** /**
* @return Collection|Blog[] * @return Collection|Blog[]
*/ */
public function getBlogs(): Collection public function getBlogs(): Collection
{ {
return $this->blogs; return $this->blogs;
} }
public function addBlog(Blog $blog): self public function addBlog(Blog $blog): self
{ {
if (!$this->blogs->contains($blog)) { if (!$this->blogs->contains($blog)) {
$this->blogs[] = $blog; $this->blogs[] = $blog;
$blog->setAuthor($this); $blog->setAuthor($this);
} }
return $this; return $this;
} }
public function removeBlog(Blog $blog): self public function removeBlog(Blog $blog): self
{ {
if ($this->blogs->removeElement($blog)) { if ($this->blogs->removeElement($blog)) {
// set the owning side to null (unless already changed) // set the owning side to null (unless already changed)
if ($blog->getAuthor() === $this) { if ($blog->getAuthor() === $this) {
$blog->setAuthor(null); $blog->setAuthor(null);
} }
} }
return $this; return $this;
} }
/** /**
* @return Collection|Comment[] * @return Collection|Comment[]
*/ */
public function getComments(): Collection public function getComments(): Collection
{ {
return $this->comments; return $this->comments;
} }
public function addComment(Comment $comment): self public function addComment(Comment $comment): self
{ {
if (!$this->comments->contains($comment)) { if (!$this->comments->contains($comment)) {
$this->comments[] = $comment; $this->comments[] = $comment;
$comment->setAuthor($this); $comment->setAuthor($this);
} }
return $this; return $this;
} }
public function removeComment(Comment $comment): self public function removeComment(Comment $comment): self
{ {
if ($this->comments->removeElement($comment)) { if ($this->comments->removeElement($comment)) {
// set the owning side to null (unless already changed) // set the owning side to null (unless already changed)
if ($comment->getAuthor() === $this) { if ($comment->getAuthor() === $this) {
$comment->setAuthor(null); $comment->setAuthor(null);
} }
} }
return $this; return $this;
} }
public function isVerified(): bool public function isVerified(): bool
{ {
return $this->isVerified; return $this->isVerified;
} }
public function setIsVerified(bool $isVerified): self public function setIsVerified(bool $isVerified): self
{ {
$this->isVerified = $isVerified; $this->isVerified = $isVerified;
return $this;
}
public function __call(string $name, array $arguments)
{
// TODO: Implement @method string getUserIdentifier()
}
/**
* Gets triggered only on insert
* @ORM\PrePersist
*/
public function onPrePersist()
{
$this->createdAt = new \DateTime();
}
return $this;
}
} }

View File

@ -0,0 +1,51 @@
<?php
namespace App\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
class ChangePasswordFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('plainPassword', RepeatedType::class, [
'type' => PasswordType::class,
'first_options' => [
'attr' => ['autocomplete' => 'new-password'],
'constraints' => [
new NotBlank([
'message' => 'Please enter a password',
]),
new Length([
'min' => 6,
'minMessage' => 'Your password should be at least {{ limit }} characters',
// max length allowed by Symfony for security reasons
'max' => 4096,
]),
],
'label' => 'New password',
],
'second_options' => [
'attr' => ['autocomplete' => 'new-password'],
'label' => 'Repeat Password',
],
'invalid_message' => 'The password fields must match.',
// Instead of being set onto the object directly,
// this is read and encoded in the controller
'mapped' => false,
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([]);
}
}

View File

@ -5,6 +5,7 @@ namespace App\Form;
use App\Entity\User; use App\Entity\User;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType; use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
@ -14,42 +15,44 @@ use Symfony\Component\Validator\Constraints\NotBlank;
class RegistrationFormType extends AbstractType class RegistrationFormType extends AbstractType
{ {
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options)
{ {
$builder $builder
->add('username') ->add('username')
->add('agreeTerms', CheckboxType::class, [ ->add('agreeTerms', CheckboxType::class, [
'mapped' => false, 'mapped' => false,
'constraints' => [ 'constraints' => [
new IsTrue([ new IsTrue([
'message' => 'You should agree to our terms.', 'message' => 'You should agree to our terms.',
]), ]),
], ],
]) ])
->add('plainPassword', PasswordType::class, [ ->add('plainPassword', PasswordType::class, [
// instead of being set onto the object directly, // instead of being set onto the object directly,
// this is read and encoded in the controller // this is read and encoded in the controller
'mapped' => false, 'mapped' => false,
'attr' => ['autocomplete' => 'new-password'], 'attr' => ['autocomplete' => 'new-password'],
'constraints' => [ 'constraints' => [
new NotBlank([ new NotBlank([
'message' => 'Please enter a password', 'message' => 'Please enter a password',
]), ]),
new Length([ new Length([
'min' => 6, 'min' => 6,
'minMessage' => 'Your password should be at least {{ limit }} characters', 'minMessage' => 'Your password should be at least {{ limit }} characters',
// max length allowed by Symfony for security reasons // max length allowed by Symfony for security reasons
'max' => 4096, 'max' => 4096,
]), ]),
], ],
]) ])
; ->add('firstName')
} ->add('lastName')
->add('email', EmailType::class);
}
public function configureOptions(OptionsResolver $resolver) public function configureOptions(OptionsResolver $resolver)
{ {
$resolver->setDefaults([ $resolver->setDefaults([
'data_class' => User::class, 'data_class' => User::class,
]); ]);
} }
} }

View File

@ -0,0 +1,31 @@
<?php
namespace App\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\NotBlank;
class ResetPasswordRequestFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('email', EmailType::class, [
'attr' => ['autocomplete' => 'email'],
'constraints' => [
new NotBlank([
'message' => 'Please enter your email',
]),
],
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([]);
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace App\Repository;
use App\Entity\ResetPasswordRequest;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordRequestInterface;
use SymfonyCasts\Bundle\ResetPassword\Persistence\Repository\ResetPasswordRequestRepositoryTrait;
use SymfonyCasts\Bundle\ResetPassword\Persistence\ResetPasswordRequestRepositoryInterface;
/**
* @method ResetPasswordRequest|null find($id, $lockMode = null, $lockVersion = null)
* @method ResetPasswordRequest|null findOneBy(array $criteria, array $orderBy = null)
* @method ResetPasswordRequest[] findAll()
* @method ResetPasswordRequest[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class ResetPasswordRequestRepository extends ServiceEntityRepository implements ResetPasswordRequestRepositoryInterface
{
use ResetPasswordRequestRepositoryTrait;
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, ResetPasswordRequest::class);
}
public function createResetPasswordRequest(object $user, \DateTimeInterface $expiresAt, string $selector, string $hashedToken): ResetPasswordRequestInterface
{
return new ResetPasswordRequest($user, $expiresAt, $selector, $hashedToken);
}
}

View File

@ -10,6 +10,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException; use Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\Security;
@ -145,7 +146,7 @@ class AppAuthenticator extends AbstractFormLoginAuthenticator implements Passwor
* *
* @throws AuthenticationException * @throws AuthenticationException
*/ */
public function checkCredentials($credentials, UserInterface $user) public function checkCredentials($credentials, UserInterface $user): bool
{ {
//return true; //return true;
return $this->passwordEncoder->isPasswordValid($user, $credentials['password']); return $this->passwordEncoder->isPasswordValid($user, $credentials['password']);

View File

@ -109,6 +109,9 @@
"laminas/laminas-zendframework-bridge": { "laminas/laminas-zendframework-bridge": {
"version": "1.2.0" "version": "1.2.0"
}, },
"monolog/monolog": {
"version": "2.2.0"
},
"nikic/php-parser": { "nikic/php-parser": {
"version": "v4.10.5" "version": "v4.10.5"
}, },
@ -246,6 +249,24 @@
"symfony/mime": { "symfony/mime": {
"version": "v5.2.9" "version": "v5.2.9"
}, },
"symfony/monolog-bridge": {
"version": "v5.3.0"
},
"symfony/monolog-bundle": {
"version": "3.7",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "3.7",
"ref": "329f6a5ef2e7aa033f802be833ef8d1268dd0848"
},
"files": [
"config/packages/dev/monolog.yaml",
"config/packages/prod/deprecations.yaml",
"config/packages/prod/monolog.yaml",
"config/packages/test/monolog.yaml"
]
},
"symfony/options-resolver": { "symfony/options-resolver": {
"version": "v5.2.4" "version": "v5.2.4"
}, },
@ -438,6 +459,18 @@
"symfony/yaml": { "symfony/yaml": {
"version": "v5.2.9" "version": "v5.2.9"
}, },
"symfonycasts/reset-password-bundle": {
"version": "1.0",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "1.0",
"ref": "97c1627c0384534997ae1047b93be517ca16de43"
},
"files": [
"config/packages/reset_password.yaml"
]
},
"symfonycasts/verify-email-bundle": { "symfonycasts/verify-email-bundle": {
"version": "v1.5.0" "version": "v1.5.0"
}, },

View File

@ -9,41 +9,46 @@
</button> </button>
<div class="collapse navbar-collapse" id="CollapsingNavbar"> <div class="collapse navbar-collapse" id="CollapsingNavbar">
<ul class="navbar-nav ml-auto"> <ul class="navbar-nav ms-auto">
<li class="nav-item dropdown my-2 my-lg-0"> <form class="d-flex">
<button type="button" id="navbar-dropdown" data-bs-target="#dropdown-menu" data-bs-toggle="dropdown" <input class="form-control me-2 my-2" type="search" placeholder="Search" aria-label="Search">
class="btn btn-primary dropdown-toggle ml-auto button-login"> <button class="btn" type="submit">Search</button>
{{ app.user.username }} </form>
</button> {% if is_granted('ROLE_USER') %}
<li class="nav-item dropdown me-auto my-2 my-lg-0">
<button type="button" id="navbar-dropdown" data-bs-target="#dropdown-menu" data-bs-toggle="dropdown"
class="btn btn-primary dropdown-toggle ml-auto button-login">
{{ app.user.username }}
</button>
{% if is_granted('ROLE_USER') %} <div class="dropdown-menu dropdown-menu-dark dropdown-menu-end" id="dropdown-menu"
<div class="dropdown-menu dropdown-menu-dark dropdown-menu-end" id="dropdown-menu" aria-labelledby="navbar-dropdown"> aria-labelledby="navbar-dropdown">
<a class="dropdown-item" href="{{ path('user') }}"> <a class="dropdown-item" href="{{ path('user') }}">
<span class="fas fa-user" aria-hidden="true"></span> <span class="fas fa-user" aria-hidden="true"></span>
Profile</a> Profile</a>
<a class="dropdown-item" href="#"> <a class="dropdown-item" href="#">
<span class="fas fa-cog" aria-hidden="true"></span> <span class="fas fa-wrench" aria-hidden="true"></span>
Settings</a> Settings</a>
<div class="dropdown-divider"></div>
{% if is_granted('ROLE_ADMIN') %}
<a class="dropdown-item" href="{{ path('admin') }}">
<span class="fas fa-cog" aria-hidden="true"></span>
Administration
</a>
<div class="dropdown-divider"></div> <div class="dropdown-divider"></div>
{% endif %} {% if is_granted('ROLE_ADMIN') %}
<a class="dropdown-item" href="{{ path('admin') }}">
<span class="fas fa-cog" aria-hidden="true"></span>
Administration
</a>
<div class="dropdown-divider"></div>
{% endif %}
<a class="dropdown-item" href="{{ path('app_logout') }}"> <a class="dropdown-item" href="{{ path('app_logout') }}">
<span class="fas fa-sign-out-alt" aria-hidden="true"></span> <span class="fas fa-sign-out-alt" aria-hidden="true"></span>&nbsp;
Logout Logout
</a> </a>
</div> </div>
</li> </li>
{% else %} {% else %}
<li class="nav-item"> <li class="nav-item">
<a class="btn btn-primary button-login" href="{{ path('app_login') }}" role="button" <a class="btn btn-primary button-login" href="{{ path('app_login') }}" role="button"
id="buttonLogin"> id="buttonLogin">
Login <span class="fas fa-sign-out-alt me-2" aria-hidden="true"></span>Sign In
</a> </a>
</li> </li>
{% endif %} {% endif %}

View File

@ -2,6 +2,7 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{% block title %}Spookie{% endblock %}</title> <title>{% block title %}Spookie{% endblock %}</title>
{% block stylesheets %} {% block stylesheets %}

View File

@ -1,12 +1,80 @@
{# templates/blog/blog_show.html.twig #}
{% extends 'base.html.twig' %} {% extends 'base.html.twig' %}
{% block title %} {% block title %} Blogpost {% endblock %}
{% endblock %}
{% block body %} {% block body %}
Blogtest
{{ blog.content }} <div class="container box">
<div class="row">
<div class="col-sm-12">
<div class="show-article-container p-3 mt-4">
<div class="row">
<div class="col-sm-12">
<img class="show-article-img" src="{{ asset('build/images/asteroid.jpeg') }}" alt="asteroid">
<div class="show-article-title-container d-inline-block pl-3 align-middle">
<span class="show-article-title ">{{ blog.title }}</span>
<br>
<span class="align-left article-details">
<img class="article-author-img rounded-circle" src="{{ asset('build/images/alien-profile.png') }}" alt="profile">
{{ blog.author }}
</span>
<span class="pl-2 article-details">{{ blog.createdAt | ago }} updated: {{ blog.editedAt | ago }} </span>
<span class="pl-2 article-details">
</span>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="article-text">
{{ blog.content }}
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<p class="share-icons mb-5">
<span class="pr-1">Share:</span>
<i class="pr-1 fa-2x fab fa-facebook-square"></i>
<i class="pr-1 fa-2x fab fa-twitter-square"></i>
<i class="pr-1 fa-2x fab fa-reddit-square"></i>
<i class="pr-1 fa-2x fa fa-share-alt-square"></i>
</p>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<h3>
<!--
<i class="pr-3 fa fa-comment"></i>Comments</h3>
-->
<hr>
<div class="row mb-5">
<div class="col-sm-12">
<img class="comment-img rounded-circle" src="{{ asset('build/images/alien-profile.png') }}" alt="profile">
<div class="comment-container d-inline-block pl-3 align-top">
<span class="commenter-name">Amy Oort</span>
<div class="form-group">
<label for="articleText"></label>
<textarea class="form-control comment-form" id="articleText" rows="1"></textarea>
</div>
<button type="submit" class="btn btn-primary">Comment</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %} {% endblock %}

View File

@ -1,21 +0,0 @@
{% extends 'base.html.twig' %}
{% block title %}Register{% endblock %}
{% block body %}
{% for flashError in app.flashes('verify_email_error') %}
<div class="alert alert-danger" role="alert">{{ flashError }}</div>
{% endfor %}
<h1>Register</h1>
{{ form_start(registrationForm) }}
{{ form_row(registrationForm.username) }}
{{ form_row(registrationForm.plainPassword, {
label: 'Password'
}) }}
{{ form_row(registrationForm.agreeTerms) }}
<button type="submit" class="btn">Register</button>
{{ form_end(registrationForm) }}
{% endblock %}

View File

@ -0,0 +1,11 @@
{% extends 'base.html.twig' %}
{% block title %}Password Reset Email Sent{% endblock %}
{% block body %}
<p>
If an account matching your email exists, then an email was just sent that contains a link that you can use to reset your password.
This link will expire in {{ resetToken.expirationMessageKey|trans(resetToken.expirationMessageData, 'ResetPasswordBundle') }}.
</p>
<p>If you don't receive an email please check your spam folder or <a href="{{ path('app_forgot_password_request') }}">try again</a>.</p>
{% endblock %}

View File

@ -0,0 +1,9 @@
<h1>Hi!</h1>
<p>To reset your password, please visit the following link</p>
<a href="{{ url('app_reset_password', {token: resetToken.token}) }}">{{ url('app_reset_password', {token: resetToken.token}) }}</a>
<p>This link will expire in {{ resetToken.expirationMessageKey|trans(resetToken.expirationMessageData, 'ResetPasswordBundle') }}.</p>
<p>Cheers!</p>

View File

@ -3,40 +3,71 @@
{% block title %}Log in!{% endblock %} {% block title %}Log in!{% endblock %}
{% block body %} {% block body %}
<form method="post">
{% if error %}
<div class="alert alert-danger">{{ error.messageKey|trans(error.messageData, 'security') }}</div>
{% endif %}
{% if app.user %} {% for flashError in app.flashes('verify_email_error') %}
<div class="mb-3"> <div class="alert alert-danger" role="alert">{{ flashError }}</div>
You are logged in as {{ app.user.username }}, <a href="{{ path('app_logout') }}">Logout</a> {% endfor %}
<form method="post">
<div class="container">
<div class="d-flex justify-content-center h-100">
<div class="card-header">
<h3>Please Sign in</h3>
</div>
<div class="card">
<div class="card-body">
<div class="input-group form-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-user"></i></span>
</div>
<input type="text" value="{{ last_username }}" name="username" id="inputUsername"
class="form-control" autocomplete="username" required autofocus>
</div>
<div class="input-group form-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-key"></i></span>
</div>
<input type="password" name="password" id="inputPassword" class="form-control"
autocomplete="current-password" required>
</div>
{#
Uncomment this section and add a remember_me option below your firewall to activate remember me functionality.
See https://symfony.com/doc/current/security/remember_me.html
<div class="checkbox mb-3">
<label>
<input type="checkbox" name="_remember_me"> Remember me
</label>
</div>
#}
<button type="submit" class="submit-button">Sign In</button>
<input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}">
</div>
<div class="card-footer">
<div class="d-flex justify-content-center links">
Don't have an account yet? &nbsp;<a href=" {{ path('app_register') }}">Register!</a>
</div>
<div class="d-flex justify-content-center">
<a href="{{ path('app_forgot_password_request') }}">Forgot your password?</a>
</div>
<!--
<div class="d-flex justify-content-center social_icon">
<span><i class="fab fa-apple"></i></span>
<span><i class="fab fa-facebook"></i></span>
<span><i class="fab fa-google-plus"></i></span>
<span><i class="fab fa-twitter"></i></span>
</div>
-->
</div>
</div>
</div>
</div> </div>
{% endif %}
<h1 class="h3 mb-3 font-weight-normal">Please sign in</h1> </form>
<label for="inputUsername">Username</label>
<input type="text" value="{{ last_username }}" name="username" id="inputUsername" class="form-control" autocomplete="username" required autofocus>
<label for="inputPassword">Password</label>
<input type="password" name="password" id="inputPassword" class="form-control" autocomplete="current-password" required>
<input type="hidden" name="_csrf_token"
value="{{ csrf_token('authenticate') }}"
>
{#
Uncomment this section and add a remember_me option below your firewall to activate remember me functionality.
See https://symfony.com/doc/current/security/remember_me.html
<div class="checkbox mb-3">
<label>
<input type="checkbox" name="_remember_me"> Remember me
</label>
</div>
#}
<button class="btn btn-lg btn-primary" type="submit">
Sign in
</button>
</form>
{% endblock %} {% endblock %}

View File

@ -0,0 +1,81 @@
{% extends 'base.html.twig' %}
{% block title %}Register{% endblock %}
{% block body %}
{% for flashError in app.flashes('verify_email_error') %}
<div class="alert alert-danger" role="alert">{{ flashError }}</div>
{% endfor %}
<div class="container">
<div class="d-flex justify-content-center h-100">
<div class="card-header">
<h3>Register</h3>
</div>
<div class="card">
<div class="card-body">
{{ form_start(registrationForm) }}
<div class="input-group form-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-user"></i></span>
</div>
{{ form_widget(registrationForm.username, {'attr': {'placeholder':'Username'}} ) }}
</div>
<div class="input-group form-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-key"></i></span>
</div>
{{ form_widget(registrationForm.plainPassword, {'attr': {'placeholder':'Password'}} ) }}
</div>
<div class="input-group form-group">
<div class="input-group-prepend">
<span class="input-group-text"></span>
</div>
{{ form_widget(registrationForm.firstName, {'attr': {'placeholder':'First Name'}} ) }}
</div>
<div class="input-group form-group">
<div class="input-group-prepend">
<span class="input-group-text"></span>
</div>
{{ form_widget(registrationForm.lastName, {'attr': {'placeholder':'Last Name'}} ) }}
</div>
<div class="input-group form-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-envelope-square"></i></span>
</div>
{{ form_widget(registrationForm.email, {'attr': {'placeholder':'eMail'}} ) }}
</div>
{{ form_row(registrationForm.agreeTerms) }}
<button type="submit" class="submit-button">Register</button>
{{ form_end(registrationForm) }}
</div>
<div class="card-footer">
<div class="d-flex justify-content-center links">
Already have an account? &nbsp;<a href=" {{ path('app_login') }}">Sign In!</a>
</div>
<div class="d-flex justify-content-center">
<a href="#">Forgot your password?</a>
</div>
<!--
<div class="d-flex justify-content-center social_icon">
<span><i class="fab fa-apple"></i></span>
<span><i class="fab fa-facebook"></i></span>
<span><i class="fab fa-google-plus"></i></span>
<span><i class="fab fa-twitter"></i></span>
</div>
-->
</div>
</div>
</div>
</div>
{% endblock %}

View File

@ -0,0 +1,22 @@
{% extends 'base.html.twig' %}
{% block title %}Reset your password{% endblock %}
{% block body %}
{% for flashError in app.flashes('reset_password_error') %}
<div class="alert alert-danger" role="alert">{{ flashError }}</div>
{% endfor %}
<h1>Reset your password</h1>
{{ form_start(requestForm) }}
{{ form_row(requestForm.email) }}
<div>
<small>
Enter your email address and we we will send you a
link to reset your password.
</small>
</div>
<button class="btn btn-primary">Send password reset email</button>
{{ form_end(requestForm) }}
{% endblock %}

View File

@ -0,0 +1,12 @@
{% extends 'base.html.twig' %}
{% block title %}Reset your password{% endblock %}
{% block body %}
<h1>Reset your password</h1>
{{ form_start(resetForm) }}
{{ form_row(resetForm.plainPassword) }}
<button class="btn btn-primary">Reset password</button>
{{ form_end(resetForm) }}
{% endblock %}

View File

@ -0,0 +1,20 @@
{% extends 'base.html.twig' %}
{% block title %}Hello UserController!{% endblock %}
{% block body %}
<style>
.example-wrapper { margin: 1em auto; max-width: 800px; width: 95%; font: 18px/1.5 sans-serif; }
.example-wrapper code { background: #F5F5F5; padding: 2px 6px; }
</style>
<div class="example-wrapper">
<h1>Hello {{ controller_name }}! ✅</h1>
This friendly message is coming from:
<ul>
<li>Your controller at <code><a href="{{ '/Users/tracer/Projects/24unix.net/24unix.net_web/24unix/src/Controller/UserController.php'|file_link(0) }}">src/Controller/UserController.php</a></code></li>
<li>Your template at <code><a href="{{ '/Users/tracer/Projects/24unix.net/24unix.net_web/24unix/templates/user/index.html.twig'|file_link(0) }}">templates/user/index.html.twig</a></code></li>
</ul>
</div>
{% endblock %}

View File

@ -9,7 +9,7 @@ if (!Encore.isRuntimeEnvironmentConfigured()) {
const CopyWebpackPlugin = require("copy-webpack-plugin"); const CopyWebpackPlugin = require("copy-webpack-plugin");
Encore Encore
// directory where compiled assets will be stored // directory where compiled assets will be stored
.setOutputPath("public/build/") .setOutputPath("public/build/")
.copyFiles({ .copyFiles({
from: "./assets/images", from: "./assets/images",
@ -73,8 +73,8 @@ Encore
// requires WebpackEncoreBundle 1.4 or higher // requires WebpackEncoreBundle 1.4 or higher
//.enableIntegrityHashes(Encore.isProduction()) //.enableIntegrityHashes(Encore.isProduction())
// uncomment if you're having problems with a jQuery plugin // uncomment if you're having problems with a jQuery plugin
//.autoProvidejQuery() .autoProvidejQuery()
// uncomment if you use API Platform Admin (composer req api-admin) // uncomment if you use API Platform Admin (composer req api-admin)
//.enableReactPreset() //.enableReactPreset()

View File

@ -4834,7 +4834,7 @@ webpack-sources@^2.3.0:
source-list-map "^2.0.1" source-list-map "^2.0.1"
source-map "^0.6.1" source-map "^0.6.1"
webpack@^5.35: webpack@^5.35, webpack@^5.38.1:
version "5.38.1" version "5.38.1"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.38.1.tgz#5224c7f24c18e729268d3e3bc97240d6e880258e" resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.38.1.tgz#5224c7f24c18e729268d3e3bc97240d6e880258e"
integrity sha512-OqRmYD1OJbHZph6RUMD93GcCZy4Z4wC0ele4FXyYF0J6AxO1vOSuIlU1hkS/lDlR9CDYBz64MZRmdbdnFFoT2g== integrity sha512-OqRmYD1OJbHZph6RUMD93GcCZy4Z4wC0ele4FXyYF0J6AxO1vOSuIlU1hkS/lDlR9CDYBz64MZRmdbdnFFoT2g==