Exemplo n.º 1
0
        public ValidUserContext ValidateUser(string username, string password)
        {
            ValidUserContext userCtx = new ValidUserContext();
            User user = _userRepository.GetSingleByUsername(username);
            if (user != null && isUserValid(user, password))
            {
                IEnumerable<Role> userRoles = GetUserRoles(user.Id);
                userCtx.User = new UserWithRoles()
                {
                    User = user,
                    Roles = userRoles
                };

                GenericIdentity identity = new GenericIdentity(user.Name);
                userCtx.Principal = new GenericPrincipal(identity, userRoles.Select(x => x.Name).ToArray());
            }

            return userCtx;
        }
        public ValidUserContext ValidateUser(string username, string password)
        {
            ValidUserContext userCtx = new ValidUserContext();
            User             user    = _userRepository.GetSingleByUsername(username);

            if (user != null && isUserValid(user, password))
            {
                IEnumerable <Role> userRoles = GetUserRoles(user.Id);
                userCtx.User = new UserWithRoles()
                {
                    User  = user,
                    Roles = userRoles
                };

                GenericIdentity identity = new GenericIdentity(user.Name);
                userCtx.Principal = new GenericPrincipal(identity, userRoles.Select(x => x.Name).ToArray());
            }

            return(userCtx);
        }