ajout de l'autologin

This commit is contained in:
Ambulance Clerc
2023-02-13 18:19:50 +01:00
parent 66713c880f
commit fc364e28e0
5 changed files with 19 additions and 3 deletions

View File

@@ -25,7 +25,7 @@ SECRET_KEY = 'django-insecure-j4jd&+4j^t_=@zr(#q@n!8e*58vkql6&_6w-t14ju8pw%ei%^s
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
cfg_dev_mode = False
cfg_dev_mode = false
ALLOWED_HOSTS = ["rh.ambulance-clerc.ch"]
if cfg_dev_mode:
@@ -60,6 +60,7 @@ MIDDLEWARE = [
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django_autologin.middleware.AutomaticLoginMiddleware',
]
ROOT_URLCONF = 'Reskreen.urls'
@@ -131,6 +132,8 @@ AUTH_PASSWORD_VALIDATORS = [
},
]
AUTOMATIC_LOGIN_MAX_AGE = 500 * 60*60*24 # 500 jours
# Internationalization
# https://docs.djangoproject.com/en/4.0/topics/i18n/

View File

@@ -17,7 +17,8 @@ from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('', admin.site.urls),
path('admin/', admin.site.urls),
path('accounts/', admin.site.urls),
path('collabs/', include('collabs.urls')),
path('vehicules/', include('vehicles.urls')),
path('caldav/', include('mycaldav.urls')),

View File

@@ -18,6 +18,8 @@ urlpatterns = [
path('manif', views.view_manif_caldav, name='view_manif_caldav'),
path('team_pdf', views.view_team_pdf_caldav, name='view_team_pdf_caldav'),
path('reskreen', views.view_reskreen, name='view_reskreen'),
path('generate_token', views.view_generate_token, name='view_generate_token'),

View File

@@ -110,13 +110,22 @@ def view_team_pdf_caldav(request):
return FileResponse(open('mycaldav/export.pdf', 'rb'), as_attachment=False, content_type='application/pdf')
@xframe_options_exempt
@login_required
def view_reskreen(request):
template = loader.get_template("reskreen.html")
#context = {'latest_task_list': o_caldav.day, 'night_task_list': o_caldav.night, 'today': datetime.today().strftime('%d.%m')}
context = {}
return HttpResponse(template.render(context, request))
from django_autologin.templatetags.django_autologin import automatic_login_token
@login_required
def view_generate_token(request):
current_user = request.user
auto_login = automatic_login_token(current_user)
print(f"{current_user.username} autologin=> {auto_login}")
return HttpResponse(f"{current_user.username}autologin=> {auto_login}")

View File

@@ -55,3 +55,4 @@ webencodings==0.5.1
x-wr-timezone==0.0.5
xhtml2pdf==0.2.7
zopfli==0.1.9
django-autologin