public void OnGet()
        {
            HttpContext.Session.Remove("token");
            HttpContext.Session.Remove("role");

            HttpContext.Response.Redirect(CurentCultureUtils.GetCurrentCultureLink("Authentication/Login"));
        }
        public static void RedirectRequests(RewriteContext context)
        {
            var request = context.HttpContext.Request;
            var path    = request.Path.Value;

            var publicRoutes = new List <string>
            {
                "Index",
                "Authentication/Login",
                "Authentication/Register"
            };

            var isUserLoggedIn = AuthenticationUtils.IsUserLoggedIn(context.HttpContext);

            bool isRoutePublic = false;

            publicRoutes.ForEach(route =>
            {
                if (path.Contains(route))
                {
                    isRoutePublic = true;
                }
            });

            if (!isUserLoggedIn && !isRoutePublic)
            {
                context.HttpContext.Response.Redirect(CurentCultureUtils.GetCurrentCultureLink("Authentication/Login"));
            }
        }
Example #3
0
        public async Task <IActionResult> OnPostAsync(int selectedDoctorId, int[] selectedReasonsIds, DateTime pickedDate)
        {
            if (ModelState.IsValid)
            {
                if (pickedDate < DateTime.UtcNow)
                {
                    ModelState.AddModelError("Date", _cultureLocalizer.Text("Date must be from the future"));
                }
                else
                {
                    Appointment.Doctor = new Doctor()
                    {
                        UserId = selectedDoctorId
                    };
                    if (selectedReasonsIds.Length > 0)
                    {
                        Appointment.AppointmentReasons = new List <Appointment2Reason>();
                        Array.ForEach(selectedReasonsIds, (reasonId) =>
                        {
                            Appointment.AppointmentReasons.Add(new Appointment2Reason()
                            {
                                ReasonId = reasonId
                            });
                        });
                    }
                    var patientId = AuthenticationUtils.GetPatientId(HttpContext);
                    if (patientId.HasValue)
                    {
                        Appointment.Patient = new Patient()
                        {
                            UserId = patientId.Value
                        };
                    }


                    Appointment.AppointmentDate = pickedDate;
                    appointmentsSetResponse     = await _appointmentsService.SetAppointment(Appointment);

                    if (appointmentsSetResponse == AppointmentSetResponse.CORRECT)
                    {
                        HttpContext.Response.Redirect(CurentCultureUtils.GetCurrentCultureLink("Appointments/AppointmentMade"));

                        return(null);
                    }
                }
            }


            await OnGetAsync();

            SelectedDoctor = selectedDoctorId;
            SelectedResons = selectedReasonsIds;
            Date           = pickedDate;
            return(Page());
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {
                var user = new User()
                {
                    Login    = LoginForm.Username,
                    Password = LoginForm.Password
                };
                var authenticationReponse = await authenticationService.Login(user);

                if (authenticationReponse.WasAuthenticationCorrect)
                {
                    HttpContext.Response.Redirect(CurentCultureUtils.GetCurrentCultureLink("Index"));

                    return(null);
                }
                Msg = _cultureLocalizer.Text("InvalidLogin");
            }

            return(Page());
        }