コード例 #1
0
        public async Task <IActionResult> Create([FromBody] AddClaims createProfileRequest)
        {
            if (ModelState.IsValid)
            {
                var response = await _authService.SetUserClaims(createProfileRequest.Jwt);

                return(response.Success ? new OkObjectResult(response.Data) : StatusCode(500));
            }

            return(StatusCode(400));
        }
コード例 #2
0
        private bool TestCommand(AddClaims evt, out IEvent e)
        {
            e = null;
            if (user == null)
            {
                return(false);
            }

            var claimsToAdd = evt.Claims.Except(user.Claims ?? new Claim[0], ClaimComparer.Instance).ToList();

            if (claimsToAdd.Count > 0)
            {
                e = new ClaimsAdded(claimsToAdd);
            }
            return(true);
        }
コード例 #3
0
        public async Task <IActionResult> AssignAdminRole([FromBody] AddClaims createProfileRequest)
        {
            try
            {
                var isAdmin = bool.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "Admin").Value);
                if (ModelState.IsValid && isAdmin)
                {
                    var response = await _authService.SetAdminClaims(createProfileRequest.Jwt);

                    return(response ? new OkResult() : StatusCode(500));
                }
            }
            catch (NullReferenceException)
            {
                return(StatusCode(403));
            }

            return(StatusCode(400));
        }