Пример #1
0
        protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, AccessRightRequirement requirement)
        {
            var data = context.User.Claims.FirstOrDefault(c => c.Type == "_UserId")?.Value;

            int             _UserId = 0, _CustomerId = 0;
            enmCustomerType _CustomerType = enmCustomerType.B2C;
            string          tempUserId    = context.User.Claims.FirstOrDefault(c => c.Type == "_UserId")?.Value;

            int.TryParse(tempUserId, out _UserId);

            string _Name          = context.User.Claims.FirstOrDefault(c => c.Type == "_Name")?.Value;
            string tempCustomerId = context.User.Claims.FirstOrDefault(c => c.Type == "_CustomerId")?.Value;

            int.TryParse(tempCustomerId, out _CustomerId);
            string tempCustomerType = context.User.Claims.FirstOrDefault(c => c.Type == "_CustomerType")?.Value;

            if (!string.IsNullOrEmpty(tempCustomerType))
            {
                Enum.TryParse <enmCustomerType>(tempCustomerType, out _CustomerType);
            }

            _currentUser.CustomerId   = _CustomerId;
            _currentUser.UserId       = _UserId;
            _currentUser.CustomerType = _CustomerType;
            _currentUser.Name         = _Name;

            if (_currentUser.HaveClaim(requirement.accessRight))
            {
                context.Succeed(requirement);
            }
            return(Task.CompletedTask);
        }
Пример #2
0
        public CurrentUsers(IHttpContextAccessor httpContext, DBContext context)
        {
            _httpContext = httpContext;
            _context     = context;
            string tempUserId = httpContext.HttpContext.User.FindFirst("_UserId")?.Value;

            int.TryParse(tempUserId, out _UserId);

            _Name = httpContext.HttpContext.User.FindFirst("_Name")?.Value;
            string tempCustomerId = httpContext.HttpContext.User.FindFirst("_CustomerId")?.Value;

            int.TryParse(tempCustomerId, out _CustomerId);
            string tempCustomerType = httpContext.HttpContext.User.FindFirst("_CustomerType")?.Value;

            _CustomerType = enmCustomerType.B2C;
            if (!string.IsNullOrEmpty(tempCustomerType))
            {
                Enum.TryParse <enmCustomerType>(tempCustomerType, out _CustomerType);
            }
        }
Пример #3
0
        public CurrentUser(IHttpContextAccessor httpContext)
        {
            _httpContext = httpContext;
            _Name        = _httpContext.HttpContext.User.FindFirst("__Name")?.Value;
            _Email       = _httpContext.HttpContext.User.FindFirst("__Email")?.Value;
            _Contact     = _httpContext.HttpContext.User.FindFirst("__Contact")?.Value;
            _MPin        = _httpContext.HttpContext.User.FindFirst("__MPin")?.Value;
            int.TryParse(_httpContext.HttpContext.User.FindFirst("__CustomerId")?.Value, out _CustomerId);
            ulong.TryParse(_httpContext.HttpContext.User.FindFirst("__UserId")?.Value, out _UserId);
            ulong.TryParse(_httpContext.HttpContext.User.FindFirst("__DistributorId")?.Value, out _DistributorId);
            string tempCustomerType = httpContext.HttpContext.User.FindFirst("__CustomerType")?.Value;
            string _Token           = httpContext.HttpContext.User.FindFirst("__Token")?.Value;

            _CustomerType = enmCustomerType.B2C;
            if (!string.IsNullOrEmpty(tempCustomerType))
            {
                Enum.TryParse <enmCustomerType>(tempCustomerType, out _CustomerType);
            }
            _cultureInfo = new CultureInfo("en-IN", false);
        }
Пример #4
0
        public async Task <string> GetTokken(ISettings settings, int CustomerId_, int userId_, enmCustomerType customerType_, string Name_)
        {
            string tboUrl       = _config["API:GenrateToken"];
            string jsonString   = JsonConvert.SerializeObject(new{ CustomerId = CustomerId_, userId = userId_, customerType = customerType_, Name = Name_ });
            var    HaveResponse = settings.GetResponse(jsonString, tboUrl, "POST");

            if (HaveResponse.Code == 0)
            {
                return(HaveResponse.Message);
            }
            else
            {
                throw new Exception(HaveResponse.Message);
            }
        }