Hey, guys, I think we can begin by creating the authentication controller login form action that will
display the login form.
It's essential that we have a form that we can submit to test all the other functionalities.
So let me jump to the code editor.
And before we actually begin, I wanted to remove this excessive header that we have in the home index
template.
It seems to be taking too much space without any reason.
And remove this header from the index file in the post folder.
Okay, so a tiny cleanup.
Now let's just go ahead and create the controller.
It can be called an auth controller.
So we add the PHP tag and we define the namespace which is app controllers.
And the class is auth controller.
Now let me add the actions.
The first one I'm going to call it create.
This action will just display the form.
And another one I'm going to call it store.
And it will be responsible for handling the form submission.
Now the names I have given to those actions are not accidental.
That's the notation you're going to see in the Laravel framework.
So the action that renders the form is typically called create.
And the action that handles the form submission is called store.
So in this video we are working on that one.
So our job is just to render the form.
Let's use our view class for that.
Render method and start with the template.
So this could be our create Our layout is layouts main, and I don't think we need any data in here.
Now let's jump to the views and create the missing folder.
So this will be auf and the template name.
It is create.
PHP.
Let's start with a header.
Let's just say login.
And then we're just going to add a form.
So we need the URL.
I think this auth controller can lead to the login page.
And the method here has to be post.
So why it has to be post.
Well if the method would be get, then the username and password will be sent as the URL query parameters,
which means they will be stored in the browser history.
So that's obviously a no no.
It needs to be sent through the post method.
So I think that we don't have here but we're going to add later are the CSRF tokens.
So let's begin by adding the inputs.
So we need a label.
Let it be email.
And also I'm going to add the for attribute for the email field so that it can be activated when you
click on the label.
The type is email.
Now I need to give an ID so that this for attribute can find the input.
And the name of it is also email and it's required.
Now I'm going to quickly copy and paste that to add another one.
That's password.
And here we can use the type password.
There is a type like that.
The ID is also password.
The name is also password and it's also required.
So we had those two inputs.
And then we're just going to have our submit button.
So the type is submit by default.
But we can be explicit in this case.
Let's just say login.
So there are a couple of features that we don't have here.
So we don't display any kind of errors.
We don't have the CSRF token.
And here in the future we might have a Remember Me feature.
That would be just a check box.
And if someone would check this check box, we're going to try to remember them being sign in for,
let's say two weeks.
So we can verify if this page gets displayed properly.
But first we need to add a route.
So let me copy and paste it for it to be quicker.
And I said we're going to use this path to display the auth controller.
So this is the auth controller create.
That's a form.
The same URL will be used but with a different method to handle the form submission.
And later on we might have one more connected to the auth controller.
This might be just a logout action.
For now, let's just check if this works.
So let me jump to the auth controller.
And here let me just die with some message like form sent.
Next up, let's just jump to the browser and see if we can submit the form and receive the data inside
the store.
Action.
I might also do var dump with the post data first.
Okay, so let me type an email because we need to type something to those fields.
By adding this required attribute, we just make them forcing the user to type something.
Now as you see, this input of type password by default is hiding the typed password.
So now I hit login, I see the submitted data and the text form sent, which just confirms that our
setup works perfectly fine.
And the logic that handles this form submission is actually authenticating the user.
This would take a little bit more time.
So for now let's just wrap up this video.
Next up we'll be working on this form submission logic trying to authenticate the user.