learningequality/ka-lite — pull request #2123 by cpauya (2014-05-24 05:42:13+00:00)
Title: Feature/2119 redirect users if exam mode is on

This is for #2119 - Redirect users if exam mode is on on that device

Hi @aronasorman - I've already added `EXAM_MODE_ON` boolean at `fle_utils.config.models.Settings` on my branch and created the `student_testing.middleware.ExamModeCheck` middleware.

However I need to verify these:

1. When you say user profile page, is this the `reverse("account_management")`?
2. How do I know the logged-in user is a student? I checked by logging-in as a student but `request.user.is_authenticated()` returns an `AnonymousUser`, I'm using the `request.is_logged_in` for now and used `request.is_admin` and `request.is_teacher` to bypass the redirect.
3. How do we prevent redirect loops? I saw GET calls to `/api/*` and `/securesync/*` which redirects to the redirect url causing a redirect loop - so I put an ignore list like

```python
redirect_to = reverse("account_management")
url_exceptions = [
"^/api/*",
"^/securesync/*",
redirect_to
]

This works when a FacilityUser logs-in so far.

I looked at #2122 also to cross-check. When a specific exam is flagged, the students will be redirected to the proper exam. I just added a TODO: comment at the bottom where we need to put the codes for this.