auth_fc: remove registration view, create and log in user (#50964)

This commit is contained in:
Serghei Mihai 2021-04-01 12:30:31 +02:00
parent 98c1ffc220
commit c79cc3963e
10 changed files with 67 additions and 437 deletions

View File

@ -35,10 +35,6 @@ class AppSettings(object):
def enable(self):
return self._setting('ENABLE', False)
@property
def create(self):
return self._setting('CREATE', False)
@property
def authorize_url(self):
return self._setting('AUTHORIZE_URL', 'https://fcp.integ01.dev-franceconnect.fr/api/v1/authorize')

View File

@ -57,23 +57,11 @@ class FcAuthenticator(BaseAuthenticator):
'fc_user_info': fc_user_info,
}
)
if fc_user_info:
context.update(
{
'registration_url': a2_utils.make_url(
'fc-registration', keep_params=True, params=params, request=request
),
'fc_user_info': fc_user_info,
'block-extra-css-class': 'fc-registration',
}
)
template = 'authentic2_auth_fc/login_registration.html'
else:
context['login_url'] = a2_utils.make_url(
'fc-login-or-link', keep_params=True, params=params, request=request
)
context['block-extra-css-class'] = 'fc-login'
template = 'authentic2_auth_fc/login.html'
context['login_url'] = a2_utils.make_url(
'fc-login-or-link', keep_params=True, params=params, request=request
)
context['block-extra-css-class'] = 'fc-login'
template = 'authentic2_auth_fc/login.html'
return TemplateResponse(request, template, context)
def profile(self, request, *args, **kwargs):
@ -100,24 +88,3 @@ class FcAuthenticator(BaseAuthenticator):
}
)
return render_to_string('authentic2_auth_fc/linking.html', context, request=request)
def registration(self, request, *args, **kwargs):
if 'fc_user_info' in request.session:
return []
context = kwargs.get('context', {}).copy()
params = {
'registration': '',
}
if app_settings.popup:
params['popup'] = ''
context.update(
{
'login_url': a2_utils.make_url(
'fc-login-or-link', keep_params=True, params=params, request=request
),
'popup': app_settings.popup,
'about_url': app_settings.about_url,
}
)
return TemplateResponse(request, 'authentic2_auth_fc/registration.html', context)

View File

@ -25,7 +25,7 @@ from django.db import IntegrityError
from authentic2 import hooks
from authentic2.a2_rbac.utils import get_default_ou
from . import app_settings, models, utils
from . import models, utils
logger = logging.getLogger(__name__)
@ -48,8 +48,14 @@ class FcBackend(ModelBackend):
logger.info(u'user %s login refused, it is inactive', user)
raise PermissionDenied
if user_info:
if not user and app_settings.create:
User = get_user_model()
User = get_user_model()
user_qs = User.objects.filter(**kwargs.get('user_filter', {}))
if user_qs.count() > 1:
return
if user_qs.exists():
user = user_qs.get()
if not user:
user = User.objects.create(ou=get_default_ou())
user.set_unusable_password()
try:
@ -69,9 +75,6 @@ class FcBackend(ModelBackend):
)
hooks.call_hooks('event', name='fc-create', user=user, sub=sub)
if not user:
return None
# always handle given_name and family_name
updated = []
if user_info.get('given_name') and user.first_name != user_info['given_name']:

View File

@ -1,4 +1,4 @@
div#fc-registration-user-info, div#fc-button-wrapper, div#fc-explanation-text {
div#fc-button-wrapper, div#fc-explanation-text {
text-align: center;
width: 100%;
}

View File

@ -1,215 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Generator: Adobe Illustrator 21.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
id="Calque_1"
inkscape:version="0.92.2 (5c3e80d, 2017-08-06)"
sodipodi:docname="FC-register-button.svg"
x="0px"
y="0px"
viewBox="0 0 283.5 82.2"
style="enable-background:new 0 0 283.5 82.2;"
xml:space="preserve"><metadata
id="metadata118"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
id="defs116" /><style
type="text/css"
id="style2">
.st0{fill:#1B1464;}
.st1{fill:#034EA2;}
.st2{fill:#FFFFFF;}
.st3{fill:#0069CC;}
.st4{fill:#ED1C24;}
.st5{enable-background:new ;}
</style><sodipodi:namedview
bordercolor="#666666"
borderopacity="1"
gridtolerance="10"
guidetolerance="10"
id="namedview9872"
inkscape:current-layer="Calque_1"
inkscape:cx="21.609389"
inkscape:cy="21.561528"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-height="1030"
inkscape:window-maximized="1"
inkscape:window-width="1920"
inkscape:window-x="0"
inkscape:window-y="26"
inkscape:zoom="2.1158854"
objecttolerance="10"
pagecolor="#ffffff"
showgrid="false" /><g
id="g9762"
inkscape:export-filename="C:\Users\Jean-Baptiste Lagade\Google Drive\UX@FC\1.LOGOS et BOUTONS SVG PNG JPG\1.SVG (Harry)\Bouton FranceConnect Bleu.png"
inkscape:export-xdpi="300.38364"
inkscape:export-ydpi="300.38364"><path
id="path9764"
class="st0"
d="M278,2H5.4C3,2,1.2,4,1.2,6.6v7.6l0,0v63.1c0,1.6,1,2.9,2.7,2.9h275.5c1.7,0,2.8-1.3,2.8-2.9 v-4.9l0,0V6.6C282.2,4,280.4,2,278,2z" /><path
id="path9766"
class="st1"
d="M49.1,3.4H5.5c-1.7,0-2.7,1.5-2.7,3.2v65.8c0,1.7,1,3,2.7,3h272.4c1.7,0,2.8-1.3,2.8-3V6.6 c0-1.7-1.1-3.2-2.8-3.2L49.1,3.4" /><g
id="g9826"><polygon
id="polygon9828"
class="st2"
points="18,22 18,56.9 48.2,74.4 78.5,56.9 78.5,22 48.2,4.5 " /><g
id="g9830"><path
id="path9832"
class="st0"
d="M48.2,3.3L17,21.4v36.1l31.3,18l31.3-18V21.4L48.2,3.3z M78.5,56.9L48.2,74.4L18,56.9V22 L48.2,4.5L78.5,22V56.9z" /></g><polygon
id="polygon9834"
class="st3"
points="62.6,20.8 48.9,12.9 35.2,20.8 25.9,26.2 25.9,26.2 25.9,52.7 25.9,52.7 48.9,66 71.9,52.7 71.9,52.7 71.9,26.2 71.9,26.2 " /><g
id="g9836"><polygon
id="polygon9838"
class="st1"
points="64.3,39.4 56,25.1 48.9,12.9 48.9,29.6 48.9,66 71.9,52.7 71.9,52.7 " /><polygon
id="polygon9840"
class="st3"
points="56,25.1 64.3,39.4 71.9,26.2 71.9,26.2 62.6,20.8 " /><polygon
id="polygon9842"
class="st4"
points="62.6,20.8 48.9,12.9 56,25.1 " /><path
id="polygon9844"
class="st3"
d="M56,25.1l-7.1-12.2L56,25.1z" /><rect
id="rect9846"
x="60.1"
y="24"
class="st3"
width="0"
height="16.6" /><polygon
id="polygon9848"
class="st4"
points="71.9,52.7 71.9,26.2 64.3,39.4 " /><path
id="polygon9850"
class="st4"
d="M64.3,39.4l7.6,13.3L64.3,39.4z" /><polygon
id="polygon9852"
class="st3"
points="33.6,39.4 41.9,25.1 48.9,12.9 48.9,29.6 48.9,66 25.9,52.7 25.9,52.7 " /><polygon
id="polygon9854"
class="st4"
points="41.9,25.1 33.6,39.4 25.9,26.2 25.9,26.2 35.2,20.8 " /><polygon
id="polygon9856"
class="st1"
points="35.2,20.8 48.9,12.9 41.9,25.1 " /><path
id="polygon9858"
class="st3"
d="M41.9,25.1l7-12.2L41.9,25.1z" /><rect
id="rect9860"
x="37.7"
y="24"
class="st3"
width="0"
height="16.6" /><polygon
id="polygon9862"
class="st1"
points="25.9,52.7 25.9,26.2 33.6,39.4 " /><path
id="polygon9864"
class="st3"
d="M33.6,39.4l-7.7,13.3L33.6,39.4z" /></g><g
id="g9866"><path
id="path9868"
class="st1"
d="M57.4,42c0.4,0,0.8-0.1,1.2,0c0.3,0.1,0.7,0.1,0.7,0.2c-0.1,0.6-1,0.7-1.4,1.3 c-0.1,0-0.1,0-0.2,0c-0.2,0.1-0.1,0.5-0.3,0.5c-0.2-0.1-0.4,0-0.7,0.1c0.3,0.3,0.7,0.5,1.1,0.4c0.1,0,0.2,0.1,0.2,0.3 c0,0,0.1,0,0.1-0.1c0.1,0,0.1,0,0.1,0.1s0,0.2,0,0.3c-0.2,0.3-0.6,0.2-0.9,0.2c0.6,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7-0.1 c0.2,0,0.1-0.4,0.3-0.5c0.1,0,0.1,0,0.2,0c0.4-0.6,1.3-0.8,1.4-1.3c0-0.1-0.4-0.1-0.7-0.2c-0.4-0.1-0.8,0-1.2,0 c-0.6,0.2-1.1,0.2-1.6,0.5c0.4-0.3,0.9-0.6,1.4-0.8c0.4-0.1,0.7-0.3,1.1-0.3c0.4-0.1,0.9-0.2,1.2-0.1c0.4,0.1,0.9,0.1,1,0.3 C60.6,42.1,60.3,42.5,59.9,42.8z" /></g></g></g><g
id="g99"><g
class="st5"
id="g69"><path
class="st2"
d="M102,33.6c-0.9,0.6-2.1,0.7-3.6,0.7c-1,0-2.2,0-3.5-0.2v-1.9c1.1,0.1,2.3,0.2,3.3,0.2c0.8,0,1.6-0.1,2.2-0.3 c0.7-0.3,1-0.9,1-1.6c0-1-0.5-1.5-1.4-1.8c-0.6-0.2-1.4-0.4-2-0.6c-1.9-0.6-3-1.5-3-3.6c0-1.2,0.5-2.4,1.5-3.1 c1-0.6,2-0.7,3.3-0.7c0.9,0,2,0.1,3.2,0.2v1.8c-1.1-0.1-2.2-0.2-3-0.2c-0.7,0-1.4,0-1.9,0.3c-0.7,0.3-0.9,1-0.9,1.6 c0,0.9,0.5,1.4,1.4,1.7c0.6,0.2,1.2,0.4,2,0.6c2,0.5,3.1,1.5,3.1,3.7C103.6,31.6,103.2,32.9,102,33.6z"
id="path41" /><path
class="st2"
d="M105.4,25.8c0.7-1.9,1.3-3.6,1.7-5.4h2.2c-0.6,1.9-1.3,3.8-2,5.4H105.4z"
id="path43" /><path
class="st2"
d="M111.7,22.4v-2h2.2v2H111.7z M113.8,34.1h-2v-9.6h2L113.8,34.1L113.8,34.1z"
id="path45" /><path
class="st2"
d="M123.9,34.1v-6c0-1.6-0.8-2.1-2.1-2.1c-0.7,0-1.5,0.2-2.6,0.6v7.5h-2v-9.6h1.7L119,25 c1.2-0.4,2.4-0.8,3.5-0.8c1,0,2,0.3,2.7,1.1c0.6,0.7,0.8,1.6,0.8,2.7v6.1H123.9z"
id="path47" /><path
class="st2"
d="M134.2,33.8c-0.7,0.4-1.7,0.5-2.8,0.5c-0.8,0-1.8-0.1-2.8-0.2v-1.6c1,0.1,1.9,0.2,2.6,0.2 c0.7,0,1.2,0,1.7-0.2c0.5-0.2,0.7-0.6,0.7-1.1c0-0.6-0.4-1-1-1.2c-0.5-0.2-0.9-0.2-1.6-0.4c-1.6-0.4-2.4-1.1-2.4-2.7 c0-0.9,0.3-1.9,1.2-2.4c0.7-0.4,1.6-0.5,2.7-0.5c0.7,0,1.6,0.1,2.6,0.2v1.6c-0.8-0.1-1.7-0.2-2.4-0.2c-0.6,0-1.1,0-1.5,0.2 c-0.5,0.2-0.6,0.6-0.6,1c0,0.6,0.3,0.9,1,1.1c0.4,0.1,0.9,0.2,1.5,0.4c1.7,0.4,2.6,1.1,2.6,2.8C135.4,32.3,135.1,33.3,134.2,33.8z "
id="path49" /><path
class="st2"
d="M141.1,34.3c-1,0-2-0.3-2.8-1.1c-0.9-0.9-1.2-2.3-1.2-4c0-1.6,0.4-3.2,1.6-4.2c0.9-0.7,2-0.9,3.3-0.9 c0.7,0,1.5,0.1,2.3,0.2V26c-0.7-0.1-1.4-0.1-2.1-0.1c-2.1,0-3,1.1-3,3.4c0,2,0.8,3.3,2.6,3.3c0.8,0,1.8-0.3,2.7-0.5v1.6 C143.3,34,142.2,34.3,141.1,34.3z"
id="path51" /><path
class="st2"
d="M147,34.1v-9.6h1.7l0.1,0.6c1.4-0.6,2.2-0.9,3.4-0.9c0,0,0.1,0,0.2,0V26c-0.2,0-0.4,0-0.5,0 c-0.9,0-1.7,0.2-2.9,0.6v7.4H147z"
id="path53" /><path
class="st2"
d="M154.5,22.4v-2h2.2v2H154.5z M156.5,34.1h-2v-9.6h2L156.5,34.1L156.5,34.1z"
id="path55" /><path
class="st2"
d="M160,34.1v-9.6h1.7l0.1,0.6c1.4-0.6,2.2-0.9,3.4-0.9c0,0,0.1,0,0.2,0V26c-0.2,0-0.4,0-0.5,0 c-0.9,0-1.7,0.2-2.9,0.6v7.4H160z"
id="path57" /><path
class="st2"
d="M170.3,34.3c-1.1,0-2.2-0.2-3-1.1c-0.9-0.9-1.2-2.3-1.2-4c0-1.6,0.4-3.1,1.4-4c0.8-0.7,1.8-1,3.1-1 c1.1,0,2.2,0.2,3,1c1.2,1,1.3,2.5,1.3,4.5h-6.7c0,2,0.9,3,2.7,3c1.1,0,2.3-0.2,3.6-0.6v1.6C173.2,34,171.7,34.3,170.3,34.3z M170.4,25.6c-1.7,0-2.2,1.1-2.3,2.7h4.6C172.7,26.5,172.1,25.6,170.4,25.6z"
id="path59" /><path
class="st2"
d="M188.8,34.1l0-0.5c-1.2,0.4-2.3,0.8-3.5,0.8c-0.8,0-1.6-0.2-2.2-0.8c-0.6-0.6-0.9-1.3-0.9-2.3 c0-1,0.4-2,1.4-2.5c0.7-0.4,1.5-0.4,2.5-0.4c0.7,0,1.6,0,2.5,0.1v-0.4c0-1.7-0.7-2.3-2.8-2.3c-0.8,0-1.7,0.1-2.5,0.2v-1.6 c0.9-0.1,1.9-0.2,2.8-0.2c1.3,0,2.6,0.1,3.5,0.9c0.9,0.8,1,1.8,1,3.2v5.8H188.8z M188.4,29.8c-0.7-0.1-1.6-0.1-2.2-0.1 c-1.6,0-2.1,0.6-2.1,1.5c0,0.9,0.6,1.6,1.7,1.6c0.8,0,1.7-0.3,2.6-0.6V29.8z"
id="path61" /><path
class="st2"
d="M195.6,34.1l-3.6-9.6h2.2l2.6,7.6h0.1l2.6-7.6h2.1l-3.6,9.6H195.6z"
id="path63" /><path
class="st2"
d="M206.8,34.3c-1.1,0-2.2-0.2-3-1.1c-0.9-0.9-1.2-2.3-1.2-4c0-1.6,0.4-3.1,1.4-4c0.8-0.7,1.8-1,3.1-1 c1.1,0,2.2,0.2,3,1c1.2,1,1.3,2.5,1.3,4.5h-6.7c0,2,0.9,3,2.7,3c1.1,0,2.3-0.2,3.6-0.6v1.6C209.7,34,208.2,34.3,206.8,34.3z M206.9,25.6c-1.7,0-2.2,1.1-2.3,2.7h4.6C209.2,26.5,208.6,25.6,206.9,25.6z"
id="path65" /><path
class="st2"
d="M217.1,34.3c-1,0-2-0.3-2.8-1.1c-0.9-0.9-1.2-2.3-1.2-4c0-1.6,0.4-3.2,1.6-4.2c0.9-0.7,2-0.9,3.3-0.9 c0.7,0,1.5,0.1,2.3,0.2V26c-0.7-0.1-1.4-0.1-2.1-0.1c-2.1,0-3,1.1-3,3.4c0,2,0.8,3.3,2.6,3.3c0.8,0,1.8-0.3,2.7-0.5v1.6 C219.3,34,218.2,34.3,217.1,34.3z"
id="path67" /></g><g
class="st5"
id="g97"><path
class="st2"
d="M98.3,52.2v6h-3.2V42.4h10.6v2.6h-7.4v4.7h6.4v2.5H98.3z"
id="path71" /><path
class="st2"
d="M108.4,58.1V46.5h2.5l0.1,0.7c1.6-0.6,2.7-1.1,4.2-1.1c0.1,0,0.2,0,0.3,0v2.6c-0.3,0-0.6,0-0.8,0 c-1.1,0-2.1,0.2-3.4,0.7v8.7H108.4z"
id="path73" /><path
class="st2"
d="M124.5,58.1l-0.1-0.6c-1.5,0.5-2.8,0.9-4.3,0.9c-1,0-2-0.3-2.7-0.9c-0.8-0.7-1.1-1.5-1.1-2.8 c0-1.3,0.5-2.5,1.7-3.1c0.9-0.5,1.8-0.6,3.1-0.6c0.8,0,2,0.1,3,0.2v-0.4c0-1.7-0.7-2.4-3.2-2.4c-1,0-2.1,0.1-3.2,0.2v-2.2 c1.2-0.1,2.5-0.2,3.7-0.2c1.7,0,3.3,0.2,4.4,1.1c1.1,0.9,1.2,2.2,1.2,3.9v7H124.5z M124.1,53.1c-0.8-0.1-1.8-0.1-2.5-0.1 c-1.7,0-2.3,0.6-2.3,1.6c0,1,0.7,1.7,1.9,1.7c0.9,0,2-0.3,2.9-0.6V53.1z"
id="path75" /><path
class="st2"
d="M139.1,58.1V51c0-1.7-0.9-2.3-2.3-2.3c-0.8,0-1.7,0.2-2.9,0.6v8.8h-3V46.5h2.5l0.1,0.6 c1.5-0.5,2.9-0.9,4.3-0.9c1.2,0,2.5,0.3,3.3,1.3c0.8,0.9,1,1.9,1,3.3v7.3H139.1z"
id="path77" /><path
class="st2"
d="M149.6,58.4c-1.3,0-2.6-0.4-3.5-1.3c-1.1-1.1-1.5-2.8-1.5-4.8c0-1.9,0.5-3.9,2-5c1.1-0.9,2.5-1.1,4.1-1.1 c0.9,0,1.9,0.1,3,0.2v2.3c-0.8-0.1-1.8-0.2-2.6-0.2c-2.5,0-3.4,1.2-3.4,3.8c0,2.3,0.9,3.7,2.9,3.7c1,0,2.2-0.3,3.3-0.6v2.2 C152.5,58.1,151,58.4,149.6,58.4z"
id="path79" /><path
class="st2"
d="M160.6,58.4c-1.3,0-2.8-0.3-3.8-1.3c-1.1-1.1-1.5-2.8-1.5-4.8c0-1.9,0.5-3.7,1.7-4.9c1-0.9,2.3-1.2,4-1.2 c1.3,0,2.7,0.3,3.8,1.2c1.5,1.3,1.6,3.1,1.6,5.6h-8.1c0.1,2.2,1.1,3.2,3.2,3.2c1.4,0,2.9-0.3,4.5-0.6v2.1 C164.3,58,162.4,58.4,160.6,58.4z M160.9,48.1c-1.8,0-2.4,1.1-2.5,2.9h5.1C163.4,49,162.7,48.1,160.9,48.1z"
id="path81" /><path
class="st2"
d="M175,58.4c-1.6,0-3.4-0.5-4.6-1.8c-1.5-1.5-2.1-3.7-2.1-6.4c0-2.5,0.7-5.2,2.7-6.7c1.5-1.2,3.4-1.5,5.4-1.5 c1.2,0,2.4,0.1,3.8,0.3V45c-1.1-0.1-2.4-0.2-3.5-0.2c-3.8,0-5.1,2-5.1,5.5c0,3.3,1.3,5.5,4.3,5.5c1.4,0,3.2-0.5,4.6-0.9v2.6 C178.7,58,176.8,58.4,175,58.4z"
id="path83" /><path
class="st2"
d="M184.2,57.2c-1.2-1-1.8-2.7-1.8-4.9s0.5-3.9,1.8-4.9c1.1-1,2.6-1.2,4.2-1.2c1.6,0,3,0.3,4.2,1.2 c1.2,1,1.8,2.7,1.8,4.9c0,2.1-0.5,3.9-1.8,4.9c-1.1,1-2.6,1.2-4.2,1.2C186.8,58.4,185.4,58.2,184.2,57.2z M191.3,52.4 c0-2.6-0.9-3.9-2.9-3.9c-2.1,0-2.9,1.2-2.9,3.8c0,2.6,0.9,3.9,2.9,3.9C190.6,56.2,191.3,55,191.3,52.4z"
id="path85" /><path
class="st2"
d="M205.4,58.1V51c0-1.7-0.9-2.3-2.3-2.3c-0.8,0-1.7,0.2-2.9,0.6v8.8h-3V46.5h2.5l0.1,0.6 c1.5-0.5,2.9-0.9,4.3-0.9c1.2,0,2.5,0.3,3.3,1.3c0.8,0.9,1,1.9,1,3.3v7.3H205.4z"
id="path87" /><path
class="st2"
d="M220.3,58.1V51c0-1.7-0.9-2.3-2.3-2.3c-0.8,0-1.7,0.2-2.9,0.6v8.8h-3V46.5h2.5l0.1,0.6 c1.5-0.5,2.9-0.9,4.3-0.9c1.2,0,2.5,0.3,3.3,1.3c0.8,0.9,1,1.9,1,3.3v7.3H220.3z"
id="path89" /><path
class="st2"
d="M231.2,58.4c-1.3,0-2.8-0.3-3.8-1.3c-1.1-1.1-1.5-2.8-1.5-4.8c0-1.9,0.5-3.7,1.7-4.9c1-0.9,2.3-1.2,4-1.2 c1.3,0,2.7,0.3,3.8,1.2c1.5,1.3,1.6,3.1,1.6,5.6H229c0.1,2.2,1.1,3.2,3.2,3.2c1.4,0,2.9-0.3,4.5-0.6v2.1 C234.9,58,233,58.4,231.2,58.4z M231.5,48.1c-1.8,0-2.4,1.1-2.5,2.9h5.1C234,49,233.3,48.1,231.5,48.1z"
id="path91" /><path
class="st2"
d="M244,58.4c-1.3,0-2.6-0.4-3.5-1.3c-1.1-1.1-1.5-2.8-1.5-4.8c0-1.9,0.5-3.9,2-5c1.1-0.9,2.5-1.1,4.1-1.1 c0.9,0,1.9,0.1,3,0.2v2.3c-0.8-0.1-1.8-0.2-2.6-0.2c-2.5,0-3.4,1.2-3.4,3.8c0,2.3,0.9,3.7,2.9,3.7c1,0,2.2-0.3,3.3-0.6v2.2 C246.9,58.1,245.4,58.4,244,58.4z"
id="path93" /><path
class="st2"
d="M255.1,58.4c-1.2,0-2.4-0.3-3.1-1.7c-0.4-0.8-0.6-1.9-0.6-3.4v-4.6h-1.8v-2.3h1.8l0.3-3.5h2.7v3.5h3.3v2.3 h-3.3v4.2c0,0.8,0,1.5,0.2,2.1c0.2,0.8,0.7,1.1,1.6,1.1c0.5,0,1.1-0.1,1.7-0.2V58C256.8,58.2,255.9,58.4,255.1,58.4z"
id="path95" /></g></g></svg>

Before

Width:  |  Height:  |  Size: 16 KiB

View File

@ -1,22 +0,0 @@
{% load staticfiles %}
{% load i18n %}
<link rel="stylesheet" type="text/css" href="{% static 'authentic2_auth_fc/css/fc.css' %}">
<div id="fc-registration-user-info">
<h3>{% trans "Create your account with FranceConnect" %}</h3>
<p class="certified">
<span class="fc-user-full-name">{{ fc_user_info.given_name }} {{ fc_user_info.family_name }}</span>
{% if fc_user_info.email %}<span class="fc-user-email">{{ fc_user_info.email }}</span>{% endif %}
</p>
</div>
<div id="fc-button-wrapper">
<div id="fc-button">
<a href="{{ registration_url }}"
class="button connexion{% if popup %} js-fc-popup{% endif %}">
</a>
</div>
</div>
{% include "authentic2_auth_fc/explanation.html" %}
{% if popup %}<script src="{% static 'authentic2_auth_fc/js/fc.js' %}" type="text/javascript"></script>{% endif %}

View File

@ -1,18 +0,0 @@
{% load staticfiles %}
{% load i18n %}
{% block registration %}
<link rel="stylesheet" type="text/css" href="{% static 'authentic2_auth_fc/css/fc.css' %}"/>
<div id="fc-button-wrapper">
<div id="fc-button">
<a href="{{ login_url }}"
class="button connexion{% if popup %} js-fc-popup{% endif %}">
<div>
<img alt="{% trans 'Register with FranceConnect' %}" src="{% static "authentic2_auth_fc/img/FC-register-button.svg" %}">
</div>
</a>
</div>
</div>
{% include "authentic2_auth_fc/explanation.html" %}
{% if popup %}<script src="{% static 'authentic2_auth_fc/js/fc.js' %}" type="text/javascript"></script>{% endif %}
{% endblock %}

View File

@ -25,6 +25,5 @@ fcpatterns = [
urlpatterns = [
url(r'^fc/', include(fcpatterns)),
url(r'^accounts/fc/register/$', views.registration, name='fc-registration'),
url(r'^accounts/fc/unlink/$', views.unlink, name='fc-unlink'),
]

View File

@ -43,6 +43,7 @@ except ImportError:
from authentic2 import app_settings as a2_app_settings
from authentic2 import constants, hooks
from authentic2 import models as a2_models
from authentic2 import utils as a2_utils
from authentic2.a2_rbac.utils import get_default_ou
from authentic2.forms.passwords import SetPasswordForm
@ -391,7 +392,6 @@ class LoginOrLinkView(PopupViewMixin, FcOAuthSessionViewMixin, View):
return self.redirect(request)
def get(self, request, *args, **kwargs):
registration = True if 'registration' in request.GET else False
'''Request an access grant code and associate it to the current user'''
self.service = get_service_from_request(request)
if request.user.is_authenticated:
@ -417,15 +417,27 @@ class LoginOrLinkView(PopupViewMixin, FcOAuthSessionViewMixin, View):
default_ou = get_default_ou()
email_is_unique = a2_app_settings.A2_EMAIL_IS_UNIQUE or default_ou.email_is_unique
user = a2_utils.authenticate(request, sub=self.sub, user_info=self.user_info, token=self.token)
email_present_and_unique = self.user_info.get('email') and email_is_unique
user_filter = {}
if email_present_and_unique:
user_filter = {'email__iexact': self.user_info['email']}
if not a2_app_settings.A2_EMAIL_IS_UNIQUE and default_ou.email_is_unique:
user_filter['ou'] = default_ou
user = a2_utils.authenticate(
request, sub=self.sub, user_info=self.user_info, token=self.token, user_filter=user_filter
)
# ignore user if sub is not matching and let the code below handle it
if not user.fc_accounts.filter(sub=self.sub).exists():
user = None
if user:
self.fc_account = user.fc_accounts.get(order=0)
if not user and self.user_info.get('email') and email_is_unique:
if not user and email_present_and_unique:
email = self.user_info['email']
User = get_user_model()
qs = User.objects.filter(email__iexact=email)
if not a2_app_settings.A2_EMAIL_IS_UNIQUE and default_ou.email_is_unique:
qs = qs.filter(ou=default_ou)
qs = User.objects.filter(**user_filter)
if qs.exists():
# there should not be multiple accounts with the same mail
@ -450,7 +462,11 @@ class LoginOrLinkView(PopupViewMixin, FcOAuthSessionViewMixin, View):
'event', name='fc-link', user=user, sub=self.sub, request=request
)
user = a2_utils.authenticate(
request=request, sub=self.sub, user_info=self.user_info, token=self.token
request=request,
sub=self.sub,
user_info=self.user_info,
token=self.token,
user_filter=user_filter,
)
else:
messages.warning(
@ -474,68 +490,35 @@ class LoginOrLinkView(PopupViewMixin, FcOAuthSessionViewMixin, View):
self.fc_account.save(update_fields=['token'])
self.update_user_info()
self.logger.info('logged in using fc sub %s', self.sub)
# redirect to account edit page if any required attribute is missing
data = utils.get_mapped_attributes_flat(request)
required_attributes = a2_models.Attribute.objects.filter(required=True).values_list(
'name', flat=True
)
required = list(a2_app_settings.A2_REGISTRATION_REQUIRED_FIELDS) + list(required_attributes)
missing = set(required) - set(data)
if missing:
messages.warning(
request,
_('The following fields are mandatory for account creation: %s') % ', '.join(missing),
)
return a2_utils.redirect(request, 'profile_edit', keep_params=True)
return self.redirect(request)
else:
params = {}
if self.service:
set_service_ref(params, self.service)
if registration:
return self.redirect_and_come_back(
request, a2_utils.make_url('fc-registration', params=params), params=params
)
else:
messages.info(
request, _('If you already have an account, please log in, else ' 'create your account.')
)
login_params = params.copy()
if not app_settings.show_button_quick_account_creation:
login_params['nofc'] = 1
login_url = a2_utils.make_url(settings.LOGIN_URL, params=login_params)
return self.redirect_and_come_back(request, login_url, params=params)
class RegistrationView(PopupViewMixin, LoggerMixin, View):
def get(self, request, *args, **kwargs):
data = utils.get_mapped_attributes_flat(request)
data['no_password'] = True
if app_settings.auto_register:
data['confirm_data'] = 'required'
else:
data['confirm_data'] = True
redirect_to = request.GET.get(REDIRECT_FIELD_NAME, '')
if not is_safe_url(url=redirect_to, allowed_hosts=request.get_host()):
redirect_to = resolve_url(settings.LOGIN_REDIRECT_URL)
# Prevent errors when redirect_to does not contain fc-login-or-link view
parsed_redirect_to = urllib.parse.urlparse(redirect_to)
if parsed_redirect_to.path == reverse('fc-login-or-link'):
redirect_to = urllib.parse.parse_qs(parsed_redirect_to.query).get(
REDIRECT_FIELD_NAME, [a2_utils.make_url('auth_homepage')]
)[0]
params = {
REDIRECT_FIELD_NAME: redirect_to,
}
service = get_service_from_request(request)
if service:
set_service_ref(params, service)
if self.get_in_popup():
params['popup'] = ''
redirect_to = a2_utils.make_url('fc-login-or-link', params=params)
if 'email' not in data:
data[REDIRECT_FIELD_NAME] = redirect_to
messages.warning(request, _("FranceConnect didn't provide your email address, please do."))
return HttpResponseRedirect(
"{}?token={}".format(reverse('registration_register'), signing.dumps(data))
messages.info(
request, _('If you already have an account, please log in, else ' 'create your account.')
)
data['valid_email'] = False
data['franceconnect'] = True
data['authentication_method'] = 'france-connect'
if service:
set_service_ref(data, service)
activation_url = a2_utils.build_activation_url(request, next_url=redirect_to, **data)
return HttpResponseRedirect(activation_url)
login_params = params.copy()
if not app_settings.show_button_quick_account_creation:
login_params['nofc'] = 1
login_url = a2_utils.make_url(settings.LOGIN_URL, params=login_params)
return self.redirect_and_come_back(request, login_url, params=params)
class UnlinkView(LoggerMixin, FormView):
@ -607,7 +590,6 @@ class UnlinkView(LoggerMixin, FormView):
login_or_link = LoginOrLinkView.as_view()
registration = RegistrationView.as_view()
unlink = UnlinkView.as_view()

View File

@ -63,16 +63,8 @@ def test_login_autorun(settings, app, franceconnect):
assert response['Location'] == reverse('fc-login-or-link')
def test_no_create(app, franceconnect):
response = app.get('/login/?service=portail&next=/idp/')
response = response.click(href='callback')
franceconnect.handle_authorization(app, response.location, status=302)
assert User.objects.count() == 0
def test_create(settings, app, franceconnect, hooks):
# test direct creation
settings.A2_FC_CREATE = True
response = app.get('/login/?service=portail&next=/idp/')
response = response.click(href='callback')
@ -230,74 +222,20 @@ def test_no_password_with_fc_account_can_reset_password(app, db, mailoutbox):
assert '_auth_user_id' in app.session
def test_registration1(settings, app, franceconnect, caplog, hooks):
response = franceconnect.login_with_fc_fixed_params(app)
def test_login_with_missing_required_attributes(settings, app, franceconnect):
settings.A2_REGISTRATION_REQUIRED_FIELDS = ['title']
assert User.objects.count() == 0
assert path(response.location) == '/login/'
response = response.follow()
response = response.click(href='/accounts/fc/register')
response.location.startswith('http://testserver/accounts/activate/')
assert User.objects.count() == 0
response = response.follow()
assert response.location.startswith('/fc/callback/')
# a new user has been created
assert User.objects.count() == 1
# but no FcAccount
assert models.FcAccount.objects.count() == 0
# we must be connected
assert app.session['_auth_user_id']
# hook must have been called
assert hooks.calls['event'][0]['kwargs']['service'] == 'portail'
response = response.follow()
# a new redirect to FC is done
response = franceconnect.handle_authorization(app, response.location)
# FcAccount now exists
assert models.FcAccount.objects.count() == 1
user = User.objects.get()
assert user.verified_attributes.first_name == 'Ÿuñe'
assert user.verified_attributes.last_name == 'Frédérique'
response = app.get('/accounts/')
response = response.click('Delete link')
response.form.set('new_password1', 'ikKL1234')
response.form.set('new_password2', 'ikKL1234')
response = response.form.submit(name='unlink')
assert models.FcAccount.objects.count() == 0
response = franceconnect.handle_logout(app, response.location)
assert path(response.location) == '/accounts/'
response = response.follow()
assert 'The link with the FranceConnect account has been deleted' in response
def test_registration2(settings, app, franceconnect, hooks):
response = app.get('/login/?service=portail&next=/idp/')
response = response.click("Register")
response = response.click(href='callback')
franceconnect.callback_params['registration'] = ''
response = franceconnect.handle_authorization(app, response.location)
assert User.objects.count() == 0
assert path(response.location) == '/accounts/fc/register/'
response = response.follow()
response.location.startswith('http://testserver/accounts/activate/')
response = response.follow()
assert path(response.location) == '/accounts/edit/'
assert User.objects.count() == 1
user = User.objects.get()
assert user.verified_attributes.first_name is None
assert user.verified_attributes.last_name is None
assert hooks.calls['event'][0]['kwargs']['service'] == 'portail'
assert hooks.calls['event'][1]['kwargs']['service'] == 'portail'
# we must be connected
assert app.session['_auth_user_id']
response = response.follow()
del franceconnect.callback_params['registration']
response = franceconnect.handle_authorization(app, response.location)
user = User.objects.get()
assert user.verified_attributes.first_name == 'Ÿuñe'
assert user.verified_attributes.last_name == 'Frédérique'
assert models.FcAccount.objects.count() == 1
assert 'The following fields are mandatory for account creation: title' in app.cookies['messages']
def test_can_change_password(settings, app, franceconnect):