-
-
Notifications
You must be signed in to change notification settings - Fork 417
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #776 [make:registration] allow email verification without aut…
…hentication (jrushlow) This PR was squashed before being merged into the 1.0-dev branch. Discussion ---------- [make:registration] allow email verification without authentication By passing the user id as an extra query param to `VerifyEmailHelper::generateSignature()` - users are able to verify their email address without being authenticated. As a precautionary note, answering `no` to `Do you want to require the user to be authenticated to verify their email?` will allow anyone with the link generated by `VerifyEmailHelper` to validated that users email address. It should also be advised that answering `no` could possibly leak personally identifiable information in log files if the user `id` is changed to say, a users email address. Commits ------- ebdb227 [make:registration] allow email verification without authentication
- Loading branch information
Showing
11 changed files
with
319 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,7 +79,8 @@ public function getTestDetails() | |
$this->getMakerInstance(MakeRegistrationForm::class), | ||
[ | ||
'n', // add UniqueEntity | ||
'y', // no verify user | ||
'y', // verify user | ||
'y', // require authentication to verify user email | ||
'[email protected]', // from email address | ||
'SymfonyCasts', // From Name | ||
'n', // no authenticate after | ||
|
@@ -110,7 +111,8 @@ function (string $output, string $directory) { | |
$this->getMakerInstance(MakeRegistrationForm::class), | ||
[ | ||
'n', // add UniqueEntity | ||
'y', // no verify user | ||
'y', // verify user | ||
'n', // require authentication to verify user email | ||
'[email protected]', // from email address | ||
'SymfonyCasts', // From Name | ||
'', // yes authenticate after | ||
|
@@ -125,5 +127,26 @@ function (string $output, string $directory) { | |
->addExtraDependencies('symfony/web-profiler-bundle') | ||
->addExtraDependencies('mailer'), | ||
]; | ||
|
||
yield 'verify_email_no_auth_functional_test' => [MakerTestDetails::createTest( | ||
$this->getMakerInstance(MakeRegistrationForm::class), | ||
[ | ||
'n', // add UniqueEntity | ||
'y', // verify user's email | ||
'y', // require authentication to verify user email | ||
'[email protected]', // from email address | ||
'SymfonyCasts', // From Name | ||
'', // yes authenticate after | ||
'main', // redirect to route after registration | ||
]) | ||
->setRequiredPhpVersion(70200) | ||
->setFixtureFilesPath(__DIR__.'/../fixtures/MakeRegistrationFormVerifyEmailNoAuthFunctionalTest') | ||
->addExtraDependencies('symfonycasts/verify-email-bundle') | ||
->configureDatabase() | ||
->updateSchemaAfterCommand() | ||
// needed for internal functional test | ||
->addExtraDependencies('symfony/web-profiler-bundle') | ||
->addExtraDependencies('mailer'), | ||
]; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
.../fixtures/MakeRegistrationFormVerifyEmailNoAuthFunctionalTest/config/packages/mailer.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
framework: | ||
mailer: | ||
dsn: 'null://null' |
20 changes: 20 additions & 0 deletions
20
...ixtures/MakeRegistrationFormVerifyEmailNoAuthFunctionalTest/config/packages/security.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
security: | ||
encoders: | ||
App\Entity\User: bcrypt | ||
|
||
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers | ||
providers: | ||
app_user_provider: | ||
entity: | ||
class: App\Entity\User | ||
property: email | ||
|
||
firewalls: | ||
dev: | ||
pattern: ^/(_(profiler|wdt)|css|images|js)/ | ||
security: false | ||
main: | ||
anonymous: true | ||
# guard: | ||
# authenticators: | ||
# - App\Security\StubAuthenticator |
18 changes: 18 additions & 0 deletions
18
...tures/MakeRegistrationFormVerifyEmailNoAuthFunctionalTest/src/Controller/MyController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 MyController extends AbstractController | ||
{ | ||
/** | ||
* @Route("/", name="main") | ||
*/ | ||
public function index(): Response | ||
{ | ||
return new Response(); | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
tests/fixtures/MakeRegistrationFormVerifyEmailNoAuthFunctionalTest/src/Entity/User.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
namespace App\Entity; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
use Symfony\Component\Security\Core\User\UserInterface; | ||
|
||
/** | ||
* @ORM\Entity() | ||
*/ | ||
class User implements UserInterface | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\GeneratedValue | ||
* @ORM\Column(type="integer") | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @ORM\Column(type="string", length=180, unique=true) | ||
*/ | ||
private $email; | ||
|
||
/** | ||
* @ORM\Column(type="array") | ||
*/ | ||
private $roles = []; | ||
|
||
/** | ||
* @var string The hashed password | ||
* @ORM\Column(type="string") | ||
*/ | ||
private $password; | ||
|
||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getEmail() | ||
{ | ||
return $this->email; | ||
} | ||
|
||
public function setEmail(string $email): self | ||
{ | ||
$this->email = $email; | ||
|
||
return $this; | ||
} | ||
|
||
public function getUsername(): string | ||
{ | ||
return (string) $this->email; | ||
} | ||
|
||
public function getRoles(): array | ||
{ | ||
$roles = $this->roles; | ||
// guarantee every user at least has ROLE_USER | ||
$roles[] = 'ROLE_USER'; | ||
|
||
return array_unique($roles); | ||
} | ||
|
||
public function setRoles(array $roles): self | ||
{ | ||
$this->roles = $roles; | ||
|
||
return $this; | ||
} | ||
|
||
public function getPassword(): string | ||
{ | ||
return (string) $this->password; | ||
} | ||
|
||
public function setPassword(string $password): self | ||
{ | ||
$this->password = $password; | ||
|
||
return $this; | ||
} | ||
|
||
public function getSalt() | ||
{ | ||
} | ||
|
||
public function eraseCredentials() | ||
{ | ||
} | ||
} |
Oops, something went wrong.