Beispiel #1
0
        public bool ValidateCredentials(string userName, string password, UserRoleKind roleRequred = UserRoleKind.Admin)
        {
            string      passwordHash = GetPasswordHashString(password);
            UserAccount userAccount  = _dbAuthController.GetUserAccount(userName, passwordHash);

            if (userAccount == null)
            {
                LogAuth(userName, roleRequred, false);
                return(false);
            }

            if (roleRequred != UserRoleKind.Unknown)
            {
                List <UserRoleKind> userRoles = _dbAuthController.GetUserRoles(userAccount.UserId);
                bool roleExists = userRoles.Contains(roleRequred);
                LogAuth(userName, roleRequred, roleExists);
                return(roleExists);
            }
            LogAuth(userName, roleRequred, true);
            return(true);
        }
Beispiel #2
0
        public UserDto GetUser(int userId)
        {
            User user = _dbUserController.GetUser(userId);

            if (user == null)
            {
                return(null);
            }
            List <Group> groups = _dbUserController.GetUserGroups(user.UserId);

            UserDto userDto = _userDtoConverter.Convert(user);

            userDto.Groups = _groupDtoConverter.Convert(groups);

            UserAccount userAccount = _dbAuthController.GetUserAccount(user.UserId);

            if (userAccount != null)
            {
                userDto.Account = _userAccountDtoConverter.Convert(userAccount);
            }

            return(userDto);
        }