Exemplo n.º 1
0
        /// <summary>
        /// Returns an IdentityUser given the user's id
        /// </summary>
        /// <param name="userId">The user's id</param>
        /// <returns></returns>
        public IdentityUser GetUserById(string userId)
        {
            IdentityUser user        = null;
            string       commandText = "Select * from Users where Id = @id";
            Dictionary <string, object> parameters = new Dictionary <string, object>()
            {
                { "@id", userId }
            };

            var rows = _database.Query(commandText, parameters);

            if (rows != null && rows.Count == 1)
            {
                var row = rows[0];
                user               = new IdentityUser();
                user.Id            = row["Id"];
                user.UserName      = row["UserName"];
                user.PasswordHash  = string.IsNullOrEmpty(row["PasswordHash"]) ? null : row["PasswordHash"];
                user.SecurityStamp = string.IsNullOrEmpty(row["SecurityStamp"]) ? null : row["SecurityStamp"];
            }

            return(user);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns a list of user's roles
        /// </summary>
        /// <param name="userId">The user's id</param>
        /// <returns></returns>
        public List <string> FindByUserId(string userId)
        {
            List <string> roles       = new List <string>();
            string        commandText = "Select Roles.Name from UserRoles, Roles where UserRoles.UserId = @userId and UserRoles.RoleId = Roles.Id";
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("@userId", userId);

            var rows = _database.Query(commandText, parameters);

            foreach (var row in rows)
            {
                roles.Add(row["Name"]);
            }

            return(roles);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns a list of user's logins
        /// </summary>
        /// <param name="userId">The user's id</param>
        /// <returns></returns>
        public List <UserLoginInfo> FindByUserId(string userId)
        {
            List <UserLoginInfo> logins            = new List <UserLoginInfo>();
            string commandText                     = "Select * from UserLogins where UserId = @userId";
            Dictionary <string, object> parameters = new Dictionary <string, object>()
            {
                { "@userId", userId }
            };

            var rows = _database.Query(commandText, parameters);

            foreach (var row in rows)
            {
                var login = new UserLoginInfo(row["LoginProvider"], row["ProviderKey"]);
                logins.Add(login);
            }

            return(logins);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns a ClaimsIdentity instance given a userId
        /// </summary>
        /// <param name="userId">The user's id</param>
        /// <returns></returns>
        public ClaimsIdentity FindByUserId(string userId)
        {
            ClaimsIdentity claims                  = new ClaimsIdentity();
            string         commandText             = "Select * from UserClaims where UserId = @userId";
            Dictionary <string, object> parameters = new Dictionary <string, object>()
            {
                { "@UserId", userId }
            };

            var rows = _database.Query(commandText, parameters);

            foreach (var row in rows)
            {
                Claim claim = new Claim(row["ClaimType"], row["ClaimValue"]);
                claims.AddClaim(claim);
            }

            return(claims);
        }