Esempio n. 1
0
        /// <summary>
        /// Get the all Roles
        /// </summary>
        /// <returns>IdentityRole</returns>
        public IEnumerable <IdentityRole> GetRoles()
        {
            const string commandText = @"SELECT ID, NAME FROM ANID2ROLES";
            var          results     = _database.Query(commandText, null);

            return(results.Select(result => new IdentityRole
            {
                Id = string.IsNullOrEmpty(result["ID"]) ? null : result["ID"],
                Name = string.IsNullOrEmpty(result["NAME"]) ? null : result["NAME"],
            }).ToList());
        }
Esempio 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)
        {
            const string commandText = @"SELECT NAME FROM ANID2USERROLES, ANID2ROLES WHERE USERID = :USERID AND ANID2USERROLES.ROLEID = ANID2ROLES.ID";
            var          parameters  = new List <OracleParameter>
            {
                new OracleParameter {
                    ParameterName = "USERID", Value = userId, OracleDbType = OracleDbType.Varchar2
                }
            };

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

            return(rows.Select(row => row["NAME"]).ToList());
        }
        /// <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)
        {
            const string commandText = @"SELECT * FROM ANID2USERLOGINS WHERE USERID = :USERID";
            var          parameters  = new List <OracleParameter>
            {
                new OracleParameter {
                    ParameterName = "USERID", Value = userId, OracleDbType = OracleDbType.Varchar2
                },
            };

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

            return(rows.Select(row => new UserLoginInfo(row["LOGINPROVIDER"], row["PROVIDERKEY"])).ToList());
        }
Esempio n. 4
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;
            const string commandText = @"SELECT * FROM ANID2USERS WHERE ID = :USERID";
            var          parameters  = new List <OracleParameter>
            {
                new OracleParameter {
                    ParameterName = "USERID", Value = userId, OracleDbType = OracleDbType.Varchar2
                }
            };

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

            if (rows == null || rows.Count != 1)
            {
                return(null);
            }

            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");
            user.PhoneNumber          = string.IsNullOrEmpty(row["PHONENUMBER"]) ? null : row["PHONENUMBER"];
            user.PhoneNumberConfirmed = (row["PHONENUMBERCONFIRMED"] == "1");
            user.LockoutEnabled       = (row["LOCKOUTENABLED"] == "1");
            user.LockoutEndDateUtc    = string.IsNullOrEmpty(row["LOCKOUTENDDATEUTC"]) ? DateTime.Now : DateTime.Parse(row["LOCKOUTENDDATEUTC"]);
            user.AccessFailedCount    = string.IsNullOrEmpty(row["ACCESSFAILEDCOUNT"]) ? 0 : int.Parse(row["ACCESSFAILEDCOUNT"]);
            user.TwoFactorEnabled     = (row["TWOFACTORENABLED"] == "1");

            return(user);
        }
        /// <summary>
        /// Returns a ClaimsIdentity instance given a userId
        /// </summary>
        /// <param name="userId">The user's id</param>
        /// <returns></returns>
        public ClaimsIdentity FindByUserId(string userId)
        {
            var          claims      = new ClaimsIdentity();
            const string commandText = @"SELECT * FROM ANID2USERCLAIMS WHERE USERID = :USERID";
            var          parameters  = new List <OracleParameter>
            {
                new OracleParameter {
                    ParameterName = "USERID", Value = userId, OracleDbType = OracleDbType.Varchar2
                },
            };

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

            foreach (var claim in rows.Select(row => new Claim(row["CLAIMTYPE"], row["CLAIMVALUE"])))
            {
                claims.AddClaim(claim);
            }

            return(claims);
        }