Ejemplo n.º 1
0
        /// <summary>
        /// Returns an TUser given the user's id
        /// </summary>
        /// <param name="userId">The user's id</param>
        /// <returns></returns>
        public TUser GetUserById(string userId)
        {
            TUser  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                      = (TUser)Activator.CreateInstance(typeof(TUser));
                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"];
                user.Email                = string.IsNullOrEmpty(row["Email"]) ? null : row["Email"];
                user.EmailConfirmed       = row["EmailConfirmed"] == "1" ? true : false;
                user.PhoneNumber          = string.IsNullOrEmpty(row["PhoneNumber"]) ? null : row["PhoneNumber"];
                user.PhoneNumberConfirmed = row["PhoneNumberConfirmed"] == "1" ? true : false;
                user.LockoutEnabled       = row["LockoutEnabled"] == "1" ? true : false;
                user.LockoutEndDateUtc    = string.IsNullOrEmpty(row["LockoutEndDateUtc"]) ? DateTime.Now : DateTime.Parse(row["LockoutEndDateUtc"]);
                user.AccessFailedCount    = string.IsNullOrEmpty(row["AccessFailedCount"]) ? 0 : int.Parse(row["AccessFailedCount"]);
            }

            return(user);
        }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo 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);
        }