Exemplo n.º 1
0
        /// <summary>
        /// Inserts a new role for a user in the UserRoles table
        /// </summary>
        /// <param name="user">The User</param>
        /// <param name="roleId">The Role's id</param>
        /// <returns></returns>
        public int Insert(IdentityUser user, string roleId)
        {
            const string commandText = "[Security].[UserRoleInsert]";
            var parameters = new Dictionary<string, object>
            {
                {"@userId", user.Id},
                {"@roleId", roleId}
            };

            return _connection.Execute(commandText, parameters, null, null, CommandType.StoredProcedure);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Inserts a new login in the UserLogins table
        /// </summary>
        /// <param name="user">User to have new login added</param>
        /// <param name="login">Login to be added</param>
        /// <returns></returns>
        public int Insert(IdentityUser user, UserLoginInfo login)
        {
            const string commandText = "[Security].[UserLoginInsert]";
            var parameters = new Dictionary<string, object>
            {
                {"@userId", user.Id},
                {"@loginProvider", login.LoginProvider},
                {"@providerKey", login.ProviderKey}
            };

            return _connection.Execute(commandText, parameters, null, null, CommandType.StoredProcedure);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates new user in the database
        /// </summary>
        public async Task<IdentityResult> RegisterUser(UserModel userModel)
        {
            var user = new IdentityUser
            {
                UserName = userModel.UserName
            };

            var result = await _userManager.CreateAsync(user, userModel.Password);

            //add additional claims to store the user's first and last names
            if (result.Succeeded)
            {
                _userManager.AddClaim(user.Id, new Claim(SecurityGlobal.FirstNameClaim, userModel.FirstName));
                _userManager.AddClaim(user.Id, new Claim(SecurityGlobal.LastNameClaim, userModel.LastName));
                _userManager.AddClaim(user.Id, new Claim(SecurityGlobal.FullNameClaim, $"{userModel.FirstName} {userModel.LastName}"));
            }

            return result;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Deletes a claim from a user 
        /// </summary>
        /// <param name="user">The user to have a claim deleted</param>
        /// <param name="claim">A claim to be deleted from user</param>
        /// <returns></returns>
        public int Delete(IdentityUser user, Claim claim)
        {
            const string commandText = "[Security].[UserClaimDelete]";
            var parameters = new Dictionary<string, object>
            {
                {"@userId", user.Id},
                {"@claimType", claim.Type},
                {"@claimValue", claim.Value}
            };

            return _connection.Execute(commandText, parameters, null, null, CommandType.StoredProcedure);
        }