2016-02-13 09:56:55 +01:00
|
|
|
# chrono - agendas system
|
|
|
|
# Copyright (C) 2016 Entr'ouvert
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify it
|
|
|
|
# under the terms of the GNU Affero General Public License as published
|
|
|
|
# by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-07-22 14:53:26 +02:00
|
|
|
from django.conf import settings
|
2016-02-13 09:56:55 +01:00
|
|
|
from django.contrib.auth import logout as auth_logout
|
|
|
|
from django.contrib.auth import views as auth_views
|
|
|
|
from django.http import HttpResponseRedirect
|
|
|
|
from django.shortcuts import resolve_url
|
2018-03-25 11:26:47 +02:00
|
|
|
from django.utils.six.moves.urllib.parse import quote
|
2016-02-13 09:56:55 +01:00
|
|
|
|
2016-07-22 14:53:26 +02:00
|
|
|
if 'mellon' in settings.INSTALLED_APPS:
|
2016-02-13 09:56:55 +01:00
|
|
|
from mellon.utils import get_idps
|
2016-07-22 14:53:26 +02:00
|
|
|
else:
|
2016-02-13 09:56:55 +01:00
|
|
|
get_idps = lambda: []
|
|
|
|
|
|
|
|
|
2019-10-29 15:36:31 +01:00
|
|
|
class LoginView(auth_views.LoginView):
|
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
|
|
if any(get_idps()):
|
|
|
|
if 'next' not in request.GET:
|
|
|
|
return HttpResponseRedirect(resolve_url('mellon_login'))
|
|
|
|
return HttpResponseRedirect(resolve_url('mellon_login') + '?next='
|
|
|
|
+ quote(request.GET.get('next')))
|
|
|
|
return super(LoginView, self).dispatch(request, *args, **kwargs)
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
login = LoginView.as_view()
|
|
|
|
|
2016-02-13 09:56:55 +01:00
|
|
|
|
|
|
|
def logout(request, next_page=None):
|
|
|
|
if any(get_idps()):
|
|
|
|
return HttpResponseRedirect(resolve_url('mellon_logout'))
|
|
|
|
auth_logout(request)
|
|
|
|
if next_page is not None:
|
|
|
|
next_page = resolve_url(next_page)
|
|
|
|
else:
|
|
|
|
next_page = '/'
|
|
|
|
return HttpResponseRedirect(next_page)
|
|
|
|
|
|
|
|
def homepage(request, *args, **kwargs):
|
|
|
|
return HttpResponseRedirect(resolve_url('chrono-manager-homepage'))
|