Ejemplo n.º 1
0
        public async Task <AccessResponse> CheckAccess(CheckAccessRequest accessRequest)
        {
            try
            {
                var validationResult = await _accessRequestValidator.ValidateAsync(accessRequest);

                if (!validationResult.IsValid)
                {
                    var response = ValidationResponseHelper.GetResponse(validationResult);
                    return(new AccessResponse
                    {
                        Status = response.Status,
                        Message = response.Message
                    });
                }


                var result = await _securityContext.CheckAccess(accessRequest.UserId, accessRequest.AccessRightNames);

                return(new AccessResponse
                {
                    Status = ActionStatus.Success,
                    AccessRightNames = result
                });
            }
            catch (SecurityDbException e)
            {
                return(new AccessResponse
                {
                    Status = ActionStatus.Warning,
                    Message = PrettyExceptionHelper.GetMessage(e)
                });
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(new AccessResponse
                {
                    Status = ActionStatus.Error,
                    Message = "Something went wrong!"
                });
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResponse> UpdateUserInfo(UserInfo userInfo)
        {
            try
            {
                var validationResult = await _userRightsValidator.ValidateAsync(userInfo);

                if (!validationResult.IsValid)
                {
                    return(ValidationResponseHelper.GetResponse(validationResult));
                }


                await _securityContext.UpdateUser(_mapper.Map <UserInfoDb>(userInfo));

                return(new ActionResponse
                {
                    Status = ActionStatus.Success
                });
            }
            catch (SecurityDbException e)
            {
                return(new ActionResponse
                {
                    Status = ActionStatus.Warning,
                    Message = PrettyExceptionHelper.GetMessage(e)
                });
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(new ActionResponse
                {
                    Status = ActionStatus.Error,
                    Message = "Something went wrong!"
                });
            }
        }