apps: ajout de méthode pour extraire le mode d'authentification de la requête en cours

This commit is contained in:
Benjamin Dauvergne 2017-11-24 19:03:23 +01:00
parent 0e80931697
commit 05585038b1
1 changed files with 36 additions and 0 deletions

View File

@ -23,6 +23,8 @@ from django.conf import settings
from django.db import router, DEFAULT_DB_ALIAS
from django.utils.timezone import now
from authentic2.constants import AUTHENTICATION_EVENTS_SESSION_KEY
class AppConfig(django.apps.AppConfig):
name = 'authentic2_cut'
@ -626,3 +628,37 @@ class AppConfig(django.apps.AppConfig):
def cut_event_fc_unlink(self, user, **kwargs):
self.log_action(user, u'déliaison de FranceConnect')
def get_authentication_how(self):
from authentic2.middleware import StoreRequestMiddleware
request = StoreRequestMiddleware.get_request()
if request:
for event in request.session.get(AUTHENTICATION_EVENTS_SESSION_KEY, []):
if 'how' in event:
return event['how']
def get_authentication_method(self, how):
if how.startswith('password'):
return 'PWD'
elif how == 'france-connect':
return 'FC'
elif how == 'email':
return 'PWD'
elif how == 'oidc':
return 'AGENT'
elif how == 'switch':
return
else:
return
def get_authentication_message(self, how):
if how.startswith('password'):
return u'connexion par mot de passe'
elif how == 'france-connect':
return u'connexion par FranceConnect'
elif how == 'email':
return u'connexon à l\'enregistrement ou par récupération de mot de passe'
elif how == 'oidc':
return u'connexion'
else:
return u'connexion how:%s' % how