On this part, we are going to complete the login process and we are going to start by creating a new
action in the account controller just below the existing and logging action.
I'm going to type public async, then task action result and that logging the parameter in here is going
to be the logging view model and the name logging VM.
Now this action is going to be used to handle a request from the form that we created on the last part,
and we have said that the default method in the forms is a post.
So in the account controller, then us decorate this action with HDP boss.
And then inside here, we are going to first check if the model state is valid, so if the model state
is not valid, if is not valid, the model state is valid.
There are just going to return a view and now we are just going to pass as a perimeter, the logging
VM.
If the model state is valid, so if the username and password are valid, then we are going to check
for the user.
We're going to check if the user exists in the database.
So from that far, user is equal to and that await who we're going to use the user manager and then
find by email async.
And then you are going to use the logging VM.
That email address.
Now, if the user is different from now, so if a user with this email address exists, if it's different
from now, then we are going to check for the password.
Otherwise in here, they're going to display an error on the screen, which says one example of that
wrong credentials for this user does not exist.
So here for that, I'll just type dump data, and we have said that we have the view back.
We have the view data.
We also have the temp data.
So temp data and to the temp data, we're going to set an error.
So the error is going to be the key and the message is going to be wrong.
So wrong credentials and then please try again.
Then down here, we are just going to return to the View and to the view, we're going to have the logging
VM as a perimeter.
Now up here, if we have a user, so if the user is different from now, then you go to now check if
the password is valid.
So from that bar password jack is equal to and that we are going to have a wait that underscore user
manager and then check password async and then ignore the first parameter is going to be the user and
the second parameter, the logging VM and then password.
So log in the M Dot.
The person.
If the passport check is true, so if the password is valid and now we are going to sign in the user
using the sign in matcher.
So the result is equal to 08 and then we're going to have these sign in manager, not password signing,
async.
And then in you, we're going to pass the first parameter, the user, the second parameter, the logging
VM, not password and then is persistent and lock on failure is going to be false and then false.
Now, if the result succeeds, if the result not succeeded, then we are going to return the user to
the home page.
So in your return and that redirect to action, it's action.
The first Parmigiani is going to be the action names of the index action, and the controller name is
going to be the movies controller.
Now in here, if the logging doesn't work, so if the password check is false down here.
We're going to set the scene there, so control, see, and then they sit in here and I'll let us at
a break point in here and then run this spot.
So near the airport has successfully let us go to the logging union, not provide an email address or
a passport, I'll just click logging.
I reached the break point, so the model state is not valid, so we're going to return a view with logging
VM that's click Continue.
And you can see that we have the email address is required of the passport field is required.
Now let us add an email address and we know that it's a valid email address and that is the etiquettes
dot com.
So the admin at e-tickets dot com and click the login button.
So new, we can see that we reached the break point, and now we know that the email address is a valid
email address which exists in our database, so we continue.
The logging camp is still not valid, so let us actually provide a password.
So let's say one two three four, which is a wrong best for it, and I click the logging button one
more time.
So we are near the model state is valid.
Let us check for the user.
The user is different from now because we have a user with that email address, but not the password
is wrong.
So the best what check step is going to fail?
So and then here we have the temp data error, and then we turn the view model, so just click continue.
And we can see that the password was reset.
So we don't have a password, but we cannot see the error up here.
So let us just close a browser and let us go and modify the log in view, and here between the P-TECH
can be div tag, we're going to add the temp data there.
So that's Adam, if condition, if and then we are going to check if the temp data error has any value.
So if the time data error is different from now, then down here we are going to have another diff so
that I see a do that in this day.
We're going to have a class.
The glass is going to be called Hamdy and then 12, and we are going to have the alert and the alert
danger bootstrap classes that inside you are going to have a span and that inside this bear, we're
going to have the bold text which says that say sorry.
So we have we have sorry.
And then after the sorry, we're going to have the same data error about this.
Let us copy this part control to see and then base it in here now for the temp data to return a value.
Let us use the at symbol.
Now let us see the chains around this project one more time.
So in your let us click the log in button.
And now you can see that we have your log into your account, so let us provide an email address so
it gets a call.
And then one two, three four and then click the log in button.
You can see it.
We have the error on credentials.
Please try again.
And if you cancel and then you come back to the login view, now you can provide.
A wrong email address, wrong password, and then you have this same error.
Now, let us provide the right credentials, so that mean that the tickets and the passport is courting
at one two three four and then question mark and the click the log in button.
And now you can see that you are successfully logged into the application because you are redirected
to the movies page.
Now on the next parts, when you successfully log in, we're going to hide the log in button.
Instead, we're going to display of the log out button.