public bool AuthorizedUser(AuthorizedViewModel authorizedViewModel)
        {
            var tokenS = DecodeToken(authorizedViewModel.Token);
            var data   = userRoleService.GetAllUserRole(new UserViewModel
            {
                UserName = tokenS.Subject
            });
            var user        = userManager.FindByNameAsync(tokenS.Subject);
            var currentUser = userManager.GetClaimsAsync(user.Result);

            if (currentUser.Result.Count == 0)
            {
                return(false);
            }
            else if (Convert.ToDateTime(currentUser.Result.SingleOrDefault(a => a.Type == "exp").Value) < DateTime.Now)
            {
                var removecliamsresult = userManager.RemoveClaimsAsync(user.Result, currentUser.Result).Result;
                if (removecliamsresult.Succeeded)
                {
                    return(false);
                }
            }
            if (!CheckRoles(data.Result.Select(a => a.Role).ToList(), authorizedViewModel.Roles))
            {
                return(false);
            }
            return(true);
        }
예제 #2
0
        public IActionResult GetPinsFromBrand(string Brand, float Latitude, float Longitude)
        {
            var authorizeds = _authorizedRepository.GetAllByBrand(Brand);
            var search      = new SearchViewModel();

            foreach (var authorized in authorizeds)
            {
                //check if the distance of authorized is inside the avalaible radius
                var distance = Geolocation.CalculateDistance(Latitude, Longitude, Convert.ToDouble(authorized.Latitude), Convert.ToDouble(authorized.Longitude), 'K');
                if (distance > DISTANCE_LIMIT)
                {
                    continue;
                }

                var Authorized = new AuthorizedViewModel()
                {
                    Id                   = authorized.Id,
                    Nome                 = authorized.Nome,
                    Titulo               = authorized.Titulo,
                    Descricao            = authorized.Descricao,
                    Endereco             = authorized.Endereco,
                    Telefone             = authorized.Telefone,
                    Latitude             = Convert.ToDouble(authorized.Latitude),
                    Longitude            = Convert.ToDouble(authorized.Longitude),
                    Email                = authorized.Email,
                    HorarioFuncionamento = authorized.HorarioFuncionamento,
                    Servicos             = authorized.Servicos
                };
                var geometry = new GeometryViewModel
                {
                    Coordinates = new List <double> {
                        Convert.ToDouble(authorized.Longitude), Convert.ToDouble(authorized.Latitude)
                    }
                };
                var property = new PropertyViewModel
                {
                    Title = authorized.Nome
                };
                var feature = new FeaturesViewModel
                {
                    Geometry = geometry,
                    Property = property
                };

                search.Features.Add(feature);
                search.Authorizeds.Add(Authorized);
            }

            var jsonString = JsonSerializer.Serialize(search);

            return(Ok(jsonString));
        }
        public bool DeleteUserRoles([FromBody] AuthorizedViewModel authorizedView)
        {
            var result = customAuthorizeService.AuthorizedUser(authorizedView);

            return(result);
        }
예제 #4
0
        public ActionResult Index()
        {
            var viewModel = AuthorizedViewModel.Create(Repository, CurrentUser.Identity.Name, Site);

            return(View(viewModel));
        }