WEBVTT 00:00:07.110 --> 00:00:11.160 In this video we're going to start writing code for the logging process. 00:00:11.430 --> 00:00:18.900 So when the user is trying to log in and they provide their logging information if the logging is successful 00:00:19.320 --> 00:00:24.080 OK they're going to be directed to the main page locked in with their notes. 00:00:24.150 --> 00:00:24.910 OK. 00:00:25.080 --> 00:00:33.890 Otherwise they're going to receive an error message if anything is wrong in their form. 00:00:34.190 --> 00:00:35.770 OK. 00:00:36.450 --> 00:00:45.210 So let's go ahead and start revising our code so similarly to the sign up process we're going to send 00:00:45.210 --> 00:00:46.730 an AJAX call. 00:00:46.760 --> 00:00:47.590 OK. 00:00:48.150 --> 00:00:49.300 From the index. 00:00:49.380 --> 00:00:50.720 Those js file. 00:00:50.990 --> 00:00:51.540 OK. 00:00:51.730 --> 00:00:57.560 So the school is going to send information to the log in those THP file. 00:00:57.630 --> 00:00:59.620 So what are we going to do. 00:00:59.650 --> 00:01:04.950 Going to copy the same code we used for sign up. 00:01:05.530 --> 00:01:05.880 OK 00:01:05.900 --> 00:01:11.940 . 00:01:15.660 --> 00:01:17.300 And then we're going to change it slightly. 00:01:17.510 --> 00:01:18.790 OK. 00:01:19.920 --> 00:01:24.560 Well the logging process. 00:01:24.570 --> 00:01:27.810 So we're looking to the loggin form. 00:01:28.030 --> 00:01:31.220 OK. 00:01:32.910 --> 00:01:38.850 And we're sending sending data to the logging those page before. 00:01:39.300 --> 00:01:46.090 Now if the logging if the Ajax school is successful we're going to check the data returned by the log 00:01:46.090 --> 00:01:47.490 in those BHB files. 00:01:47.730 --> 00:01:55.700 So if the logging is successful OK the file logging that page is going to return success. 00:01:55.860 --> 00:02:01.530 So we're going to check if the data equals success. 00:02:02.400 --> 00:02:10.230 Ok then we going to direct or redirect our user to the Notes page. 00:02:10.230 --> 00:02:14.780 OK so it is going to be window not location. 00:02:16.260 --> 00:02:17.680 OK. 00:02:17.810 --> 00:02:23.430 We're going to the main page logged in those BHB. 00:02:24.240 --> 00:02:24.840 Otherwise 00:02:31.320 --> 00:02:34.960 the logging in those page profile is going to return an error message. 00:02:34.980 --> 00:02:35.440 OK. 00:02:35.520 --> 00:02:39.840 And we're going to display the error message inside the logging message. 00:02:39.930 --> 00:02:40.390 OK. 00:02:40.530 --> 00:02:43.570 Which is right on the top of this phone. 00:02:43.800 --> 00:02:44.060 OK. 00:02:44.070 --> 00:02:50.820 So we're going to select the day of corresponding to that message. 00:02:51.660 --> 00:02:58.520 So it's already is a logging message and then we're going to change its e-mail content. 00:02:59.100 --> 00:03:00.720 OK. 00:03:01.050 --> 00:03:04.440 To the content of the data variable. 00:03:04.920 --> 00:03:05.960 OK. 00:03:07.040 --> 00:03:09.370 So it is save. 00:03:09.390 --> 00:03:16.770 Now let's go to the logging those BHB file and write code for the logging process. 00:03:16.770 --> 00:03:24.410 So he start the session OK or restarts the prerecession using the session start function 00:03:26.660 --> 00:03:28.510 . 00:03:31.200 --> 00:03:38.080 You need to have BHB tags from the beginning and the end code 00:03:38.080 --> 00:03:44.910 . 00:03:46.680 --> 00:03:48.840 I'm going to tidy up these comments. 00:03:48.840 --> 00:03:53.760 They look like these are the moments because they were thought by brackets to be a shemale comments 00:03:53.900 --> 00:03:58.320 and when to just pause the video and just take them take them up for BHB. 00:03:58.380 --> 00:03:59.390 OK. 00:04:00.180 --> 00:04:02.630 OK so now let's connect to the database. 00:04:02.670 --> 00:04:03.310 OK. 00:04:03.600 --> 00:04:06.860 So going to use exactly the same scene sucks as before. 00:04:06.900 --> 00:04:11.730 We'll just include the connection file. 00:04:13.560 --> 00:04:17.220 All right. 00:04:18.230 --> 00:04:19.100 OK. 00:04:19.890 --> 00:04:22.300 Now we're going to check the user inputs. 00:04:22.410 --> 00:04:25.110 So as usual we going to find the error messages first. 00:04:25.110 --> 00:04:25.560 OK. 00:04:25.590 --> 00:04:27.570 And then we're going to get the inputs. 00:04:27.570 --> 00:04:30.730 So we're going to have a couple of error messages. 00:04:30.810 --> 00:04:34.030 Missing e-mail and missing password. 00:04:34.740 --> 00:04:39.320 So if we're missing e-mail so let's create a paragraph. 00:04:39.460 --> 00:04:45.150 Ok so later on we're going to up these paragraphs inside a div and give the div some signing. 00:04:45.390 --> 00:04:55.720 So we're missing e-mailing and have please answer your e-mail address. 00:04:57.420 --> 00:04:58.490 OK. 00:04:58.500 --> 00:05:02.940 So we can make the message bold by adding the strong tags 00:05:05.850 --> 00:05:06.690 like is 00:05:09.450 --> 00:05:12.380 the next one is going to be missing. 00:05:12.480 --> 00:05:14.460 Password. 00:05:15.580 --> 00:05:16.750 OK. 00:05:20.090 --> 00:05:24.290 And you're going to have more or less the same thing. 00:05:24.380 --> 00:05:24.960 OK. 00:05:25.190 --> 00:05:29.310 Please enter your password. 00:05:29.540 --> 00:05:31.790 Now let's get the inputs. 00:05:31.810 --> 00:05:35.530 Are going to do exactly the same thing as we did in the Sign-Up code. 00:05:35.600 --> 00:05:36.470 OK. 00:05:36.470 --> 00:05:40.790 So it is just copying code and adjusts. 00:05:41.260 --> 00:05:47.490 So for the e-mail. 00:05:53.270 --> 00:05:56.680 OK so are you going to check if the email is empty. 00:05:56.690 --> 00:05:57.280 OK. 00:05:57.340 --> 00:06:01.740 And then we're going to add the missing e-mail error. 00:06:01.990 --> 00:06:02.790 OK. 00:06:02.870 --> 00:06:10.280 Otherwise we're going to filter the e-mail using the filter sign size e-mail and we don't need to validate 00:06:10.280 --> 00:06:11.000 the e-mail. 00:06:11.150 --> 00:06:12.370 OK. 00:06:12.720 --> 00:06:17.030 We're going to be only checking the combination of the e-mail and password. 00:06:17.050 --> 00:06:24.200 OK we're not going to be doing any sort of registration of data. 00:06:24.200 --> 00:06:24.630 OK. 00:06:24.830 --> 00:06:27.070 So we don't have to validate the e-mail. 00:06:27.530 --> 00:06:30.820 So it is the least bit OK 00:06:34.790 --> 00:06:36.650 now regarding the name of the inputs. 00:06:36.650 --> 00:06:44.470 If you look at the logging form the name of the e-mail inputs is called logging e-mail. 00:06:44.650 --> 00:06:48.000 OK. 00:06:50.570 --> 00:06:55.490 So it's not e-mail like this in the form. 00:06:55.490 --> 00:06:57.430 OK. 00:06:57.470 --> 00:07:02.050 Now let's do the same thing for the password. 00:07:05.150 --> 00:07:09.890 So the name for the password in was is logging password. 00:07:11.670 --> 00:07:12.450 OK. 00:07:12.750 --> 00:07:22.880 And the variable is going to be password and the error is missing password and when with field said 00:07:22.880 --> 00:07:27.410 the password you're going to filter it as a string. 00:07:27.410 --> 00:07:30.270 So we're to use filter sanitize string. 00:07:30.350 --> 00:07:32.110 OK. 00:07:33.500 --> 00:07:39.130 All right so far we go the user inputs and also we stored the errors in the error is variable. 00:07:39.260 --> 00:07:42.480 Ok so we covered this step as well. 00:07:43.600 --> 00:07:44.920 All right. 00:07:46.090 --> 00:07:49.720 Now we're going to check if there are any errors. 00:07:49.790 --> 00:07:50.670 OK. 00:07:51.050 --> 00:07:51.470 So 00:07:58.130 --> 00:08:07.920 if the air is very well is most empty OK or if error is then going to echo an error message. 00:08:07.940 --> 00:08:09.000 All right. 00:08:09.530 --> 00:08:17.550 So we're going to go to the Sign-Up code and copy the same code from there. 00:08:17.600 --> 00:08:18.410 It's very similar 00:08:18.410 --> 00:08:25.790 . 00:08:25.790 --> 00:08:27.420 All right. 00:08:27.920 --> 00:08:28.850 And then 00:08:32.450 --> 00:08:35.100 we're going to have an else statement. 00:08:36.180 --> 00:08:36.650 OK. 00:08:36.690 --> 00:08:43.270 For no errors. 00:08:49.520 --> 00:08:49.980 OK. 00:08:50.180 --> 00:08:55.400 So if we have no errors then we're going to prepare the variables for the query in the same way we have 00:08:55.400 --> 00:08:57.760 done in the sign up file. 00:08:57.950 --> 00:08:58.850 OK. 00:08:58.850 --> 00:09:02.870 So we're going to have the e-mail and password. 00:09:02.870 --> 00:09:07.480 So it's prepared these two variables for the query. 00:09:08.660 --> 00:09:09.740 And also we're going to have 00:09:13.040 --> 00:09:15.170 to use the hash function. 00:09:15.320 --> 00:09:16.040 OK. 00:09:16.280 --> 00:09:16.610 So 00:09:25.010 --> 00:09:28.270 OK. 00:09:30.350 --> 00:09:36.020 Now we're going to create a query and then run it. 00:09:36.110 --> 00:09:37.670 OK. 00:09:38.240 --> 00:09:47.150 So the query is going to check if the combination of the e-mail and password provided exists in the 00:09:47.510 --> 00:09:48.540 Users table. 00:09:48.710 --> 00:09:53.260 OK so the query is going to be following. 00:09:53.260 --> 00:09:57.000 So we're going to create a variable as Q L. 00:09:57.250 --> 00:09:58.360 OK. 00:09:58.880 --> 00:10:04.060 So we get to select from our table. 00:10:05.230 --> 00:10:10.740 OK it uses we're going to select store. 00:10:11.120 --> 00:10:11.470 OK. 00:10:11.480 --> 00:10:14.780 So we can select all the records from the table where 00:10:21.240 --> 00:10:23.550 the following condition is fulfilled. 00:10:23.670 --> 00:10:24.560 OK. 00:10:24.570 --> 00:10:27.520 So using the parenthesis is optional. 00:10:27.540 --> 00:10:27.910 OK. 00:10:27.930 --> 00:10:30.980 So you can still have this without the princes. 00:10:31.020 --> 00:10:34.860 So the first promise is going to be e-mail. 00:10:35.170 --> 00:10:35.790 OK. 00:10:36.030 --> 00:10:42.610 Equals the provided e-mail and then 00:10:46.320 --> 00:10:50.460 the password equals the provided password 00:10:53.940 --> 00:10:56.160 or the hashed password. 00:10:57.810 --> 00:11:01.070 And we want the user to be activated. 00:11:01.080 --> 00:11:07.920 So we're going to check also the activation field that we're going to make sure that the user is activated 00:11:07.930 --> 00:11:08.230 . 00:11:08.520 --> 00:11:12.990 OK so the occupation fields should be activated like this. 00:11:13.290 --> 00:11:15.260 OK. 00:11:17.310 --> 00:11:22.710 Now let's run the query and I saw the results in the variable. 00:11:22.710 --> 00:11:23.860 We're going to call results. 00:11:24.000 --> 00:11:24.470 OK. 00:11:24.630 --> 00:11:31.920 Why is Kali and the so called query which is going to take this problem which is the link variable and 00:11:32.070 --> 00:11:33.350 the query tail. 00:11:33.770 --> 00:11:36.430 OK. 00:11:36.990 --> 00:11:38.680 Now to check if we have a match. 00:11:38.730 --> 00:11:44.580 We're going to need to look into our results objects and make sure as we of course only one row inside 00:11:44.640 --> 00:11:45.630 these objects. 00:11:45.630 --> 00:11:46.180 OK. 00:11:46.410 --> 00:11:54.350 So to do this we're going to check if the number of rows inside these objects is 1. 00:11:54.370 --> 00:11:56.990 So first let's create a variable. 00:11:57.020 --> 00:11:58.230 Are going to call count. 00:11:58.350 --> 00:12:02.080 Where are we going to store the outputs of the function. 00:12:02.130 --> 00:12:08.640 My is choli number of rows of objects. 00:12:08.640 --> 00:12:09.470 Result. 00:12:09.730 --> 00:12:10.430 OK. 00:12:11.160 --> 00:12:15.480 So if Count equals 1 00:12:23.880 --> 00:12:25.560 OK then 00:12:29.040 --> 00:12:33.710 we're going to lock our user and return a success message. 00:12:33.850 --> 00:12:35.020 OK. 00:12:35.730 --> 00:12:40.630 So first we need to fetch that through using the fetch array function. 00:12:40.680 --> 00:12:44.340 So this function has been covered in the BHB my Eskdale chapters. 00:12:44.610 --> 00:12:46.550 OK quite in detail. 00:12:46.740 --> 00:12:51.920 So let's create a variable that are going to call row. 00:12:51.990 --> 00:12:53.030 What are we going to store. 00:12:53.190 --> 00:12:54.430 That's a single row. 00:12:54.660 --> 00:12:58.520 So we're going to use the function my is choli fetch array. 00:12:58.960 --> 00:12:59.360 OK. 00:12:59.550 --> 00:13:05.970 So again this function takes a couple of parameters so the first one is going to be our results objects 00:13:06.990 --> 00:13:13.770 and the second one is an optional promiser which will specify how we would like our roads to be returned 00:13:13.770 --> 00:13:19.180 so we can have either an array or a numeric array or both. 00:13:19.290 --> 00:13:22.660 OK so I'm going to go for an array. 00:13:22.770 --> 00:13:31.650 So the problem is it is going to be my is choli and this core associative like this. 00:13:31.650 --> 00:13:36.420 All right then to look our user. 00:13:36.430 --> 00:13:41.820 We're going to set the session variables so we're going to store inside our session 00:13:46.410 --> 00:13:46.980 array. 00:13:47.100 --> 00:13:56.110 OK the values that we're going to find inside Bastro So we're going to start with the user id pay to 00:13:56.210 --> 00:14:06.540 know of a value for the user id which will correspond to the value corresponding to user ID inside the 00:14:06.630 --> 00:14:07.250 row. 00:14:07.540 --> 00:14:09.740 OK. 00:14:11.550 --> 00:14:14.910 And then we're going to have one for the username 00:14:20.640 --> 00:14:24.820 and another one for the e-mail. 00:14:27.750 --> 00:14:28.530 OK. 00:14:28.530 --> 00:14:31.060 So I went for all these because we're going to need them later. 00:14:31.140 --> 00:14:31.860 OK. 00:14:32.340 --> 00:14:37.560 Either for the profile page or for the main may be logged in page. 00:14:37.610 --> 00:14:45.360 OK so originally we wanted to press to brings an error if they don't mind so we can actually check if 00:14:45.360 --> 00:14:47.170 the count is different than one. 00:14:47.220 --> 00:14:47.850 OK. 00:14:47.880 --> 00:14:55.600 Then print an error and then have an else statements like this. 00:14:57.690 --> 00:15:06.390 OK so first this brings an error if there is the count is different than 1 so risk copying error message 00:15:06.390 --> 00:15:08.690 from the sign up code. 00:15:09.220 --> 00:15:12.340 OK let's get that's one. 00:15:13.170 --> 00:15:14.370 And let's say 00:15:17.700 --> 00:15:19.610 something like. 00:15:19.610 --> 00:15:25.150 Wrong username password. 00:15:26.660 --> 00:15:28.910 OK. 00:15:31.860 --> 00:15:39.860 Now we are going to check if the user has actually takes the Remember Me box. 00:15:39.930 --> 00:15:40.920 OK. 00:15:40.920 --> 00:15:45.780 So if they did that's OK then we're going to 00:15:51.930 --> 00:15:54.450 have some code. 00:15:54.750 --> 00:15:56.630 OK. 00:15:57.150 --> 00:15:59.940 Otherwise we are going to return success straightaway. 00:16:00.150 --> 00:16:12.660 So if they haven't checked that box which means that we don't have a Vost variable OK corresponding 00:16:12.660 --> 00:16:13.110 to 00:16:15.720 --> 00:16:18.080 remember me. 00:16:19.300 --> 00:16:25.980 I think that's if you remember the name of those inputs is memory. 00:16:26.190 --> 00:16:33.960 You can use the empty function instead of. 00:16:36.840 --> 00:16:42.030 So if that's empty we going to echo success straight away. 00:16:43.360 --> 00:16:43.760 OK. 00:16:43.800 --> 00:16:51.670 Otherwise we can have some code for the remainder of the process. 00:16:51.810 --> 00:16:53.390 OK. 00:16:53.400 --> 00:16:55.560 So so far we have done that one 00:16:59.820 --> 00:17:02.700 and you have done that one as well 00:17:02.700 --> 00:17:09.420 . 00:17:09.420 --> 00:17:11.360 Now let's have a quick look at our code. 00:17:11.520 --> 00:17:16.950 So of course a semi-colon missing from that statement. 00:17:17.070 --> 00:17:20.920 OK. 00:17:23.850 --> 00:17:25.950 Also if we look at the query. 00:17:25.950 --> 00:17:26.590 OK. 00:17:27.060 --> 00:17:36.870 That's from needs to be in capital letters and records and password and acceleration. 00:17:39.480 --> 00:17:46.440 Also right after running the query it is good proxies to make sure that the query has actually run successfully 00:17:46.440 --> 00:17:46.680 . 00:17:46.680 --> 00:17:54.110 So we're going to need to check if the query has run successfully as we did in the sign up file. 00:17:54.240 --> 00:17:56.070 OK. 00:17:56.070 --> 00:17:57.120 So to do this 00:18:03.690 --> 00:18:05.460 we can just copy this piece of code. 00:18:05.640 --> 00:18:05.970 OK 00:18:06.050 --> 00:18:13.650 . 00:18:13.650 --> 00:18:14.120 OK. 00:18:14.370 --> 00:18:22.250 So let's save and test our code now. 00:18:23.570 --> 00:18:26.150 Sorry if we send me an empty form. 00:18:27.600 --> 00:18:28.610 OK. 00:18:29.240 --> 00:18:32.590 We're only expecting the first two errors. 00:18:32.610 --> 00:18:38.470 We're not expecting this one so let's have a quick look at what's happening in the code. 00:18:38.700 --> 00:18:42.440 OK. 00:18:45.960 --> 00:18:47.470 So if there are any errors. 00:18:47.570 --> 00:18:48.190 OK. 00:18:48.270 --> 00:18:50.370 We print an error message. 00:18:50.370 --> 00:18:55.320 Else we prepare the variables for the query and then we run the query. 00:18:55.320 --> 00:19:06.930 So actually this curly bracket needs to be closed after running the query OK and doing all these checks 00:19:06.930 --> 00:19:10.910 so that needs to be closed right at the end. 00:19:11.180 --> 00:19:11.390 Here 00:19:14.910 --> 00:19:20.640 is save and refresh again. 00:19:23.110 --> 00:19:24.990 We're getting the right error messages. 00:19:25.060 --> 00:19:31.990 So now let's divide corrects details. 00:19:35.400 --> 00:19:38.070 OK he's working so he's looking mean. 00:19:38.200 --> 00:19:41.320 And I update redirected to the notes page. 00:19:41.400 --> 00:19:43.260 OK. 00:19:43.260 --> 00:19:46.860 So in the next video we're going to cover the Remember Me code