Permalink
Browse files

Initial login/logout with social auth

  • Loading branch information...
stephenmcd committed Jul 30, 2011
1 parent f18f1f8 commit aaf40bb4044f5340c3b0653bc60310f5f45f6733
Showing with 51 additions and 4 deletions.
  1. +11 −0 core/urls.py
  2. +17 −0 core/views.py
  3. +1 −1 fabfile.py
  4. +5 −0 local_settings.py.template
  5. +1 −0 settings.py
  6. +6 −0 templates/base.html
  7. +8 −1 templates/index.html
  8. +2 −2 urls.py
View
@@ -0,0 +1,11 @@
+
+from django.conf.urls.defaults import *
+from django.conf import settings
+from django.views.generic.simple import direct_to_template
+
+urlpatterns = patterns("core.views",
+ url("^auth/logout/$", "logout", name="logout"),
+ url("^%s/$" % settings.LOGIN_REDIRECT_URL.strip("/"), "loggedin", name="loggedin"),
+ url("^$", direct_to_template, {"template": "index.html"}, name="home"),
+)
+
View
@@ -0,0 +1,17 @@
+
+from django.contrib.auth.decorators import login_required
+from django.contrib.auth import logout as auth_logout
+from django.contrib import messages
+from django.shortcuts import redirect
+
+
+def loggedin(request):
+ if request.user.is_authenticated():
+ messages.success(request, "Logged in")
+ return redirect(request.COOKIES.get("next", "home"))
+
+def logout(request):
+ if request.user.is_authenticated():
+ auth_logout(request)
+ messages.success(request, "Logged out")
+ return redirect("home")
View
@@ -30,7 +30,7 @@ def install():
def restart():
with cd(PROJECT_DIRNAME):
- run("supervisorctl restart drawnby_app")
+ sudo("supervisorctl restart drawnby_app")
def deploy():
push()
@@ -0,0 +1,5 @@
+
+TWITTER_CONSUMER_KEY = ""
+TWITTER_CONSUMER_SECRET = ""
+FACEBOOK_APP_ID = ""
+FACEBOOK_API_SECRET = ""
View
@@ -79,6 +79,7 @@
'django.contrib.auth.backends.ModelBackend',
)
+# Set these in local_settings.py
TWITTER_CONSUMER_KEY = ""
TWITTER_CONSUMER_SECRET = ""
FACEBOOK_APP_ID = ""
View
@@ -1,6 +1,12 @@
<html>
<head></head>
<body>
+
+{% for message in messages %}
+<p>{{ message }}</p>
+{% endfor %}
+
{% block main %}{% endblock %}
+
</body>
</html>
View
@@ -1,5 +1,12 @@
{% extends "base.html" %}
{% block main %}
-drawnby homepage
+{% if request.user.is_authenticated %}
+<a href="{% url logout %}">Logout</a>
+{% else %}
+Login via:<br>
+<a href="{% url begin "twitter" %}">Twitter</a> / <a href="{% url begin "facebook" %}">Facebook</a>
+{% endif %}
+
+
{% endblock %}
View
@@ -1,11 +1,11 @@
from django.conf.urls.defaults import *
from django.conf import settings
-from django.views.generic.simple import direct_to_template
urlpatterns = patterns("",
- url("^$", direct_to_template, {"template": "index.html"}, name="home"),
+ url("", include("core.urls")),
+ url("", include("social_auth.urls")),
("^%s/(?P<path>.*)$" % settings.MEDIA_URL.strip("/"),
"django.views.static.serve", {"document_root": settings.MEDIA_ROOT}),
)

0 comments on commit aaf40bb

Please sign in to comment.