Skip to content

Commit

Permalink
Merge pull request #9 from digao21/master
Browse files Browse the repository at this point in the history
corrigindo o bug da sessao
  • Loading branch information
ftuyama committed May 16, 2016
2 parents 14ba059 + b745cbb commit e0324a9
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
22 changes: 22 additions & 0 deletions Athena/middleware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from datetime import datetime, timedelta
from django.conf import settings
from django.contrib import auth
from django.http import HttpResponsePermanentRedirect


class AutoLogout:
def process_request(self, request):
if not request.user.is_authenticated() :
#Can't log out if not logged in
return

try:
if datetime.now() - request.session['last_touch'] > timedelta( 0, settings.AUTO_LOGOUT_DELAY * 60, 0):
del request.session['last_touch']
auth.logout(request)
request.session['advise'] = 'true';
#return HttpResponsePermanentRedirect(redirect_url)
except KeyError:
pass

request.session['last_touch'] = datetime.now()
11 changes: 7 additions & 4 deletions Athena/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
'Athena.middleware.AutoLogout',
)

SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
AUTO_LOGOUT_DELAY = 1

ROOT_URLCONF = 'Athena.urls'

TEMPLATES = [
Expand Down Expand Up @@ -112,13 +116,9 @@
# https://docs.djangoproject.com/en/1.8/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

MEDIA_ROOT = os.path.join(BASE_DIR, 'arquivos')
Expand All @@ -131,3 +131,6 @@
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static/'),
)

# Session expire
# SESSION_COOKIE_AGE = 30
19 changes: 18 additions & 1 deletion Promachos/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from Athena.utils import checar_login_professor, checar_login_aluno
from Aeacus import compare
from pprint import pprint
from datetime import datetime

import re

Expand All @@ -23,8 +24,10 @@ def login(request):
aluno = checar_login_aluno(request)

if professor:
request.session['last_touch'] = datetime.now()
return HttpResponseRedirect('/professor')
if aluno:
request.session['last_touch'] = datetime.now()
return HttpResponseRedirect('/aluno')

if request.method == 'POST':
Expand Down Expand Up @@ -53,6 +56,20 @@ def login(request):
context_instance=RequestContext(request),
)

try:
if request.session['advise'] == 'true':
return render_to_response(
'login.html',
{
"invalid_message": "Sessao expirada",
"success_message": ""
},
context_instance=RequestContext(request),
)
except KeyError:
pass


return render_to_response('login.html',
{"invalid_message": ""},
context_instance=RequestContext(request))
Expand Down Expand Up @@ -530,4 +547,4 @@ def perfil(request):
return render_to_response(
'perfil.html',
context_instance=RequestContext(request),
)
)

0 comments on commit e0324a9

Please sign in to comment.