Chapters
47 Chapters
|
4:41:51
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!
Subscribe to download the code!
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
This tutorial also works great for Symfony 6!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"babdev/pagerfanta-bundle": "^3.3", // v3.3.0
"composer/package-versions-deprecated": "^1.11", // 1.11.99.4
"doctrine/annotations": "^1.0", // 1.13.2
"doctrine/doctrine-bundle": "^2.1", // 2.6.3
"doctrine/doctrine-migrations-bundle": "^3.0", // 3.1.1
"doctrine/orm": "^2.7", // 2.10.1
"knplabs/knp-markdown-bundle": "^1.8", // 1.9.0
"knplabs/knp-time-bundle": "^1.11", // v1.16.1
"pagerfanta/doctrine-orm-adapter": "^3.3", // v3.3.0
"pagerfanta/twig": "^3.3", // v3.3.0
"phpdocumentor/reflection-docblock": "^5.2", // 5.2.2
"scheb/2fa-bundle": "^5.12", // v5.12.1
"scheb/2fa-qr-code": "^5.12", // v5.12.1
"scheb/2fa-totp": "^5.12", // v5.12.1
"sensio/framework-extra-bundle": "^6.0", // v6.2.0
"stof/doctrine-extensions-bundle": "^1.4", // v1.6.0
"symfony/asset": "5.3.*", // v5.3.4
"symfony/console": "5.3.*", // v5.3.7
"symfony/dotenv": "5.3.*", // v5.3.8
"symfony/flex": "^1.3.1", // v1.21.6
"symfony/form": "5.3.*", // v5.3.8
"symfony/framework-bundle": "5.3.*", // v5.3.8
"symfony/monolog-bundle": "^3.0", // v3.7.0
"symfony/property-access": "5.3.*", // v5.3.8
"symfony/property-info": "5.3.*", // v5.3.8
"symfony/rate-limiter": "5.3.*", // v5.3.4
"symfony/runtime": "5.3.*", // v5.3.4
"symfony/security-bundle": "5.3.*", // v5.3.8
"symfony/serializer": "5.3.*", // v5.3.8
"symfony/stopwatch": "5.3.*", // v5.3.4
"symfony/twig-bundle": "5.3.*", // v5.3.4
"symfony/ux-chartjs": "^1.3", // v1.3.0
"symfony/validator": "5.3.*", // v5.3.8
"symfony/webpack-encore-bundle": "^1.7", // v1.12.0
"symfony/yaml": "5.3.*", // v5.3.6
"symfonycasts/verify-email-bundle": "^1.5", // v1.5.0
"twig/extra-bundle": "^2.12|^3.0", // v3.3.3
"twig/string-extra": "^3.3", // v3.3.3
"twig/twig": "^2.12|^3.0" // v3.3.3
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.3", // 3.4.0
"symfony/debug-bundle": "5.3.*", // v5.3.4
"symfony/maker-bundle": "^1.15", // v1.34.0
"symfony/var-dumper": "5.3.*", // v5.3.8
"symfony/web-profiler-bundle": "5.3.*", // v5.3.8
"zenstruck/foundry": "^1.1" // v1.13.3
}
}
10 Comments
Hello,
When I use FormLoginAuthenticator(built-in) and try to login, the page is still redirecting login page. Authentication is succesfull but page is same.
We were coding redirect response in LoginFormAuthenticator(custom) as below. Did you configure anything for redirection in buil-in authenticator like custom authenticator? If not, why do I see same login page, do I have to configure authentictionsuccess also in buil-in?
Built-in Authenticator:
Hey Mahmut,
I didn't get why you send 2 different codes from
onAuthenticationSuccess().. .which is yours? I suppose you use the custom authenticator like that first code block, so I will assume that's your code. Maybe try to debug the flow withdd()? Make sure you hit thatreturn new RedirectResponse($this->router->generate('app_main_homepage',['username' => $username]));line on the successful login. If not - most probably you hit the earlier redirect which isreturn new RedirectResponse($target);. Probably you need to tweak the logic in youronAuthenticationSuccess()to make sure you redirect users to correct pages.I hope that helps!
Cheers!
Hi Victor,
Sorry for confusing. I am using below code during error. I mean if ı use built-in authenticator, it is redirecting same login page.
However, my custom login authenticator is working well.
Hey Mahmut,
The built-in authenticator can be configured via the configuration, but if you need more flexibility - better to go with your own custom authenticator where you can do whatever you want. Still you can debug the flow using
dd()- that should help to understand the flow and why it does not work as expected for you.Cheers!
I do not get the pre-filled email input once I have logged out. Is this normal? Is it because the session data has been erased at logout?
Hey Francois,
You can totally ignore that
value={{ last_username }}of course if it's not something you need. But the idea behind this thing is to keep the last username user entered - useful when they have misprint their credentials, e.g. password so they don't need to retype the username again and try a different password. That's a common practice on may websites over the internet, but that's totally up to you. Of course when you log out going to the /logout URL - the session will be destroyed and you will not see thatlast_usernameanymore.Cheers!
how can we implement this if we kept using the old
loginFormAuthonticatoron theonAuthenticationFailuremethod?Hey @Soufiyane!
Are you referring to how to print the "last username" thing? If so, the 2 steps are:
1) In your custom authenticator, in
authenticate(), after reading the email, call:2) In your controller, read that value in the same way as see in this chapter :).
Let me know if that helps!
Cheers!
Hi. I stayed with the custom login in my project. Can you show me how to add
$authenticationUtils-> getLastUsername(), in this case? In case withoutform_login: it didn't work :)Hey Leszek,
You only need to inject the service
Symfony\Component\Security\Http\Authentication\AuthenticationUtilsinto your Controller's method, or in case you need it in your authenticator, you can add another argument constructor and inject it thereCheers!
"Houston: no signs of life"
Start the conversation!