Answer the question
In order to leave comments, you need to log in
What is correct to put in a separate class for the web?
Hello. I'm doing a training project in php (experience - about a year) and for the 2nd time I'm changing its architecture. The thing is that I can’t fully comprehend which parts, in this case, the server part of the site should be taken out in a separate class? Let's say I have 2 types of users on my project: administrators and ordinary users, as well as a bulletin board. Initially, I made a user class for all users, which was responsible for both registration and authorization. In general, for everything the user belongs to (except for the database and classes with lots). And so I scratched my head and thought that an authorized user needs its own class, for registration - the same as for methods for checking the validity of data during registration, for example.
In general, I would like to learn to feel and understand what really needs to be moved to a separate class, and what can be left as methods in some class, making it bigger.
Thanks in advance!
Answer the question
In order to leave comments, you need to log in
Rasmusen505 ,
Registration, authorization are processes, the user is an entity.
A process can affect many entities, an entity can participate in many processes.
In the case of authorization, many classes can be involved in the process:
- Classes of forms of representations (View), which draw the forms themselves and bind the parameters of the form model into them.
- Classes of models of registration/authentication forms, which can also validate the form.
- The UserIdentity class that implements the IIdentity interface responsible for user authentication.
- The user class, which often implements the IIdentity interface.
- Controller classes that handle requests and sit between the view and the models, eg. This is if we are talking about the MVP architecture.
User registration is a process in which many classes can participate and it does approximately the following:
1) Gets information about registration data from the user (View class and form model class)
2) Validates user data when sending a registration request (Controller receives from the view (View) information, creates a model (class) User and saves)
3) If there is already such a user in the database (checking at the model / DBMS level for the uniqueness of certain fields), then the controller from the model translates errors into the form class and the user corrects them .
4) If everything is OK, then the user is given a message about successful registration (response from the controller) and the controller sends a link to confirm registration by email (here the token is saved tied to the entry in the user table, it is needed to generate a link to confirm registration, then it is searched for the right user to activate it).
5) Next, another controller or another method of the same controller processes the link and sets a flag through the user model that the registration is confirmed.
I think you are confusing the registration class with the registration form model.
Then the confusion in terminology and the train of thought is correct.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question