Previously we restricted access to the new article page to logged in users ballylee.
If we try and access to the page without being loved then we get this message.
We also want to restrict access to the edit and delete pages too as we don't want someone who isn't
logged in to be able to edit I'll delete an article.
Before we restrict access to other pages Let's add a method to the arfe class that makes it easier.
We don't want to be repeating this code in every page we want to restrict access to.
So let's add a new static method called require logging in and in here if the use it isn't logged in
will stop the script with the unauthorized message.
And let's add a p-h P duck comment to this function too.
Then in the new article script instead of this code we can call this new method like that.
And if we try and access that page when we're not logged in.
It restricts access as before.
So now any page that we want to restrict access to.
We can just add a Karl to this method at the top before we do that.
Now we've got some cold in the log in and log out scripts that should really be in the authentication
class.
More specifically this code where we're dealing with this session to lug the user in.
So let's copy these two lines.
And then in the art class we'll create another new method called luggin in here will paste the code
that we just copied from the log in script into the body of this method and add a comment block then
we can replace these two lines in the log in script with a call to the new method having all the cold
related to the session in here means that if we ever change the name of the elements we're storing in
the session from is logged into something else for example.
Then we only have to change it in this class.
Let's do the same for the log out script.
Will copy this code.
And then in the art class create a new method called log out and paste the code in there will add a
comment block.
And then in the logout script we can replace this code with a call to the new method.
Let's give that a try.
We can log in
and access the new article page and then log out successfully.
Now we just need to add one line of code to any page to require a user to be logged in before they can
access it.