Commit d7caf949 authored by Odair M.'s avatar Odair M.

Closes #158: para acessar todas as paginas precisa está autenticado...

Closes #158: para acessar todas as paginas precisa está autenticado exceto a pagina de login e de admin
parent e21f1fa0
Pipeline #19214 passed with stage
in 14 seconds
from django.http import HttpResponseRedirect
from django.urls import reverse
from django.conf import settings
from re import compile
EXEMPT_URLS = [compile(reverse(settings.LOGIN_URL).lstrip('/'))]
if hasattr(settings, 'LOGIN_EXEMPT_URLS'):
EXEMPT_URLS += [compile(expr) for expr in settings.LOGIN_EXEMPT_URLS]
class LoginRequiredMiddleware:
"""
Middleware that requires a user to be authenticated to view any page other
than LOGIN_URL. Exemptions to this requirement can optionally be specified
in settings via a list of regular expressions in LOGIN_EXEMPT_URLS (which
you can copy from your urls.py).
Requires authentication middleware and template context processors to be
loaded. You'll get an error if they aren't.
"""
def process_request(self, request):
assert hasattr(request, 'user'), "The Login Required middleware\
requires authentication middleware to be installed. Edit your\
MIDDLEWARE_CLASSES setting to insert\
'django.contrib.auth.middlware.AuthenticationMiddleware'. If that doesn't\
work, ensure your TEMPLATE_CONTEXT_PROCESSORS setting includes\
'django.core.context_processors.auth'."
if not request.user.is_authenticated():
path = request.path_info.lstrip('/')
if not any(m.match(path) for m in EXEMPT_URLS):
print(reverse(settings.LOGIN_URL))
return HttpResponseRedirect(reverse(settings.LOGIN_URL))
......@@ -13,9 +13,6 @@ https://docs.djangoproject.com/en/1.9/ref/settings/
import os
from django.contrib import messages
import os
print()
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PROJECT_DIR = os.path.join(BASE_DIR, '..')
......@@ -64,8 +61,15 @@ MIDDLEWARE_CLASSES = [
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'adega.middleware.LoginRequiredMiddleware',
]
LOGIN_EXEMPT_URLS = (
r'/admin/$',
r'adega/admin/',
)
ROOT_URLCONF = 'adega.urls'
TEMPLATES = [
......
from django.shortcuts import render, redirect
from django.contrib.auth.decorators import login_required
from django.contrib.auth import logout as process_logout
from submission.models import Submission
@login_required
def dashboard(request):
degrees = request.user.educator.degree.all()
degrees_last_submissions = []
......@@ -24,8 +22,6 @@ def dashboard(request):
"hide_navbar": True
})
@login_required
def logout(request):
process_logout(request)
......
from django.shortcuts import render, redirect
from django.views.generic import View
from django.contrib.auth.decorators import login_required
from django.contrib.auth import logout as process_logout
from report_api.views import get_degree_information
from degree.models import Degree
......@@ -8,7 +7,6 @@ from submission.models import Submission
import json
@login_required
def index(request, submission_id):
submission_id = int(submission_id)
......@@ -28,7 +26,6 @@ def index(request, submission_id):
#class Views(View):
# template_name = "index.html"
# @login_required
# def setDegree(self,request,degree_id):
# request.session["degree"] = degree_id
# return redirect('degree:index' )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment