Hi everyone welcome back.
So in this video we're going to do the final class which is to refill class.
So let's get started.
So the last feature we have here is a refill which basically allows the admin to refill for any user
whatever amount of refills that he would like it.
So we're going to write the class glass refill.
OK.
And then we're going to inherit from resource.
And as we discuss it's also a post so as you can see here it's a post.
So we to post and then self.
OK so the first thing is as usual we want to get the posted data.
We do posted data is equal to and then we want to get the user name and the password.
OK.
So we want to get a couple of things actually we want to get the user name.
You want to get the admin password and we want to get the full amount.
So when I get posted so that's OK.
So the Post day that is the request that we get Jason.
OK.
So this should be done to get Gs on and then username is equal to posted data and then username and
then we have the admin password so password is equal to posting data.
And then we're going to access it at admen underscore piñon.
Great.
So it's a hidden field with not just password.
OK.
Then the last thing is refill amounts a refill is equal to the posted data.
Or let's say a refill amount.
Is equal to posted data and then refill.
OK.
So hopefully this meets us so we we are basically getting the user and the admin and refill amount from
the posted to you that we've got at this you are out now.
The next thing we want to do is we want to check for a three or one and 3 or.
If you see here we have three old ones and three or four three and one is invalid use your name and
three or four is invalid admin password.
OK.
So let's go back.
So the first thing is how do we check for three or one and we've already done it before.
So you're right.
If not use or exist if this user doesn't exist with this username then we're going to return return
Jason is equal to status 2 0 1 3 0 1.
And the message I want to tell him something for example invalid Youzhny so sorry invalid.
And then I'm just going to return on if I have returned Jason or the return map.
OK so that's for the three to one year.
Now what about the checking for the password right.
So you want to make sure that the correct admin password is is the same.
Now there are many ways you can do this we can also use hashing just like we use for the regular or
the regular username password but for the sake we're just going a hard chordates are we going to see
the correct password is equal to.
I don't know.
ABC 1 2 3 this is not the best practice.
It's always better not to store any passwords in this app you file but instead store it in the database
securely.
But for now we can just hardcoded because we already know how to hash the function so there's no point
in just making this longer.
So for now we're just going to go with it but you should know that you should nost or any passwords
inside this app QIC you should actually just store it in the database and always access the hashed version
off it.
So you should store the hash version of your correct password in the administrator for example and you
make a new collection called Administration admin and then you would store the user name and the correct
passwords here.
OK.
But for now we're just going to store the correct answer and then we're going to say if not password.
So if the password that that it was signed that was sent is not equal to the correct password that in
that case we want to tell the the the sender three or four sorry you sent an invalid admin password.
OK.
So I'm going to say return Jaisalmer is equal to status is three or four.
And the message is let's say Invalid admin passwords so invalid admin password.
Great and just return Jaison if I attorneys get.
So really this wasn't too hard now once we have we have this sorry excuse me.
So once we have this then we need to update the user to give him the new refill amounts.
OK.
So first thing we're going to do is we're going to see tokens.
Right.
Our current tokens is equal to you.
And then we're going to say count tokens use the function that we wrote and then for this username and
then we're going to say users update.
So I'm going to update is this user OK.
Yes.
OK.
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
hems and when I set.
Right so I'm going to do another Giese in here for what I want to set of dollars.
Then inside here I'm going to write tokens.
I want to update his organs so that they are refill amount plus current tokens right.
So I want to refill them for example hundred.
And if he already has like five then I want him to have 105.
OK.
So that should be it to do it.
The number of tokens.
And then finally I want to prepare the theater and Jason to Dohme success or return James on to his
status is 200 hundred and for the message is going to be.
For example Rayfield successfully.
So Greifeld this successfully.
And then just returned G-ds on return.
Jason ephi eternity's
Imp's So we have now finished writing all of these
functions and classes just a couple of things so for now I'm just going to remove this current tokens
are not going to add screen tokens.
So I'm going to make it overload the number of tokens that I have.
So for example if the user has five and he refills them he loses these five.
You only guess the new one.
OK.
You can you can leave it if you want but I just prefer you to leave it that way.
OK.
Now a couple of things that we have to do is to add a couple of things so AP to add resource we need
to add all the resources that we wrote so add resource and then we want to add the register class at
slash register.
If you remember we have here the chart slash register slash the text slash ratio.
OK.
So we're going to add the register to slash register.
We're going to add the resource on detect to slash detect.
And I'm going to add the resource ratio OK to slash refill.
Ok now I'm going to run the applications I want to see if name is equal to main.
Right as we always do then the run host is equal to.
Don't forget this one is very important.
Zero point zero zero point zero OK.
So this is the house where we're going to run everything on and that should be it for the API in general
so we've written an API which measures the similarity of two codes using hundred seventy five lines
of code with lots of empty lines in the middle.
But we can actually make this you know a lot you know very very small.
And the reason is that if you notice you're We always have this returned Jason equal to we generate
this return to the center of that range and then just 25 it will actually we can call this as a function
right.
So we can actually make this as a function and then we just pass it the status quo.
And the message and then it generates all of this.
But for now we're just going to leave it in the most intuitive way.
It doesn't have to be you know production line ready.
Definitely not production line ready but at least for now we know that it works.
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
detection refill see if there's any problems.
And so we're going to stop here and I'm going to see you in the next video.
So until a nice video happy Cody.