Automatically Authenticating after Registration
…function called authenticateUser inside RegisterController. Normally,
authentication happens automatically, but we can also trigger it manually:
// src/Yoda/UserBundle/Entity/Controller/RegisterController.php
// ...
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
private function authenticateUser(User $user)
{
}
This code might look strange, and I don’t…
Creating a Login Form (Part 2)
…
Copy the template code from the docs and create the login.html.twig file:
{# src/Yoda/UserBundle/Resources/views/Security/login.html.twig #}
{% if error %}
{% endif %}
Introduction
…s get to work.
Over the next hour, we’re going to take things to the next level, aiming
at some of the most difficult areas of Symfony, like security, forms, and
some serious Doctrine topics. Some of this stuff will look pretty tough at…
Twig Mind Tricks
…every template, you have access to
a variable called app. This has a bunch of useful things on it, like
the request, the security context, the User object, and the session:
It's actually an object called GlobalVariables, which you can check out
yourself. So…
FOSUserBundle
…method for installing bundles.
Generating the User Entity¶
Let’s forget about security for a second and pretend that all we care about
is creating a User entity that is stored in the database. Let’s create
a new bundle called UserBundle to house the…
Form Improvements for Symfony 6
…Here, you can see blog posts that
are categorized by each version. This is a collection of blog posts about what's
new in Symfony 5.1, like the new security system. And... here are posts about
what's new in Symfony 5.3, or…
Timeline: Finding a Hidden Surprise
…the routing layer happens! That's RouterListener. You can
also see Firewall: this is where authentication takes place. Security is a complex
system... so being able to see a bit about what happens inside of it is pretty
cool. At some point... it calls a…
addStyleEntry(): CSS-Only Entrypoint
…files left. Open account/index.html.twig:
Yep, this has a link tag to the first... and in security/login.html.twig, here's
the other:
Oh, and we also include login.css from register.html.twig:
This is kind of a tricky situation.... because…
Services, Autowiring & Pushing To GitHub
…
Inside SecurityBundle, look at DependencyInjection and open SecurityExtension.php.
This class loads several XML files that provide all of the services for this bundle.
Inside the Resources/config/ directory, open security.xml. Around line 136...
yep! You'll see the services that our new service…
Symfony's Branching Strategy & Pull Requests
…more level of difficulty: it's time to contribute new
code with a pull request. Let's look at an issue I found:
#27835.
This comes from the Security component. Let me give you some background: if you try
to access a protected page as…
Autowiring Deprecations
…supported in version 4.0. You should rename or
alias security.user_password_encoder.generic to ... long class name...
UserPasswordEncoder instead.
Um... what?????
This is saying that somewhere, we are type-hinting an argument with
Symfony\Component\Security\Core\Encoder\UserPasswordEncoder... but there is no…
Multiple Entries / Pages
…login
page... which has just a little bit of its own JavaScript: a toggleable message
and an error if you get crazy and type a super-long username.
Open up the template: app/Resources/FOSUserBundle/views/Security/login.html.twig.
Yep, it has a script…
Deploy to AWS!
…use the micro instance size, and just
use the default settings on the next screens.
For the security group, I'm going to select a group I already created: "Web Access
Testing." The important thing is to allow port 22 for SSH and ports 80…
Dependency Injection Extensions
…I just make something up, like journey and put a
dino_count of 10 under it:
When we refresh, we get a huge error!
And it says it found valid namespaces for framework, security, twig,
monolog, blah blah blah. Hey, those are the root keys…
Upgrading & What's New in Symfony 5!
…secrets management
Auto-validation
The new PHP 7.4 "preload" file
Using "migrate_from" to migrate your hashed passwords for max security
bin/console lint:container
And these are just my favorite features (see Symfony.com 4.4/5.0 Features Blog for even more…
FOSUserBundle FTW!
…you'll learn how to:
Install & setup FOSUserBundle
Understanding and configuring security
Using your own base layout
Overriding templates
Customizing and extending the forms
Removing the username field entirely
Updating any text via translations
Creating an event subscriber to do things before/after registration (or…
RESTful APIs in the Real World Course 2
…we're attacking the hard
stuff:
Using a serializer
Token Authentication System (Silex's security system)
Hypermedia versus media
The HAL hypermedia type
The HATEOAS PHP library
The HAL Browser
Embedding resources (versus adding links)
Tricks with Behat for testing API's
Pagination and filtering…
FOSUserBundle FTW! (v1.3)
…bundle, and with good reason.
It comes packed with features for login, registration, forgot password
and a lot more. But it's also a big tool, and learning to master it will
go a long way to making the security system in your application great.
Maker Bundle: Let's Generate Some Code!
…I'll start running symfony console, which is the same thing. Thanks
to the new bundle, we have a ton of commands that start with make! Commands for
generating a security system, making a controller, generating doctrine entities to
talk to the database, forms, listeners…
Creating the User Class
…double-check our user was added correctly, run:
symfony console dbal:run-sql 'select * from user'
Nice, here he is! But hmm... we have a serious security issue here... don't worry, we'll fix it soon... but
can you guess what it is?
Next…
x
1000+