We will create a Login page in our project.
👉composer require symfony/security-bundle
DATABASE_URL="mysql://db_user:db_password@127.0.0.1:3306/db_name?serverVersion=5.7&charset=utf8mb4"
replace db_user with your database account username , db_password with your database password for that user and at last db_name with your database name which you want to create .Then run this command
👉php bin/console doctrine:database:create
this will create a database with the given name.
Step 3 : create user entity now , run below given command
👉php bin/console make:user
After executing this command it will ask some questions just to hit enter till you get a success message on the terminal.
Step 4 :Now we will migrate using the given below command
👉 php bin/console make:migration
Step 5 : Now run the given commands it will create a table named user in the database
👉 php bin/console doctrine:migrations:migrate
Step 6 : Now run the given command
👉 php bin/console make:auth
now running this command will ask following questions
What style of authentication do you want? [Empty authenticator]:
[0] Empty authenticator
[1] Login form authenticator
> 1 //my input in command prompt
The class name of the authenticator to create (e.g. AppCustomAuthenticator):
> AppCustomAuthenticator //my input in command prompt
Choose a name for the controller class (e.g. SecurityController) [SecurityController]:
> //just hit enter it will take default suggested
Do you want to generate a '/logout' URL? (yes/no) [yes]:
> //just hit enter it will take default suggested
Step 7 : Now go to the given URL http://127.0.0.1:8000/login you will see a login page it means we have successfully created a login page
We will create a registration page in our project.
step1: run
👉 composer require form validator then this command
👉 php bin/console make:registration this command will ask below questions
Do you want to add a @UniqueEntity validation annotation on your User class to make sure duplicate accounts aren't created? (yes/no) [yes]:
> //hit enter if you want to stop duplicate account creation
Do you want to send an email to verify the user's email address after registration? (yes/no) [yes]:
> no //hit enter if you want to send a link on user email to verify given email, i have entered no because i dont want this as of now
Do you want to automatically authenticate the user after registration? (yes/no) [yes]: //hit enter if you want to let user use their account just after registration , without asking to login again to him after regestration
>
step 2: now just go to the url http://127.0.0.1:8000/register your registration form is ready to use.
0 Comments