|
|
|
@ -25,14 +25,10 @@ def home(request): |
|
|
|
""" |
|
|
|
This is the homepage |
|
|
|
""" |
|
|
|
# HTTP_SM_USER is available on both unsecure and secure pages. |
|
|
|
# If it has a value then we know the user is logged into BCeID/siteminder |
|
|
|
siteminder_is_authenticated = request.META.get('HTTP_SM_USER', '') != '' |
|
|
|
|
|
|
|
# if the user is returning from BCeID registration, then log them in to the site |
|
|
|
if siteminder_is_authenticated and request.session.get('went_to_register', False): |
|
|
|
if request.user.is_authenticated and request.session.get('went_to_register', False): |
|
|
|
request.session['went_to_register'] = False |
|
|
|
return redirect(settings.PROXY_BASE_URL + settings.FORCE_SCRIPT_NAME[:-1] + '/login') |
|
|
|
return redirect('oidc_authentication_init') |
|
|
|
|
|
|
|
return render(request, 'intro.html', context={'hide_nav': True}) |
|
|
|
|
|
|
|
@ -115,36 +111,14 @@ def register_sc(request): |
|
|
|
request.session['went_to_register'] = True |
|
|
|
return redirect(settings.REGISTER_BCSC_URL) |
|
|
|
|
|
|
|
def login(request): |
|
|
|
""" |
|
|
|
This page is proxy-protected by Siteminder. Users who are not |
|
|
|
logged into BCeID will get a login page. Users who are logged into |
|
|
|
BCeID will be redirected to the dashboard |
|
|
|
""" |
|
|
|
if settings.DEPLOYMENT_TYPE in ['localdev', 'minishift'] and not request.session.get('fake_bceid_guid'): |
|
|
|
return redirect(settings.PROXY_BASE_URL + settings.FORCE_SCRIPT_NAME[:-1] + '/bceid') |
|
|
|
|
|
|
|
def signin(request): |
|
|
|
if not request.user.is_authenticated: |
|
|
|
# Fix for weird siteminder behaviour...... |
|
|
|
# If a user is logged into an IDIR then they can see the login page but |
|
|
|
# the SMGOV headers are missing. If this is the case, then log them out |
|
|
|
# of their IDIR, and redirect them back to here again.... |
|
|
|
|
|
|
|
# FUTURE DEV NOTE: The DC elements of HTTP_SM_USERDN header will tell us |
|
|
|
# exactly how the user is logged in. But it doesn't seem like a very |
|
|
|
# good idea at this time to rely on this magic string. e.g. CN=Smith\, |
|
|
|
# John,OU=Users,OU=Attorney General,OU=BCGOV,DC=idir,DC=BCGOV |
|
|
|
|
|
|
|
if request.GET.get('noretry', '') != 'true': |
|
|
|
return redirect(settings.LOGOUT_URL_TEMPLATE % ( |
|
|
|
settings.PROXY_BASE_URL, |
|
|
|
settings.FORCE_SCRIPT_NAME[:-1] + '/login%3Fnoretry=true')) |
|
|
|
|
|
|
|
return render(request, '407.html') |
|
|
|
|
|
|
|
if timezone.now() - request.user.last_login > datetime.timedelta(minutes=1): |
|
|
|
request.user.last_login = timezone.now() |
|
|
|
request.user.save() |
|
|
|
## I think Django might be doing this automatically now that we have switched to mozilla-django-oidc? |
|
|
|
#if timezone.now() - request.user.last_login > datetime.timedelta(minutes=1): |
|
|
|
# request.user.last_login = timezone.now() |
|
|
|
# request.user.save() |
|
|
|
|
|
|
|
copy_session_to_db(request, request.user) |
|
|
|
|
|
|
|
|