2012-02-04 17:40:31 -06:00
|
|
|
# Copyright 2012 Nebula, Inc.
|
2011-07-03 20:55:00 -07:00
|
|
|
#
|
2011-01-12 13:43:31 -08:00
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License. You may obtain
|
|
|
|
# a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
# under the License.
|
2011-07-03 20:55:00 -07:00
|
|
|
|
2015-12-03 12:34:01 -08:00
|
|
|
from django.conf import settings
|
2012-10-04 15:43:40 -07:00
|
|
|
from django import shortcuts
|
2014-07-29 16:57:39 +02:00
|
|
|
import django.views.decorators.vary
|
2011-10-31 11:31:05 -07:00
|
|
|
|
|
|
|
import horizon
|
2014-04-11 16:26:35 -06:00
|
|
|
from horizon import base
|
2015-02-05 09:25:24 +00:00
|
|
|
from horizon import exceptions
|
2015-12-03 12:34:01 -08:00
|
|
|
from horizon import notifications
|
|
|
|
|
|
|
|
|
|
|
|
MESSAGES_PATH = getattr(settings, 'MESSAGES_PATH', None)
|
2011-01-15 01:16:25 -08:00
|
|
|
|
2012-03-26 18:08:48 -07:00
|
|
|
|
2012-10-04 15:43:40 -07:00
|
|
|
def get_user_home(user):
|
2017-01-27 12:27:39 +00:00
|
|
|
try:
|
|
|
|
token = user.token
|
|
|
|
except AttributeError:
|
|
|
|
raise exceptions.NotAuthenticated()
|
|
|
|
# Domain Admin, Project Admin will default to identity
|
|
|
|
if token.project.get('id') is None or user.is_superuser:
|
2014-04-11 16:26:35 -06:00
|
|
|
try:
|
2017-01-27 12:27:39 +00:00
|
|
|
dashboard = horizon.get_dashboard('identity')
|
2014-04-11 16:26:35 -06:00
|
|
|
except base.NotRegistered:
|
|
|
|
pass
|
2017-01-27 12:27:39 +00:00
|
|
|
else:
|
2014-04-11 16:26:35 -06:00
|
|
|
dashboard = horizon.get_default_dashboard()
|
|
|
|
|
|
|
|
return dashboard.get_absolute_url()
|
2012-03-26 18:08:48 -07:00
|
|
|
|
2011-01-12 13:43:31 -08:00
|
|
|
|
2014-07-29 16:57:39 +02:00
|
|
|
@django.views.decorators.vary.vary_on_cookie
|
2012-10-04 15:43:40 -07:00
|
|
|
def splash(request):
|
2015-02-05 09:25:24 +00:00
|
|
|
if not request.user.is_authenticated():
|
|
|
|
raise exceptions.NotAuthenticated()
|
|
|
|
|
|
|
|
response = shortcuts.redirect(horizon.get_user_home(request.user))
|
2014-11-20 08:49:09 -07:00
|
|
|
if 'logout_reason' in request.COOKIES:
|
|
|
|
response.delete_cookie('logout_reason')
|
2016-09-12 15:22:20 +05:30
|
|
|
if 'logout_status' in request.COOKIES:
|
|
|
|
response.delete_cookie('logout_status')
|
2015-12-03 12:34:01 -08:00
|
|
|
# Display Message of the Day message from the message files
|
|
|
|
# located in MESSAGES_PATH
|
|
|
|
if MESSAGES_PATH:
|
|
|
|
notifications.process_message_notification(request, MESSAGES_PATH)
|
2014-06-18 16:34:59 +05:30
|
|
|
return response
|