public bool LogIn(string email, string password, UserRole userRole)
        {
            try
            {
                string passwordHash;
                User   user;
                switch (userRole)
                {
                case UserRole.Student:
                    user         = _studentRepository.ReadStudentByEmail(email);
                    passwordHash = user?.PasswordHash;
                    break;

                case UserRole.Lecturer:
                    user         = _lecturerRepository.ReadLecturerByEmail(email);
                    passwordHash = user?.PasswordHash;
                    break;

                case UserRole.Administrator:
                    user         = _administratorRepository.ReadAdministratorByEmail(email);
                    passwordHash = user?.PasswordHash;
                    break;

                default: return(false);
                }

                var status = !string.IsNullOrEmpty(passwordHash) &&
                             _hashService.ValidatePassword(password, passwordHash);

                if (status)
                {
                    SetUserInSession(new User
                    {
                        Id        = user.Id, Email = user.Email, UserRole = user.UserRole,
                        FirstName = user.FirstName, LastName = user.LastName, PasswordHash = user.PasswordHash
                    });
                }
                return(status);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
예제 #2
0
 public Lecturer ReadLecturerByEmail(string email)
 {
     try
     {
         return(_lecturerRepository.ReadLecturerByEmail(email));
     }
     catch (Exception e)
     {
         return(null);
     }
 }