1
00:00:01,130 --> 00:00:02,270
In this video.

2
00:00:02,270 --> 00:00:04,370
Let's work with the log in.

3
00:00:04,370 --> 00:00:10,190
Functionality is going to be the same steps as we did for the register.

4
00:00:10,280 --> 00:00:17,060
The first step is let's get to the templates and let's provide the details that we need.

5
00:00:17,330 --> 00:00:25,070
And this is a form where we want to make the request and it's going to be post method and then the end

6
00:00:25,070 --> 00:00:28,250
point is going to be as API.

7
00:00:29,120 --> 00:00:36,800
Four slash vision, one for slash users and then four slash look in.

8
00:00:37,580 --> 00:00:46,130
And inside the impute we have a variable called email, and then the password, which is equally as

9
00:00:46,130 --> 00:00:48,650
the properties inside our model.

10
00:00:48,680 --> 00:00:50,700
Let's have a look for that.

11
00:00:50,720 --> 00:00:54,140
We have email and then the password.

12
00:00:54,140 --> 00:01:01,970
So we have access to those variable inside the controller where it's going to hold the values.

13
00:01:02,180 --> 00:01:07,770
Now the next step is make sure you provide submit as a value to type.

14
00:01:07,790 --> 00:01:09,980
Now we are done with that.

15
00:01:10,190 --> 00:01:17,770
The next step is let's get into the controller for log in and we are done with the API.

16
00:01:17,780 --> 00:01:21,360
So let's collapse this one and here we go.

17
00:01:21,380 --> 00:01:23,390
Everything remains the same.

18
00:01:23,420 --> 00:01:30,690
We have the value on the email and then the password being the structured from the request body.

19
00:01:30,710 --> 00:01:33,350
So let's go ahead and then register.

20
00:01:33,350 --> 00:01:37,310
But as soon as it is registered, we want to return this data.

21
00:01:37,310 --> 00:01:40,040
So let's have a look inside here.

22
00:01:40,070 --> 00:01:49,190
Let me provide Ben gmail.com then the password as one, two, three, four, five.

23
00:01:49,610 --> 00:01:54,010
You can see that the user is being registered successfully.

24
00:01:54,020 --> 00:02:01,280
So to make sure that the user is being registered, right click and click on Inspect and then click

25
00:02:01,280 --> 00:02:07,100
on application and under cookies, click on our new URL.

26
00:02:07,100 --> 00:02:16,280
And you can see that we have connect DOT as ID when in session ID, and this is the user being locked

27
00:02:16,280 --> 00:02:16,820
in.

28
00:02:17,210 --> 00:02:21,080
So now we know that the user is being log in successfully.

29
00:02:21,080 --> 00:02:24,260
So let's go ahead and then redirect the user.

30
00:02:24,320 --> 00:02:28,250
So the same concept as we did for the register.

31
00:02:28,250 --> 00:02:36,230
So instead of returning the JSON data, we are going to redirect the user to his or her profile page

32
00:02:36,260 --> 00:02:38,510
as we did for the register.

33
00:02:38,540 --> 00:02:44,180
Let's screw up and copy the code for redirect, which is this.

34
00:02:45,220 --> 00:02:47,050
And for the log in.

35
00:02:47,050 --> 00:02:55,990
Also, we are going to replace with this one and let me remove the console log for the error message.

36
00:02:55,990 --> 00:02:59,140
It's going to be the same as we did for the register.

37
00:02:59,140 --> 00:03:01,360
So I'm going to copy this code.

38
00:03:03,140 --> 00:03:09,020
And let's scroll down and locate where we want to return an error.

39
00:03:09,290 --> 00:03:12,590
The first one is if the image exists.

40
00:03:12,590 --> 00:03:20,710
So let me paste it here and I want to display the message inside the log in template.

41
00:03:20,740 --> 00:03:28,280
It's going to be as log in and the message is going to be as invalid log in credentials.

42
00:03:28,280 --> 00:03:33,740
So let me replace with this one and let me remove this one from here.

43
00:03:34,440 --> 00:03:41,580
So I'm going to copy the same code and replace with this one in case the password is wrong.

44
00:03:42,420 --> 00:03:50,640
Now let's get back to the log in template and let's display that and we have the code inside the register.

45
00:03:50,640 --> 00:03:53,670
So I'm going to copy for checking error.

46
00:03:53,670 --> 00:03:59,550
And here this is the HTML for displaying the error and paste that.

47
00:03:59,640 --> 00:04:05,130
Lastly, let's get back to the users root where we are rendering the form.

48
00:04:05,130 --> 00:04:12,480
As soon as we click on the link and let's provide the fourth value for the error as we did.

49
00:04:12,480 --> 00:04:19,079
So this one going to be as come on object and then the error and that is it.

50
00:04:19,079 --> 00:04:22,050
So let's go ahead and then log in.

51
00:04:22,620 --> 00:04:32,040
I want to log in with fake credentials as bin at gmail.com and the password and a password.

52
00:04:32,810 --> 00:04:36,620
And I got invalid login credentials.

53
00:04:36,620 --> 00:04:41,030
But if I look in with right details, let's have a look.

54
00:04:45,320 --> 00:04:50,780
And now you can see that I have been redirected to my profile page.

