Пример #1
0
 public async Task <IActionResult> Index()
 {
     if (int.TryParse(User.FindFirstValue("id"), out int id))
     {
         var patient = (await _patientRepository.GetWithInclude(p => p.Id == id, p => p.Belay)).FirstOrDefault();
         if (!patient.IsValid())
         {
             _notificationService.AddWarning("Личная информация указана не полностью, некорые функции могут быть не доступны");
         }
         return(View(patient));
     }
     _notificationService.AddError("Ошибка идентификации");
     _notificationService.ApplyForRedirect(TempData);
     return(RedirectToAction("Index", "Home"));
 }
Пример #2
0
        public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            int.TryParse(context.HttpContext.User.FindFirst("id")?.Value, out int id);
            long.TryParse(context.HttpContext.User.FindFirst("phoneNumber")?.Value, out long phoneNumber);
            //var timeStamp = context.HttpContext.User.FindFirst("timeStamp")?.Value;

            if (id == 0 || phoneNumber == 0 || !(await _patientRepository.GetWhere(u => u.Id == id && u.PhoneNumber == phoneNumber)).Any())
            {
                await context.HttpContext.SignOutAsync();

                var controller = context.Controller as Controller;
                if (controller == null)
                {
                    return;
                }

                _notificationService.AddError("Ошибка cookie, одно из утверждений не соответствует действительности. Авторизируйтесь повторно");
                _notificationService.ApplyForRedirect(controller.TempData);
                context.Result = new RedirectResult("/Account/Login");
            }
            else
            {
                await next();
            }
        }