diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..858f86c --- /dev/null +++ b/templates/base.html @@ -0,0 +1,21 @@ +{# vim: set ft=djangohtml #} + + + + {{ title }} + + + {% block head_css %}{% endblock %} + + {% block head_js %}{% endblock %} + + + {% block container %} +
+ {% block body %}{% endblock %} +
+ {% endblock %} + {% block body_js %}{% endblock %} + + + diff --git a/templates/login.html b/templates/login.html new file mode 100644 index 0000000..66cb19a --- /dev/null +++ b/templates/login.html @@ -0,0 +1,34 @@ +{# vim: set ft=djangohtml #} +{% extends "base.html" %} + +{% block head_css %} + + +{% endblock %} + +{% block container %} +
+
+ +
+ + {% if error %} +
+
+
+ {{ error }} +
+
+
+ {% endif %} +
+{% endblock container %} diff --git a/urls.py b/urls.py index 980230e..00f6c56 100644 --- a/urls.py +++ b/urls.py @@ -4,10 +4,14 @@ from django.conf.urls import patterns, url, include from django.contrib import admin import re +import views + admin.autodiscover() urlpatterns = patterns('', url(r'^%s(?P.*)$' % re.escape(settings.STATIC_URL.lstrip('/')), 'django.contrib.staticfiles.views.serve', {'insecure': True}), url(r'^admin/', include(admin.site.urls)), + url(r'^login/$', views.login, name='login'), + url(r'^$', views.index, name='index'), url(r'', include('social_auth.urls')), ) diff --git a/views.py b/views.py new file mode 100644 index 0000000..724e256 --- /dev/null +++ b/views.py @@ -0,0 +1,33 @@ +from django.contrib.auth.decorators import login_required +from django.shortcuts import redirect, render_to_response +from django.template import RequestContext + + +def index(request): + '''Index page. Everyone starts here. If the user is logged in (that is, they + have a session id) return the follower_graph view. Otherwise, render the + index page.''' + if request.session.get('sessionid', False): + return follower_graph(request) + # Set a test cookie. When the user clicks the 'Login' button, test and make + # sure this cookie was set properly. + request.session.set_test_cookie() + return render_to_response('login.html') + + +def login(request): + '''Do a quick check to make sure cookies are enabled. If so, redirect to + GitHub so the user can login.''' + # Make sure the user can accept cookies. + if request.session.test_cookie_worked(): + request.session.delete_test_cookie() + return redirect('/login/github/') + else: + # Render an error -- fix your damn cookies! + return render_to_response('login.html', + { 'error': "Fix your damn cookies!" }) + + +@login_required +def follower_graph(request): + return 'Hello!'