-from django.shortcuts import render
+# mandayejs - saml reverse proxy
+# Copyright (C) 2015 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/>.
-# Create your views here.
+import json
+import os
+import subprocess
+import urlparse
+
+from django.conf import settings
+from django.contrib.auth import views as auth_views
+from django.contrib.auth import logout as auth_logout
+from django.contrib.auth.decorators import login_required
+from django.http import HttpResponseRedirect
+from django.views.generic.base import TemplateView
+
+
+def login(request, *args, **kwargs):
+ return auth_views.login(request, *args, **kwargs)
+
+def logout(request, *args, **kwargs):
+ auth_logout(request)
+ return HttpResponseRedirect('/')
+
+
+class Panel(TemplateView):
+ template_name = 'mandaye/panel.html'
+
+panel = Panel.as_view()
+
+
+class PostLogin(TemplateView):
+ template_name = 'mandaye/post-login.html'
+
+ def get_context_data(self, **kwargs):
+ context = super(PostLogin, self).get_context_data(**kwargs)
+ context['address'] = self.request.build_absolute_uri('/login'),
+ return context
+
+post_login = login_required(PostLogin.as_view())
+
+def post_login_do(request, *args, **kwargs):
+ # XXX: this should come from both configuration (address and locators) and
+ # user database (credentials)
+ login_info = {
+ 'username_locator': '#username',
+ 'username_value': settings.MANDAYE_USERNAME,
+ 'password_locator': '#password',
+ 'password_value': settings.MANDAYE_PASSWORD,
+ 'address': request.build_absolute_uri('/login'),
+ 'cookies': [],
+ }
+ phantom = subprocess.Popen(['/usr/bin/phantomjs',
+ '--ignore-ssl-errors=yes',
+ '--ssl-protocol=any',
+ os.path.join(settings.BASE_DIR, 'do_login.js')],
+ close_fds=True,
+ stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE)
+ stdout, stderr = phantom.communicate(json.dumps(login_info))
+ result = json.loads(stdout)
+ if result.get('result') != 'ok':
+ return HttpResponseRedirect('/')
+ response = HttpResponseRedirect('/')
+ for cookie in result.get('cookies'):
+ response.set_cookie(
+ key=cookie.get('name'),
+ value=cookie.get('value'),
+ path=cookie.get('path'),
+ secure=cookie.get('secure'),
+ httponly=cookie.get('httponly'),
+ )
+ return response
from django.contrib import admin
urlpatterns = patterns('',
- url(r'^_mandaye/panel$', 'mandayejs.views.panel', name='panel'),
- url(r'^_mandaye/login/$', 'mandayejs.views.login', name='auth_login'),
- url(r'^_mandaye/logout/$', 'mandayejs.views.logout', name='auth_logout'),
- url(r'^_mandaye/post-login/$', 'mandayejs.views.post_login', name='post-login'),
- url(r'^_mandaye/post-login-do/$', 'mandayejs.views.post_login_do', name='post-login-do'),
+ url(r'^_mandaye/panel$', 'mandayejs.mandaye.views.panel', name='panel'),
+ url(r'^_mandaye/login/$', 'mandayejs.mandaye.views.login', name='auth_login'),
+ url(r'^_mandaye/logout/$', 'mandayejs.mandaye.views.logout', name='auth_logout'),
+ url(r'^_mandaye/post-login/$', 'mandayejs.mandaye.views.post_login', name='post-login'),
+ url(r'^_mandaye/post-login-do/$', 'mandayejs.mandaye.views.post_login_do', name='post-login-do'),
url(r'^_mandaye/admin/', include(admin.site.urls)),
)
+++ /dev/null
-# mandayejs - saml reverse proxy
-# Copyright (C) 2015 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/>.
-
-import json
-import os
-import subprocess
-import urlparse
-
-from django.conf import settings
-from django.contrib.auth import views as auth_views
-from django.contrib.auth import logout as auth_logout
-from django.contrib.auth.decorators import login_required
-from django.http import HttpResponseRedirect
-from django.views.generic.base import TemplateView
-
-
-def login(request, *args, **kwargs):
- return auth_views.login(request, *args, **kwargs)
-
-def logout(request, *args, **kwargs):
- auth_logout(request)
- return HttpResponseRedirect('/')
-
-
-class Panel(TemplateView):
- template_name = 'mandaye/panel.html'
-
-panel = Panel.as_view()
-
-
-class PostLogin(TemplateView):
- template_name = 'mandaye/post-login.html'
-
- def get_context_data(self, **kwargs):
- context = super(PostLogin, self).get_context_data(**kwargs)
- context['address'] = self.request.build_absolute_uri('/login'),
- return context
-
-post_login = login_required(PostLogin.as_view())
-
-def post_login_do(request, *args, **kwargs):
- # XXX: this should come from both configuration (address and locators) and
- # user database (credentials)
- login_info = {
- 'username_locator': '#username',
- 'username_value': settings.MANDAYE_USERNAME,
- 'password_locator': '#password',
- 'password_value': settings.MANDAYE_PASSWORD,
- 'address': request.build_absolute_uri('/login'),
- 'cookies': [],
- }
- phantom = subprocess.Popen(['/usr/bin/phantomjs',
- '--ignore-ssl-errors=yes',
- '--ssl-protocol=any',
- os.path.join(settings.BASE_DIR, 'do_login.js')],
- close_fds=True,
- stdin=subprocess.PIPE,
- stdout=subprocess.PIPE)
- stdout, stderr = phantom.communicate(json.dumps(login_info))
- result = json.loads(stdout)
- if result.get('result') != 'ok':
- return HttpResponseRedirect('/')
- response = HttpResponseRedirect('/')
- for cookie in result.get('cookies'):
- response.set_cookie(
- key=cookie.get('name'),
- value=cookie.get('value'),
- path=cookie.get('path'),
- secure=cookie.get('secure'),
- httponly=cookie.get('httponly'),
- )
- return response