WEBVTT

00:05.150 --> 00:06.650
Hi everyone welcome back.

00:06.900 --> 00:12.150
So in the previous video we saw that we did the whole structure for the project and now we're going

00:12.150 --> 00:14.410
to re-implementing the after P1.

00:14.460 --> 00:15.200
OK.

00:15.420 --> 00:20.520
So the first thing is as usual we run out of important some of the important libraries and functions

00:20.580 --> 00:23.740
and variables right from other modules.

00:23.910 --> 00:29.130
So first of all read on our imports from class import the flask constructor.

00:29.130 --> 00:31.040
We're also going to import J-Zone F-5s.

00:31.180 --> 00:32.070
We use a lot.

00:32.100 --> 00:37.160
When we return sounds into the user in Jason format and we're also going to import request.

00:37.200 --> 00:37.750
OK.

00:37.980 --> 00:41.260
Now if you notice you're this is a request without an ass.

00:41.280 --> 00:44.450
The other libraries Call requests with an ass.

00:44.460 --> 00:45.050
OK.

00:45.120 --> 00:48.380
So just be careful that these two are not the same things they're different.

00:48.390 --> 00:50.850
And many people actually confuse the two.

00:50.850 --> 00:51.830
OK.

00:52.380 --> 00:53.000
All right.

00:53.070 --> 00:58.540
Now the second thing is we want flask restful so affronts us we're asked for we're going to import API.

00:58.590 --> 00:58.860
Right.

00:58.860 --> 01:04.620
So we want the API constructor and we also want to import resource which we inherit from.

01:06.370 --> 01:13.370
The third thing we want to import is by Mungo's so from the by Mongo books by Mongo we want to import

01:14.040 --> 01:19.410
the Mongo client that we use to connect to the Mongo D-B using the daquiri network.

01:19.410 --> 01:19.790
OK.

01:19.810 --> 01:21.460
Dr. componentry.

01:21.720 --> 01:25.350
Now we also want to hash passwords so we're going to import it.

01:25.710 --> 01:32.160
And then we're going to employ it secret right because that's what we used to do have the password and

01:32.160 --> 01:37.560
then we're going to import this time we're going to important not buy import or actually let's just

01:37.560 --> 01:39.090
leave it as as it is now.

01:39.100 --> 01:42.250
OK so we will not import an Alpine denser flow.

01:42.390 --> 01:43.530
We're going to leave that out.

01:43.560 --> 01:45.980
We're going to see why are we going to leave it later.

01:46.230 --> 01:51.870
And then we're also going to import requests so we send requests with an S is going to be used to get

01:51.870 --> 01:54.760
the image from the or else that they use are sent.

01:54.840 --> 01:55.630
OK.

01:55.860 --> 01:58.970
And then we're also going to import subprocess.

01:58.980 --> 02:03.390
And when I explain why we're going to import this one in there in the future of India.

02:03.510 --> 02:05.790
And we're also going to import it Jason.

02:06.150 --> 02:06.560
So we are.

02:06.570 --> 02:11.710
But I also want to Jason what you on this side you don't need to download it is already in Python.

02:11.730 --> 02:12.130
OK.

02:12.150 --> 02:14.020
So there's this.

02:14.130 --> 02:15.200
All right.

02:15.240 --> 02:21.480
So you don't need to download it or install or anything so it's already in but or I said the first thing

02:21.480 --> 02:27.480
we do is we do an app is equal to flask and then underscore in a square name underscore it underscored

02:27.610 --> 02:28.250
or right.

02:28.320 --> 02:35.590
So we initialize the flask with the name main and then we do Abiah as you go to API constructor.

02:35.700 --> 02:38.280
So we initialize a new API.

02:38.730 --> 02:40.210
Next we do client.

02:40.440 --> 02:47.570
So we want to connect to the maladie So we do client you go to mung the client and then inside we're

02:47.570 --> 02:56.290
going to say Mongo D.B and then semi-colon slash slash and then D-B to 7 0 1 7.

02:56.360 --> 03:02.090
So that means we're connecting to the Mangione be and it's located at D-B right from the dock Nagar

03:02.100 --> 03:10.080
compose your D.B and you're also connecting to the portal default for default port of Mungo D-B which

03:10.080 --> 03:11.530
is 2 7 0 1 0.

03:11.610 --> 03:12.850
OK.

03:12.990 --> 03:16.130
Now after if connected to landlines we want to do a new database.

03:16.140 --> 03:20.720
I want to say D-B is equal to client dot image.

03:20.760 --> 03:25.610
So we're going to do a new database called Image recognition.

03:25.980 --> 03:26.610
OK.

03:26.820 --> 03:30.360
And then I'm going to say users is equal to D-B.

03:30.390 --> 03:35.260
And then when I do a new collection inside the database called users right.

03:35.820 --> 03:38.390
All right so we're now finished.

03:38.430 --> 03:39.360
The main point.

03:39.360 --> 03:39.880
OK.

03:39.930 --> 03:41.680
So now we want to register it.

03:41.690 --> 03:44.590
So do a class and then register.

03:44.980 --> 03:45.730
All right.

03:46.050 --> 03:49.080
And then you're going to inherit from resource.

03:49.080 --> 03:49.750
All right.

03:49.890 --> 03:54.240
And we said that this is going to be a post right if you remember from here we said all of them are

03:54.240 --> 03:55.460
going to be published.

03:55.530 --> 03:56.190
Right.

03:56.460 --> 04:01.270
So we're going to come back here and then we're going to write a defined post self.

04:01.280 --> 04:02.290
All right.

04:02.340 --> 04:04.670
And then inside post we want to get.

04:04.670 --> 04:06.650
First of all we always get to post the data.

04:06.660 --> 04:12.720
So we say post a day that is equal to your request diet get your score.

04:12.830 --> 04:13.640
Jason.

04:13.740 --> 04:14.290
OK.

04:14.430 --> 04:20.370
So you get the J on file at the post and then we get the user name and the password so say a user name

04:20.400 --> 04:24.000
is equal to the today the user name.

04:24.060 --> 04:31.840
OK so the users use your name and also the passwords so your password is equal to posted data and then

04:31.840 --> 04:32.850
password.

04:33.070 --> 04:34.620
Right.

04:35.540 --> 04:38.030
All right so we have the user name and the password.

04:38.100 --> 04:40.980
Well the first thing we did is for the error.

04:41.280 --> 04:46.920
Well as you might have guessed 3:01 that hey there's a way to use it with this using the existing.

04:46.920 --> 04:48.120
So choose another one.

04:48.240 --> 04:51.660
So I want to say if user exists.

04:52.040 --> 04:54.450
So when I write a helper function later on.

04:54.450 --> 04:58.570
So if you use your existing username then what do I do.

04:58.620 --> 05:08.000
Well I want to say you returned Jason is equal to status is three I want two hours in the air and then

05:08.000 --> 05:13.580
a message is invalid usually dates are invalid username.

05:13.770 --> 05:14.600
OK.

05:14.830 --> 05:18.710
And I just returned just on a fly off this return Jason.

05:19.160 --> 05:22.550
So are you going to return the Jaysh on if I ever return.

05:22.640 --> 05:23.630
OK.

05:24.230 --> 05:26.720
Now what happens if this is not the case.

05:26.720 --> 05:29.450
Well we need to now have the password right.

05:29.570 --> 05:34.840
So we're going to say hashed password this is standard is equal to me script.

05:34.840 --> 05:37.990
And then I call the crib hash password function.

05:38.180 --> 05:40.390
And then inside when I write the password.

05:40.460 --> 05:43.320
But I'm going to encode it as UTF 8.

05:43.450 --> 05:45.220
And don't forget about that one.

05:45.230 --> 05:48.670
Or else you're going to it's not going to work.

05:48.860 --> 05:57.240
So you could add two UTF 8 and then you generate assaults on Gaza a be grouped generate salt.

05:57.260 --> 05:57.790
OK.

05:57.920 --> 06:02.010
So generate salt and that's called off.

06:02.090 --> 06:02.630
All right.

06:02.690 --> 06:04.440
So now we have a hashed password.

06:04.460 --> 06:05.240
OK.

06:05.540 --> 06:12.330
Now the next thing is we're going to store the user and the password into our entire database.

06:12.330 --> 06:14.960
I mean I say users got.

06:15.290 --> 06:16.030
OK.

06:16.050 --> 06:21.400
And then and then I inserted the user name as opposed to a user name.

06:21.410 --> 06:23.540
Now we verified it doesn't exist.

06:23.870 --> 06:28.870
I'm also going to do the password password and then.

06:28.940 --> 06:31.520
So let's do that with a capital P.

06:31.820 --> 06:37.810
So the password is going to mean the posted password that the user or hashed password actually not that

06:37.820 --> 06:39.780
posted you know forgot about that.

06:39.890 --> 06:43.760
So the hashed password not the plain password.

06:43.760 --> 06:50.770
So you don't end up like most of these companies and then tokens is going to I'm going to give the user

06:50.770 --> 06:52.240
just a few tokens in the store.

06:52.250 --> 06:54.420
So I'm going to give them like five tokens right.

06:54.440 --> 06:56.740
Or for say for tokens.

06:56.980 --> 06:57.380
All right.

06:57.410 --> 06:58.300
That should be enough.

06:58.310 --> 07:01.100
And then if you want to you can refill later.

07:01.550 --> 07:06.610
OK so once I've generated this user now I want to return a rope line.

07:06.710 --> 07:11.560
So I want to say return Jason is equal to status is 200.

07:11.780 --> 07:18.210
And the message is let's say you know you successfully signed up for this guy.

07:18.220 --> 07:23.050
OK so you're successful they signed up for this.

07:23.450 --> 07:24.060
OK.

07:24.500 --> 07:25.250
All right.

07:25.460 --> 07:27.840
And then once we are done that we just return.

07:27.840 --> 07:32.150
Jason if I return Jason and that should be you.

07:32.180 --> 07:34.410
We shouldn't have anything other than that.

07:34.710 --> 07:40.490
But see we already used the user as this option but we didn't write it so we need to go back and rewrite

07:40.610 --> 07:42.280
the user exists.

07:42.650 --> 07:48.080
So I'm going to come here before the register class and then let's see if I can move it here.

07:48.150 --> 07:51.620
Right then I'm going to write define user exist.

07:51.710 --> 07:56.570
Ok so I'm going to write this user in this function and that is going to take the user name and is going

07:56.570 --> 08:00.650
to tell me this from this user exists in the database or not.

08:00.780 --> 08:02.290
So I'm going to say this.

08:02.510 --> 08:07.540
So if that's so a little bit of inundations yours here too.

08:07.590 --> 08:13.740
If users got signed then I want to find the user name with this user.

08:14.150 --> 08:22.810
So a user name is you try to find some documents with this username that count is equal to zero.

08:22.940 --> 08:24.770
Then I'm going to return false.

08:24.770 --> 08:25.310
Why.

08:25.310 --> 08:30.830
Because this user this user name does not exist in my collection right.

08:30.830 --> 08:34.080
There's no user of this username so I'm allowing him to.

08:34.130 --> 08:37.510
So this user does not exist to answer this question.

08:37.610 --> 08:40.060
User exists with this user name.

08:40.100 --> 08:42.410
No because the count is zero.

08:42.530 --> 08:43.220
OK.

08:43.520 --> 08:47.440
Else if he does exist that count is greater than zero.

08:47.510 --> 08:53.230
So if his account is one for example then that means that the user does exists or return true.

08:53.300 --> 08:53.830
OK.

08:53.900 --> 09:00.100
So very simple on just checking the user with this user name exists then return false otherwise.

09:00.120 --> 09:06.750
Which is true and that should be it for for the registration with just did it in a couple of lines if

09:06.890 --> 09:07.620
it's OK.

09:07.730 --> 09:10.950
So hopefully this is not too hard to see.

09:11.360 --> 09:19.340
So the next thing we want to do is to implement the classify function but we're going to stop here and

09:19.340 --> 09:23.840
we're going to take it from the next video and we're going to start with the classification and the

09:23.840 --> 09:24.380
refilling.

09:24.410 --> 09:24.950
OK.

09:25.010 --> 09:27.320
So the next that is going to be quite long.

09:27.470 --> 09:28.150
All right.

09:28.280 --> 09:32.310
So we're going to stop here and we're going to wake up in the next few years until the next video.

09:32.330 --> 09:32.890
Happy the.
