WEBVTT

00:05.200 --> 00:07.010
Hi everyone welcome back.

00:07.010 --> 00:11.380
So in this video we're going to do the final class which is to refill class.

00:11.390 --> 00:12.650
So let's get started.

00:12.890 --> 00:19.570
So the last feature we have here is a refill which basically allows the admin to refill for any user

00:19.790 --> 00:23.730
whatever amount of refills that he would like it.

00:23.780 --> 00:26.760
So we're going to write the class glass refill.

00:26.940 --> 00:27.330
OK.

00:27.330 --> 00:29.810
And then we're going to inherit from resource.

00:30.650 --> 00:35.450
And as we discuss it's also a post so as you can see here it's a post.

00:35.840 --> 00:40.690
So we to post and then self.

00:40.880 --> 00:45.120
OK so the first thing is as usual we want to get the posted data.

00:45.270 --> 00:52.670
We do posted data is equal to and then we want to get the user name and the password.

00:52.710 --> 00:53.200
OK.

00:53.310 --> 00:56.900
So we want to get a couple of things actually we want to get the user name.

00:57.020 --> 01:01.110
You want to get the admin password and we want to get the full amount.

01:01.440 --> 01:05.360
So when I get posted so that's OK.

01:05.400 --> 01:10.340
So the Post day that is the request that we get Jason.

01:10.590 --> 01:11.600
OK.

01:12.230 --> 01:26.240
So this should be done to get Gs on and then username is equal to posted data and then username and

01:26.310 --> 01:31.390
then we have the admin password so password is equal to posting data.

01:32.010 --> 01:35.650
And then we're going to access it at admen underscore piñon.

01:35.710 --> 01:36.320
Great.

01:36.570 --> 01:40.770
So it's a hidden field with not just password.

01:41.120 --> 01:41.890
OK.

01:42.090 --> 01:49.190
Then the last thing is refill amounts a refill is equal to the posted data.

01:49.560 --> 01:51.380
Or let's say a refill amount.

01:52.540 --> 01:56.860
Is equal to posted data and then refill.

01:56.930 --> 01:57.730
OK.

01:58.180 --> 02:03.730
So hopefully this meets us so we we are basically getting the user and the admin and refill amount from

02:03.730 --> 02:09.410
the posted to you that we've got at this you are out now.

02:09.520 --> 02:13.400
The next thing we want to do is we want to check for a three or one and 3 or.

02:13.440 --> 02:19.330
If you see here we have three old ones and three or four three and one is invalid use your name and

02:19.330 --> 02:21.930
three or four is invalid admin password.

02:21.970 --> 02:23.000
OK.

02:23.290 --> 02:24.570
So let's go back.

02:24.850 --> 02:29.390
So the first thing is how do we check for three or one and we've already done it before.

02:29.390 --> 02:29.870
So you're right.

02:29.890 --> 02:37.840
If not use or exist if this user doesn't exist with this username then we're going to return return

02:37.840 --> 02:42.850
Jason is equal to status 2 0 1 3 0 1.

02:43.060 --> 02:50.120
And the message I want to tell him something for example invalid Youzhny so sorry invalid.

02:50.860 --> 02:59.250
And then I'm just going to return on if I have returned Jason or the return map.

02:59.470 --> 03:02.530
OK so that's for the three to one year.

03:02.680 --> 03:06.350
Now what about the checking for the password right.

03:06.370 --> 03:11.750
So you want to make sure that the correct admin password is is the same.

03:11.800 --> 03:17.800
Now there are many ways you can do this we can also use hashing just like we use for the regular or

03:17.800 --> 03:22.470
the regular username password but for the sake we're just going a hard chordates are we going to see

03:22.470 --> 03:25.510
the correct password is equal to.

03:25.680 --> 03:26.180
I don't know.

03:26.230 --> 03:29.540
ABC 1 2 3 this is not the best practice.

03:29.550 --> 03:36.280
It's always better not to store any passwords in this app you file but instead store it in the database

03:36.280 --> 03:37.280
securely.

03:37.510 --> 03:42.790
But for now we can just hardcoded because we already know how to hash the function so there's no point

03:42.790 --> 03:44.530
in just making this longer.

03:44.530 --> 03:49.600
So for now we're just going to go with it but you should know that you should nost or any passwords

03:50.200 --> 03:57.160
inside this app QIC you should actually just store it in the database and always access the hashed version

03:57.160 --> 03:57.960
off it.

03:58.000 --> 04:03.850
So you should store the hash version of your correct password in the administrator for example and you

04:03.850 --> 04:09.490
make a new collection called Administration admin and then you would store the user name and the correct

04:09.520 --> 04:10.350
passwords here.

04:10.390 --> 04:11.030
OK.

04:11.170 --> 04:18.340
But for now we're just going to store the correct answer and then we're going to say if not password.

04:18.370 --> 04:25.420
So if the password that that it was signed that was sent is not equal to the correct password that in

04:25.420 --> 04:34.210
that case we want to tell the the the sender three or four sorry you sent an invalid admin password.

04:34.220 --> 04:34.840
OK.

04:35.060 --> 04:41.510
So I'm going to say return Jaisalmer is equal to status is three or four.

04:41.680 --> 04:49.690
And the message is let's say Invalid admin passwords so invalid admin password.

04:49.740 --> 04:57.390
Great and just return Jaison if I attorneys get.

04:57.740 --> 05:05.610
So really this wasn't too hard now once we have we have this sorry excuse me.

05:05.800 --> 05:12.100
So once we have this then we need to update the user to give him the new refill amounts.

05:12.100 --> 05:12.700
OK.

05:12.880 --> 05:17.200
So first thing we're going to do is we're going to see tokens.

05:17.390 --> 05:18.090
Right.

05:18.520 --> 05:23.190
Our current tokens is equal to you.

05:23.500 --> 05:30.730
And then we're going to say count tokens use the function that we wrote and then for this username and

05:30.730 --> 05:34.280
then we're going to say users update.

05:34.430 --> 05:38.660
So I'm going to update is this user OK.

05:39.540 --> 05:40.910
Yes.

05:41.210 --> 05:41.810
OK.

05:41.960 --> 05:49.630
So first of all I want to search for the user name as the one I have and for what I'm going to update

05:49.630 --> 05:51.730
hems and when I set.

05:51.760 --> 05:59.580
Right so I'm going to do another Giese in here for what I want to set of dollars.

06:00.210 --> 06:04.070
Then inside here I'm going to write tokens.

06:04.220 --> 06:11.870
I want to update his organs so that they are refill amount plus current tokens right.

06:11.900 --> 06:14.220
So I want to refill them for example hundred.

06:14.270 --> 06:17.930
And if he already has like five then I want him to have 105.

06:17.960 --> 06:18.660
OK.

06:20.620 --> 06:22.700
So that should be it to do it.

06:22.710 --> 06:23.990
The number of tokens.

06:24.100 --> 06:30.160
And then finally I want to prepare the theater and Jason to Dohme success or return James on to his

06:30.820 --> 06:37.630
status is 200 hundred and for the message is going to be.

06:37.630 --> 06:42.120
For example Rayfield successfully.

06:42.540 --> 06:45.040
So Greifeld this successfully.

06:45.260 --> 06:48.300
And then just returned G-ds on return.

06:48.310 --> 06:50.400
Jason ephi eternity's

06:53.660 --> 06:59.290
Imp's So we have now finished writing all of these

07:02.800 --> 07:09.480
functions and classes just a couple of things so for now I'm just going to remove this current tokens

07:09.480 --> 07:11.560
are not going to add screen tokens.

07:11.740 --> 07:15.910
So I'm going to make it overload the number of tokens that I have.

07:15.910 --> 07:20.770
So for example if the user has five and he refills them he loses these five.

07:20.770 --> 07:22.100
You only guess the new one.

07:22.150 --> 07:23.290
OK.

07:23.620 --> 07:27.720
You can you can leave it if you want but I just prefer you to leave it that way.

07:27.760 --> 07:28.580
OK.

07:29.050 --> 07:34.930
Now a couple of things that we have to do is to add a couple of things so AP to add resource we need

07:34.930 --> 07:42.940
to add all the resources that we wrote so add resource and then we want to add the register class at

07:43.870 --> 07:45.070
slash register.

07:45.070 --> 07:51.650
If you remember we have here the chart slash register slash the text slash ratio.

07:51.760 --> 07:52.330
OK.

07:52.660 --> 07:55.480
So we're going to add the register to slash register.

07:55.690 --> 08:04.670
We're going to add the resource on detect to slash detect.

08:05.470 --> 08:17.640
And I'm going to add the resource ratio OK to slash refill.

08:18.250 --> 08:27.710
Ok now I'm going to run the applications I want to see if name is equal to main.

08:28.110 --> 08:34.770
Right as we always do then the run host is equal to.

08:34.770 --> 08:37.070
Don't forget this one is very important.

08:37.090 --> 08:39.360
Zero point zero zero point zero OK.

08:39.600 --> 08:47.210
So this is the house where we're going to run everything on and that should be it for the API in general

08:47.210 --> 08:54.560
so we've written an API which measures the similarity of two codes using hundred seventy five lines

08:54.560 --> 08:58.260
of code with lots of empty lines in the middle.

08:58.490 --> 09:05.110
But we can actually make this you know a lot you know very very small.

09:05.210 --> 09:11.080
And the reason is that if you notice you're We always have this returned Jason equal to we generate

09:11.090 --> 09:16.880
this return to the center of that range and then just 25 it will actually we can call this as a function

09:16.880 --> 09:17.350
right.

09:17.510 --> 09:22.750
So we can actually make this as a function and then we just pass it the status quo.

09:22.820 --> 09:25.990
And the message and then it generates all of this.

09:26.090 --> 09:29.430
But for now we're just going to leave it in the most intuitive way.

09:29.470 --> 09:32.370
It doesn't have to be you know production line ready.

09:32.390 --> 09:37.220
Definitely not production line ready but at least for now we know that it works.

09:37.460 --> 09:43.100
And in the next video we're going to see how we can test it and just take it on a run try the registration

09:43.100 --> 09:46.380
detection refill see if there's any problems.

09:46.380 --> 09:50.970
And so we're going to stop here and I'm going to see you in the next video.

09:50.980 --> 09:53.000
So until a nice video happy Cody.
