Answer the question
In order to leave comments, you need to log in
How to design an authorization page in terms of the MVC pattern in PHP?
Hello!
Can you tell me how to design an authorization and registration page in terms of MVC?
I think that we need an object of the User class, which accepts a login password (and optionally a full name and email for registration) in the constructor.
You also need an AuthPage class that accepts this User, checks against the database and writes to cookies and session. In the case of a correct login password pair, it shows (through the View class) a personal account, if not, it shows an error. And the RegisterPage class that writes the User to the database?
Or am I writing nonsense at all, and no classes are needed and all this logic will be fine in index.php?
Answer the question
In order to leave comments, you need to log in
Or am I just writing nonsense
All this logic will be fine in index.php?
Controller LoginController
Model User
View with login form
MVC? Easily.
==== Login method ====
Entity - authorization sessions.
Login Attempt - Create an entry with validation rules. The validation rules check that the correct input is entered, the user is not locked out, the password matches, and so on.
In case of a successful login, set a cookie with a callback. The cookie contains a token, the key to which is stored in the session record in the database.
==== Session support ====
At each request, including AJAX, we read the authorization cookie. We are looking for a session, checking the key, session activity (expiration), user rights.
We can record in the user's properties that he is online.
We can write its properties (or at least an identifier) to the authorized user class.
==== Exit ====
If there are no cookies, do nothing, just redirect to the main page.
If there is a cookie, find the session and deactivate it. You can delete the cookie. It is possible not to delete if you are collecting a digital footprint - for example, you want to track multi-accounts, etc.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question