Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
roomlist
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
23
Issues
23
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
SRCT
roomlist
Commits
f8ea3812
Commit
f8ea3812
authored
Jun 20, 2017
by
Daniel W Bond
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implemented middleware checking if a student is blocked or not, and logging them out if so
parent
3e5794af
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
4 deletions
+27
-4
roomlist/settings/views.py
roomlist/settings/views.py
+27
-4
No files found.
roomlist/settings/views.py
View file @
f8ea3812
# standard library imports
from
__future__
import
absolute_import
,
print_function
# core django imports
from
django.
shortcuts
import
render
from
django.
views.generic
import
View
,
DetailView
,
TemplateView
,
RedirectView
from
django.
contrib
import
messages
from
django.
contrib.auth
import
logout
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.http
import
Http404
from
django.core.urlresolvers
import
reverse
from
django.http
import
Http404
from
django.shortcuts
import
render
from
django.views.generic
import
View
,
DetailView
,
TemplateView
,
RedirectView
from
django.utils.safestring
import
mark_safe
# third party imports
from
braces.views
import
LoginRequiredMixin
from
accounts.models
import
Student
,
Major
# imports from your apps
from
accounts.models
import
Student
,
Major
from
core.utils
import
shadowbanning
...
...
@@ -96,3 +99,23 @@ class RedirectSlug(RedirectView):
raise
Http404
else
:
return
Http404
class
BlockingMiddleware
(
object
):
"""Prevent students who have been blocked from accessing any
login-protected content.
This is implemented as middleware to immediately force a user's logout,
not just to block them once they've logged out and are logging back in."""
def
process_view
(
self
,
request
,
view_func
,
view_args
,
view_kwargs
):
if
request
.
user
.
is_authenticated
():
if
request
.
user
.
student
.
blocked
:
msg
=
"""You are not permitted to use Roomlist. Please contact us at
<a href="mailto:roomlist@lists.srct.gmu.edu">
roomlist@lists.srct.gmu.edu</a>
if you believe this to be an error."""
messages
.
add_message
(
request
,
messages
.
ERROR
,
mark_safe
(
msg
))
logout
(
request
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment