Created
February 17, 2013 15:58
-
-
Save Mortal/4971972 to your computer and use it in GitHub Desktop.
Django password protection with Apache basic protection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, sys | |
here = lambda * x: os.path.join(os.path.abspath(os.path.dirname(__file__)), *x) | |
sys.path.append(here('venv/lib/python2.6/site-packages')) | |
sys.path.append(here('web')) | |
os.environ['DJANGO_SETTINGS_MODULE'] = 'mftutor.settings' | |
from django.contrib.auth.models import User | |
from django import db | |
from mftutor.settings import YEAR | |
def check_password(environ, user, password): | |
db.reset_queries() | |
kwargs = {'username': user, 'is_active': True, 'tutorprofile__tutor__year__exact': YEAR} | |
try: | |
try: | |
user = User.objects.get(**kwargs) | |
except User.DoesNotExist: | |
return None | |
if user.check_password(password): | |
return True | |
else: | |
return False | |
finally: | |
db.connection.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Location /static/gallery/> | |
AuthType Basic | |
AuthName "matfystutor.dk" | |
AuthBasicProvider wsgi | |
WSGIAuthUserScript /home/mftutor/web/auth.wsgi | |
Require valid-user | |
</Location> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment