"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "openstack_auth/views.py" between
horizon-18.6.2.tar.gz and horizon-18.6.3.tar.gz

About: OpenStack Horizon (Optional Service: Dashboard) provides a web-based self-service portal to interact with underlying OpenStack services, such as launching an instance, assigning IP addresses and configuring access controls.
The "Victoria" series (maintained release).

views.py  (horizon-18.6.2):views.py  (horizon-18.6.3)
skipping to change at line 66 skipping to change at line 66
csrf.REASON_BAD_TOKEN, csrf.REASON_BAD_TOKEN,
csrf.REASON_MALFORMED_REFERER, csrf.REASON_MALFORMED_REFERER,
csrf.REASON_INSECURE_REFERER]: csrf.REASON_INSECURE_REFERER]:
reason = "" reason = ""
else: else:
reason += " " reason += " "
reason += str(_("Cookies may be turned off. " reason += str(_("Cookies may be turned off. "
"Make sure cookies are enabled and try again.")) "Make sure cookies are enabled and try again."))
return reason return reason
def set_logout_reason(res, msg):
msg = msg.encode('unicode_escape').decode('ascii')
res.set_cookie('logout_reason', msg, max_age=10)
# TODO(stephenfin): Migrate to CBV # TODO(stephenfin): Migrate to CBV
@sensitive_post_parameters() @sensitive_post_parameters()
@csrf_protect @csrf_protect
@never_cache @never_cache
def login(request): def login(request):
"""Logs a user in using the :class:`~openstack_auth.forms.Login` form.""" """Logs a user in using the :class:`~openstack_auth.forms.Login` form."""
# If the user enabled websso and the default redirect # If the user enabled websso and the default redirect
# redirect to the default websso url # redirect to the default websso url
if (request.method == 'GET' and settings.WEBSSO_ENABLED and if (request.method == 'GET' and settings.WEBSSO_ENABLED and
skipping to change at line 122 skipping to change at line 126
if requested_region in regions and requested_region != current_region: if requested_region in regions and requested_region != current_region:
initial.update({'region': requested_region}) initial.update({'region': requested_region})
if request.method == "POST": if request.method == "POST":
form = functional.curry(forms.Login) form = functional.curry(forms.Login)
else: else:
form = functional.curry(forms.Login, initial=initial) form = functional.curry(forms.Login, initial=initial)
choices = settings.WEBSSO_CHOICES choices = settings.WEBSSO_CHOICES
reason = get_csrf_reason(request.GET.get('csrf_failure')) reason = get_csrf_reason(request.GET.get('csrf_failure'))
logout_reason = request.COOKIES.get(
'logout_reason', '').encode('ascii').decode('unicode_escape')
logout_status = request.COOKIES.get('logout_status')
extra_context = { extra_context = {
'redirect_field_name': auth.REDIRECT_FIELD_NAME, 'redirect_field_name': auth.REDIRECT_FIELD_NAME,
'csrf_failure': reason, 'csrf_failure': reason,
'show_sso_opts': settings.WEBSSO_ENABLED and len(choices) > 1, 'show_sso_opts': settings.WEBSSO_ENABLED and len(choices) > 1,
'classes': { 'classes': {
'value': '', 'value': '',
'single_value': '', 'single_value': '',
'label': '', 'label': '',
}, },
'logout_reason': logout_reason,
'logout_status': logout_status,
} }
if request.is_ajax(): if request.is_ajax():
template_name = 'auth/_login.html' template_name = 'auth/_login.html'
extra_context['hide'] = True extra_context['hide'] = True
else: else:
template_name = 'auth/login.html' template_name = 'auth/login.html'
try: try:
res = django_auth_views.LoginView.as_view( res = django_auth_views.LoginView.as_view(
template_name=template_name, template_name=template_name,
redirect_field_name=auth.REDIRECT_FIELD_NAME, redirect_field_name=auth.REDIRECT_FIELD_NAME,
form_class=form, form_class=form,
extra_context=extra_context, extra_context=extra_context,
redirect_authenticated_user=False)(request) redirect_authenticated_user=False)(request)
except exceptions.KeystonePassExpiredException as exc: except exceptions.KeystonePassExpiredException as exc:
res = django_http.HttpResponseRedirect( res = django_http.HttpResponseRedirect(
reverse('password', args=[exc.user_id])) reverse('password', args=[exc.user_id]))
msg = _("Your password has expired. Please set a new password.") msg = _("Your password has expired. Please set a new password.")
res.set_cookie('logout_reason', msg, max_age=10) set_logout_reason(res, msg)
# Save the region in the cookie, this is used as the default # Save the region in the cookie, this is used as the default
# selected region next time the Login form loads. # selected region next time the Login form loads.
if request.method == "POST": if request.method == "POST":
utils.set_response_cookie(res, 'login_region', utils.set_response_cookie(res, 'login_region',
request.POST.get('region', '')) request.POST.get('region', ''))
utils.set_response_cookie(res, 'login_domain', utils.set_response_cookie(res, 'login_domain',
request.POST.get('domain', '')) request.POST.get('domain', ''))
# Set the session data here because django's session key rotation # Set the session data here because django's session key rotation
skipping to change at line 200 skipping to change at line 209
token = request.POST.get('token') token = request.POST.get('token')
try: try:
request.user = auth.authenticate(request, auth_url=auth_url, request.user = auth.authenticate(request, auth_url=auth_url,
token=token) token=token)
except exceptions.KeystoneAuthException as exc: except exceptions.KeystoneAuthException as exc:
if settings.WEBSSO_DEFAULT_REDIRECT: if settings.WEBSSO_DEFAULT_REDIRECT:
res = django_http.HttpResponseRedirect(settings.LOGIN_ERROR) res = django_http.HttpResponseRedirect(settings.LOGIN_ERROR)
else: else:
msg = 'Login failed: %s' % exc msg = 'Login failed: %s' % exc
res = django_http.HttpResponseRedirect(settings.LOGIN_URL) res = django_http.HttpResponseRedirect(settings.LOGIN_URL)
res.set_cookie('logout_reason', msg, max_age=10) set_logout_reason(res, msg)
return res return res
auth_user.set_session_from_user(request, request.user) auth_user.set_session_from_user(request, request.user)
auth.login(request, request.user) auth.login(request, request.user)
if request.session.test_cookie_worked(): if request.session.test_cookie_worked():
request.session.delete_test_cookie() request.session.delete_test_cookie()
return django_http.HttpResponseRedirect(settings.LOGIN_REDIRECT_URL) return django_http.HttpResponseRedirect(settings.LOGIN_REDIRECT_URL)
# TODO(stephenfin): Migrate to CBV # TODO(stephenfin): Migrate to CBV
def logout(request, login_url=None, **kwargs): def logout(request, login_url=None, **kwargs):
skipping to change at line 368 skipping to change at line 377
messages.error(request, msg) messages.error(request, msg)
if unscoped_auth_ref: if unscoped_auth_ref:
try: try:
request.user = auth.authenticate( request.user = auth.authenticate(
request, auth_url=unscoped_auth.auth_url, request, auth_url=unscoped_auth.auth_url,
token=unscoped_auth_ref.auth_token) token=unscoped_auth_ref.auth_token)
except exceptions.KeystoneAuthException as exc: except exceptions.KeystoneAuthException as exc:
msg = 'Keystone provider switch failed: %s' % exc msg = 'Keystone provider switch failed: %s' % exc
res = django_http.HttpResponseRedirect(settings.LOGIN_URL) res = django_http.HttpResponseRedirect(settings.LOGIN_URL)
res.set_cookie('logout_reason', msg, max_age=10) set_logout_reason(res, msg)
return res return res
auth.login(request, request.user) auth.login(request, request.user)
auth_user.set_session_from_user(request, request.user) auth_user.set_session_from_user(request, request.user)
request.session['keystone_provider_id'] = keystone_provider request.session['keystone_provider_id'] = keystone_provider
request.session['keystone_providers'] = keystone_providers request.session['keystone_providers'] = keystone_providers
request.session['k2k_base_unscoped_token'] = base_token request.session['k2k_base_unscoped_token'] = base_token
request.session['k2k_auth_url'] = k2k_auth_url request.session['k2k_auth_url'] = k2k_auth_url
message = ( message = (
_('Switch to Keystone Provider "%(keystone_provider)s" ' _('Switch to Keystone Provider "%(keystone_provider)s" '
'successful.') % {'keystone_provider': keystone_provider}) 'successful.') % {'keystone_provider': keystone_provider})
skipping to change at line 397 skipping to change at line 406
form_class = forms.Password form_class = forms.Password
success_url = settings.LOGIN_URL success_url = settings.LOGIN_URL
def get_initial(self): def get_initial(self):
return {'user_id': self.kwargs['user_id']} return {'user_id': self.kwargs['user_id']}
def form_valid(self, form): def form_valid(self, form):
# We have no session here, so regular messages don't work. # We have no session here, so regular messages don't work.
msg = _('Password changed. Please log in to continue.') msg = _('Password changed. Please log in to continue.')
res = django_http.HttpResponseRedirect(self.success_url) res = django_http.HttpResponseRedirect(self.success_url)
res.set_cookie('logout_reason', msg, max_age=10) set_logout_reason(res, msg)
return res return res
 End of changes. 7 change blocks. 
4 lines changed or deleted 13 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)