The question arose of designing the distribution of user roles having their own different data. I will give an example not concerning mine, but more simple.
There are such models: Декан , Преподаватель , Студент , Абитуриент . These models have their own characteristics (properties):
- Dean - in charge of the faculty, term of work, etc.
- The teacher - subject specialization, qualifications, etc.
- A student is a group, an average score, etc.
- Applicant - applications for admission, etc.
There will also be two models for the authentication system Пользователь , Роль and possibly права доступа (but as long as they are not needed)
- User - login data (username and password), token for Auth2.0, Role, etc.
- Role - the name of the role, permissions, etc.
public class Dean { public string Faculty { get; set; } public int Experience { get; set; } ... } public class Teacher { public string Specialization { get; set; } public string Qualification { get; set; } ... } public class Student { public string Group { get; set; } public double Average { get; set; } ... } public class Enrollee { public virtual ICollection<Bid> Bids { get; set; } ... } public class User { public string Email { get; set; } public string Password { get; set; } public virtual Role Role { get; set; } } public class Role { public string Name { get; set; } public virtual ICollection<User> Users { get; set; } public virtual ICollection<Permission> Permissions { get; set; } } According to the RBAC pattern, we need to have S (User) entities that have many R (Role) roles, Role has many P (Permission) access rights. But what about the models Dean, Lecturer, Student, Applicant?
At the moment, I see so far only solutions that I consider wrong:
- Assign the UserId field for each model, which connects the essence of each user with the authentication system (add, for example,
public int? UserId {get; set;}to Dean). - Instead of all models, use only one User, with all the fields of previous models (which is even worse)
How to implement such a system so that it is scaleable, followed and, most importantly, correct?