예제 #1
0
        public void UAUpdateClaims(MSClaimEdit model)
        {
            var userManager = HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>();

            // Clean / tidy / trim the incoming type and value strings
            var claimType  = model.ClaimType.Trim();
            var claimValue = model.ClaimValue.Trim();

            // Validate the requested claim against the master list of allowed claims
            if (AppClaimGetByMatch(claimType, claimValue) == null)
            {
                return;
            }

            foreach (var email in model.EmailAddresses)
            {
                var trimedEmail = email.Trim();
                // Using the user manager object, attempt to find the user account by its email address
                var o = userManager.FindByEmailAsync(email).Result;

                // If found, check whether it already has the requested claim
                if (o.Claims.Where(c => c.ClaimType == claimType && c.ClaimValue.ToLower() == claimValue.Trim().ToLower()).Count() == 0)
                {
                    IdentityResult result = userManager.AddClaim(o.Id, new Claim(claimType, claimValue));
                }
            }
        }
예제 #2
0
        public IHttpActionResult PutUpdateClaim(MSClaimEdit model)
        {
            // Ensure that an "editedItem" is in the entity body
            if (model == null)
            {
                return(BadRequest("Must send an entity body with the request"));
            }

            // Ensure that we can use the incoming data
            if (ModelState.IsValid)
            {
                // Attempt to update the item
                m.UAUpdateClaims(model);
                return(Ok());
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }