1 00:00:00,900 --> 00:00:01,530 Welcome back. 2 00:00:01,950 --> 00:00:04,680 Now, what we need to do is that we need to work on the log in page. 3 00:00:05,160 --> 00:00:10,140 And in order to work on the log in page, the first step is that we need to convert the log in page 4 00:00:10,140 --> 00:00:13,230 from log in that into email to a log in that PDB. 5 00:00:13,680 --> 00:00:17,070 So I'm going to rename the page and I'm going to give it the BGP extension. 6 00:00:17,080 --> 00:00:19,340 I'm going to say logging dot BHP. 7 00:00:19,980 --> 00:00:21,240 So this is the first step. 8 00:00:21,750 --> 00:00:26,940 Now let me go to the log and I'm going to say here for Slash and then log in that be a tree. 9 00:00:27,660 --> 00:00:28,800 And this is the log a bit. 10 00:00:29,070 --> 00:00:36,150 So what we need to do is that we need to take the user from from this log into the account if we if 11 00:00:36,150 --> 00:00:37,320 the log in successfully. 12 00:00:37,860 --> 00:00:42,420 So in the log in Beijing, let me open up the log in page and let's start working on this. 13 00:00:42,930 --> 00:00:47,550 So the first thing is that we need to make sure that the form is, is that we have a form. 14 00:00:47,550 --> 00:00:50,520 So we have a form, as you can see, and we have two inputs. 15 00:00:50,520 --> 00:00:54,030 We have the email and the password and the log in button. 16 00:00:54,450 --> 00:00:58,920 So what we need to do is that here in this form, we need to give it action and method. 17 00:00:59,550 --> 00:01:00,570 So I'm going to say action. 18 00:01:01,080 --> 00:01:11,040 The action is, is going to be log in that the same page and the method is obviously going to be both. 19 00:01:12,590 --> 00:01:16,280 And let's work on the let's work on the logic. 20 00:01:17,570 --> 00:01:21,110 But before we work on the logic, we need to give this button, this input. 21 00:01:21,980 --> 00:01:22,970 We need to give it any. 22 00:01:23,000 --> 00:01:33,080 So I'm going to say your name and the name is going to be log in n log in, underscore median. 23 00:01:33,950 --> 00:01:42,440 Now at the top, we need to add the P because that's going to check and process the log in in this speech. 24 00:01:42,980 --> 00:01:47,140 So here I'm going to say first, I'm going to say include. 25 00:01:47,300 --> 00:01:54,470 Then what we want to include is that we want to include the server server for slash connection. 26 00:01:56,210 --> 00:01:59,240 And then we want to also include this issue. 27 00:01:59,330 --> 00:02:04,850 So I'm going to say at the top, at the very top, I'm going to say session starts because we need to 28 00:02:04,850 --> 00:02:11,420 use the session later and we need to use a statement to check the the pattern. 29 00:02:11,420 --> 00:02:16,070 If the user clicked on the button on the log in button, so I'm going to say a set lost. 30 00:02:18,820 --> 00:02:27,400 And a set Bost log in underscore the end, which is this button, remember this button that I just gave 31 00:02:27,400 --> 00:02:36,880 it a name, log in, underscore between, log in, underscore within, and then you're in this log in. 32 00:02:36,880 --> 00:02:43,750 What we want to do is that we want to get user information, so we need to get the email and the password. 33 00:02:43,780 --> 00:02:46,210 I'm going to say email is equal to. 34 00:02:47,830 --> 00:02:48,340 Fast. 35 00:02:50,000 --> 00:02:50,600 Email. 36 00:02:52,590 --> 00:02:53,580 And the passwords. 37 00:02:57,330 --> 00:02:59,850 Is equal to last. 38 00:03:06,960 --> 00:03:07,590 Password. 39 00:03:11,470 --> 00:03:14,620 And then we need to use the connection in order to connect to the database. 40 00:03:14,620 --> 00:03:19,090 So I'm going to say ACORN and then prepare, prepare. 41 00:03:19,090 --> 00:03:21,730 And then we need to say select. 42 00:03:23,730 --> 00:03:24,900 Select. 43 00:03:27,670 --> 00:03:29,140 Sally. 44 00:03:30,630 --> 00:03:31,820 When do we want to select? 45 00:03:31,830 --> 00:03:44,160 We want to select the the we want to select the user ID and the user the user ID and the user. 46 00:03:46,050 --> 00:03:46,680 Email. 47 00:03:48,120 --> 00:03:49,920 And the username as well. 48 00:03:50,250 --> 00:03:58,860 Being a person username user, underscore name and comma and then user user email. 49 00:03:59,550 --> 00:04:01,350 User user email. 50 00:04:03,040 --> 00:04:08,740 And user password where? 51 00:04:10,920 --> 00:04:13,710 From from first from users. 52 00:04:13,710 --> 00:04:14,190 Where? 53 00:04:14,520 --> 00:04:15,660 From users where? 54 00:04:16,830 --> 00:04:17,490 Where. 55 00:04:20,620 --> 00:04:21,490 User. 56 00:04:22,860 --> 00:04:23,430 Name. 57 00:04:23,760 --> 00:04:24,660 User email. 58 00:04:25,500 --> 00:04:26,940 User email. 59 00:04:27,930 --> 00:04:28,920 Is equal. 60 00:04:30,350 --> 00:04:34,370 To question mark and. 61 00:04:36,500 --> 00:04:37,130 And. 62 00:04:38,530 --> 00:04:39,220 Password. 63 00:04:41,570 --> 00:04:42,170 That's. 64 00:04:43,310 --> 00:04:44,330 Use our password. 65 00:04:48,740 --> 00:04:52,070 Is equal to question mark. 66 00:04:54,290 --> 00:04:56,420 And then we need to see a limit. 67 00:04:57,930 --> 00:05:01,800 Limit one when you want only one user. 68 00:05:02,910 --> 00:05:08,970 And then we need to store this in a variable called statement is the empty. 69 00:05:10,320 --> 00:05:16,800 And before we proceed we need to say here in the file we need to hash the password in order to compare 70 00:05:16,800 --> 00:05:18,960 the password with the hash password in the database. 71 00:05:19,710 --> 00:05:21,240 So here we need to say in the file. 72 00:05:23,230 --> 00:05:30,790 And then we want to use this the to bind we need to say and then bind. 73 00:05:31,890 --> 00:05:32,350 Baram. 74 00:05:33,120 --> 00:05:41,340 And then we want to bind the SS email and password email. 75 00:05:42,370 --> 00:05:43,300 And crossword. 76 00:05:44,900 --> 00:05:46,220 And then we need to execute. 77 00:05:46,220 --> 00:05:49,160 We need to say, here is the empty. 78 00:05:50,430 --> 00:05:51,060 Excuse. 79 00:05:52,950 --> 00:05:57,720 This is going to exclude, uh, the the queen. 80 00:05:59,160 --> 00:06:01,400 And then I'm going to hear check. 81 00:06:01,410 --> 00:06:02,490 I'm going to say if. 82 00:06:03,720 --> 00:06:11,030 If the statement is three times true, then here, here we have a result. 83 00:06:11,040 --> 00:06:12,450 Else we don't have a result. 84 00:06:13,110 --> 00:06:19,890 So if this is true, what we want to do is that we need to bind the result, read a statement, and 85 00:06:19,890 --> 00:06:21,630 then bind results. 86 00:06:23,010 --> 00:06:24,720 So what is the what? 87 00:06:24,800 --> 00:06:29,510 What are the what are the values that we want to get from the database? 88 00:06:29,520 --> 00:06:37,080 We want to get the user ID, we want to get the user name and we want to get the user. 89 00:06:38,860 --> 00:06:39,550 Email. 90 00:06:41,600 --> 00:06:42,920 And we want to get the. 91 00:06:44,100 --> 00:06:45,150 User password. 92 00:06:47,040 --> 00:06:47,750 Passport. 93 00:06:53,180 --> 00:06:58,490 And then we need to say Fitch statement, which we need to get to the results. 94 00:06:59,360 --> 00:07:07,400 But before I reach the the result, I'm going to see if if. 95 00:07:09,610 --> 00:07:18,760 If statement if statement num underscore rise is equal to one. 96 00:07:19,660 --> 00:07:23,350 If there's only one user, then we need to fetch. 97 00:07:23,350 --> 00:07:33,100 We need to say a statement which we need to say your statement and then which statement is the empty 98 00:07:34,000 --> 00:07:35,020 and then fetch. 99 00:07:35,650 --> 00:07:45,340 This is going to get a result from the database and we need to store this speech in a in a variable. 100 00:07:45,580 --> 00:07:46,330 It's a raw. 101 00:07:47,460 --> 00:07:48,390 Because this is going to return. 102 00:07:48,390 --> 00:07:52,470 Only one draft to raw is going to be equal to statement which. 103 00:07:53,520 --> 00:07:56,520 And here your air. 104 00:07:58,490 --> 00:07:58,910 Air. 105 00:08:00,280 --> 00:08:01,140 You're there. 106 00:08:01,180 --> 00:08:04,120 There must be an error, and that's it. 107 00:08:04,150 --> 00:08:06,990 Now we want to get the result from. 108 00:08:07,000 --> 00:08:08,060 From the. 109 00:08:08,830 --> 00:08:09,670 From the database. 110 00:08:13,020 --> 00:08:17,790 So we can use this right in order to access the the parameters of these parameters. 111 00:08:17,790 --> 00:08:22,560 Or we can instead, we can use these parameters immediately. 112 00:08:22,560 --> 00:08:28,320 So if we decide to use these parameters immediately, there is no need to store this in or we just need 113 00:08:28,320 --> 00:08:31,800 to say fetch and then we can store. 114 00:08:31,800 --> 00:08:40,890 Now everything in the session, we need a session and then user underscore ID is equal to the ID, the 115 00:08:40,890 --> 00:08:46,380 user ID and then user username. 116 00:08:47,780 --> 00:08:49,280 User username. 117 00:08:49,700 --> 00:08:51,980 Session username. 118 00:08:53,300 --> 00:08:53,930 Session. 119 00:08:55,880 --> 00:08:58,580 User name. 120 00:09:00,920 --> 00:09:04,550 Is equal to user. 121 00:09:06,320 --> 00:09:14,120 Underscore me here, by the way, I should say user underscore name and user underscore name and then 122 00:09:14,750 --> 00:09:15,350 session. 123 00:09:19,250 --> 00:09:19,970 User. 124 00:09:20,360 --> 00:09:26,060 Their score email is equal to user. 125 00:09:27,880 --> 00:09:28,510 Email. 126 00:09:30,540 --> 00:09:31,260 And then. 127 00:09:32,960 --> 00:09:33,560 Session. 128 00:09:35,810 --> 00:09:36,710 Use our password. 129 00:09:38,260 --> 00:09:40,440 We shouldn't be storing the user passwords. 130 00:09:40,440 --> 00:09:43,960 We we we don't need to do this and we shouldn't be doing this, actually. 131 00:09:44,650 --> 00:09:47,620 The last thing that we need to store in this session is the log in status. 132 00:09:48,190 --> 00:09:50,080 And here we need to say logged in. 133 00:09:50,920 --> 00:09:52,480 Logged in is equal to two. 134 00:09:58,570 --> 00:09:59,650 And that's it. 135 00:10:00,700 --> 00:10:05,620 Now, what we want to do is that we want to, um. 136 00:10:06,100 --> 00:10:07,090 To handle EOR. 137 00:10:07,100 --> 00:10:08,950 So here, in case of error, we need to say Heather. 138 00:10:10,450 --> 00:10:12,640 Heather and then location. 139 00:10:14,900 --> 00:10:25,580 Index location log in that BHP and then error is equal to something went wrong. 140 00:10:30,470 --> 00:10:37,370 And here, in case of success, we just need to take the user through the login page to the, to the 141 00:10:37,370 --> 00:10:39,710 account page location. 142 00:10:40,820 --> 00:10:45,590 Location and then account dot BHP. 143 00:10:47,550 --> 00:10:55,980 And here we can see the message is equal to log in successfully. 144 00:10:57,330 --> 00:11:03,720 You can display this message to the user and to hear what they need to do here before I guess they need 145 00:11:03,720 --> 00:11:09,480 to say a statement and then store result, store results. 146 00:11:10,560 --> 00:11:11,400 So that's it to you. 147 00:11:11,430 --> 00:11:13,140 In case of success, we need to do this. 148 00:11:14,190 --> 00:11:14,630 And. 149 00:11:17,270 --> 00:11:17,690 That's it. 150 00:11:17,690 --> 00:11:22,910 Leave me now and let me also display the air so the air can be displayed above the form. 151 00:11:23,480 --> 00:11:31,430 So above the form your B and then style color. 152 00:11:33,320 --> 00:11:33,830 Read. 153 00:11:35,290 --> 00:11:35,920 Glass. 154 00:11:37,910 --> 00:11:42,230 Text Santer here, I'm going to say B2B. 155 00:11:44,220 --> 00:11:49,320 And I'm going to say if is set yet. 156 00:11:51,530 --> 00:11:52,910 If a circuit error. 157 00:11:55,840 --> 00:11:58,660 Then we need to display their. 158 00:12:01,550 --> 00:12:02,060 Echo. 159 00:12:04,980 --> 00:12:06,630 Get air. 160 00:12:09,120 --> 00:12:11,580 Air semicolon. 161 00:12:13,940 --> 00:12:21,680 And regarding the handling of errors here, in case there is not equal to one, then we can also say 162 00:12:21,680 --> 00:12:27,080 else and then we can copy this header and display an error. 163 00:12:29,130 --> 00:12:36,000 And here we can see a log in that BGP and then enter is equal to. 164 00:12:38,860 --> 00:12:49,390 You could not vary by your account or there is no account with these credentials. 165 00:12:50,080 --> 00:12:54,040 And in case of error we need to display here. 166 00:12:54,880 --> 00:12:55,720 Something went wrong. 167 00:12:56,220 --> 00:12:59,170 It also let me add the registration link here. 168 00:12:59,860 --> 00:13:08,200 I'm going to say it is equal to register that BHP alamy go to the log in page to test. 169 00:13:08,230 --> 00:13:13,510 So first of all, I'm going to go to the log in page and refresh and I'm going to here try to log in 170 00:13:13,510 --> 00:13:16,480 with the account that they have created earlier with this account. 171 00:13:17,410 --> 00:13:18,970 So I know my email and password. 172 00:13:18,970 --> 00:13:24,610 Lainey here say info at email dot com. 173 00:13:28,420 --> 00:13:32,530 So if I click on log in, as you can see, I will be taken to my account. 174 00:13:33,910 --> 00:13:39,580 And if I go back to the log in page, let's log in with an email that doesn't exist. 175 00:13:46,020 --> 00:13:50,850 So if they try to log in with this with these credentials, it's going to say, according, to verify 176 00:13:50,850 --> 00:13:52,770 your account is for this part. 177 00:13:53,250 --> 00:13:59,280 And the last thing that we need to do is that we need to prevent the user from going to a login page 178 00:13:59,280 --> 00:14:00,240 if they are logged in. 179 00:14:00,600 --> 00:14:02,340 And to do this, we need to adhere. 180 00:14:03,960 --> 00:14:08,520 So here what I'm going to do is that I'm going to add a statement at the top and then I'm going to say, 181 00:14:08,520 --> 00:14:09,660 session is set. 182 00:14:09,660 --> 00:14:11,760 Session is set. 183 00:14:13,390 --> 00:14:13,990 Session. 184 00:14:15,600 --> 00:14:19,410 Logged in, logged on their score in. 185 00:14:19,410 --> 00:14:25,320 If the user is logged in, then we need to take the user to the account page. 186 00:14:25,650 --> 00:14:28,770 So I'm going to say here, location, either location. 187 00:14:29,670 --> 00:14:34,450 And then I'm going to take the user to the account and then that's it. 188 00:14:34,470 --> 00:14:39,300 We just take the user to that account page and we exit in case the session is set. 189 00:14:40,350 --> 00:14:46,590 Similarly, with the registration page, in order to protect the page completely, we need to, instead 190 00:14:46,590 --> 00:14:55,620 of saying else here, we should actually copy this part and remove it from here and add the elite bracket 191 00:14:55,620 --> 00:14:55,860 here. 192 00:14:55,860 --> 00:14:57,120 Don't forget the cannoli bracket. 193 00:14:57,840 --> 00:14:59,370 And at the top, we need to say. 194 00:15:01,130 --> 00:15:02,630 You're at the top, we need to say. 195 00:15:03,170 --> 00:15:12,950 But if just if if user is logged in, then we take them to the account which lets now this lady notice 196 00:15:12,950 --> 00:15:13,200 this. 197 00:15:13,760 --> 00:15:16,310 So now I should, I should be logged in. 198 00:15:16,310 --> 00:15:21,230 So if I try to go to the login page, I will not be able to. 199 00:15:21,950 --> 00:15:25,280 So if I go to the log in, I will not be able to. 200 00:15:25,280 --> 00:15:28,940 If I try to go to the register, I will not be able to. 201 00:15:29,660 --> 00:15:34,160 As you can see, as you can see, I will not be able to go to the to either the registration page or 202 00:15:34,160 --> 00:15:36,650 the logging page because I'm not logged in.