]> git.0d.be Git - mandayejs.git/commitdiff
move views to app
authorFrédéric Péters <fpeters@entrouvert.com>
Sun, 22 Mar 2015 18:28:21 +0000 (19:28 +0100)
committerFrédéric Péters <fpeters@entrouvert.com>
Sun, 22 Mar 2015 18:28:21 +0000 (19:28 +0100)
mandayejs/mandaye/views.py
mandayejs/urls.py
mandayejs/views.py [deleted file]

index 91ea44a218fbd2f408430959283f0419c921093e..ff1e0260ea8ded24f0efcd455176b448315abd9e 100644 (file)
@@ -1,3 +1,85 @@
-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
index aad7578cde73463652b4b79ad7e5ca2be9ba80e4..e25b1083d75b8b52555e79d8f68da2379b1aa514 100644 (file)
@@ -18,11 +18,11 @@ from django.conf.urls import patterns, include, url
 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)),
 )
diff --git a/mandayejs/views.py b/mandayejs/views.py
deleted file mode 100644 (file)
index ff1e026..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-# 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