We will continue on our project. After we have seen how to make the 'Register' form, now we will create the 'login' form to connect to our application.
The first step is to create the 'ViewModel', and then we create the 'login' UI.
In the 'LoginViewModel' Class, I will add the following properties: Email, Password and 'RememberMe'.
The Password property, I can retrieve it from 'UserInputViewModel'. An optional property of boolean type 'RememberMe'.
If the value of 'RememberMe' is True: The authentication Cookie is stored in the browser even if I close it. If the value of 'RememberMe' is False: The Cookie will be deleted after the browser is closed. So I add the property 'RememberMe' with the 'Display' attribute to simplify its display.
Now, I will create the 'Login' form. Right click on the 'Users' folder, then add a 'Razor Page' named 'Login'. To save some time, I will build the 'Login' form from the 'Register' form. The title of this form is 'login'.
In 'Logn.cshtml.cs' I add a property of type 'LoginViewModel' with my 'InputLogin'. I mark the 'InputLogin' property by '[BindProperty]' to apply the data binding model.
In 'Login.cshtml', I just keep the three fields email, password, RememberMe. I also add 'asp-for'.
I will run to see the rendering, right click on 'Login.cshtml' then 'View in browser'. The 'Register' button I rename it to 'Login'. I can change the icon from the title of this form by another 'bootstrap' icon.
The part on the 'login' action I leave it for the next video inshaallah. But I activate the 'Register' and 'Login' links which is in the navigation bar. I go back to '_Layout' in the 'Shared' folder and I will make the following changes. For the 'Register' link, I add 'asp-page=/Admin/Users/Register'. For the 'Login' link, I add 'asp-page=/Admin/Users/Login'. I Check the links in the navigation bar.
video txt