Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial login/logout with social auth
- Loading branch information
1 parent
f18f1f8
commit aaf40bb
Showing
8 changed files
with
51 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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"), | |||
) | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
|
|||
TWITTER_CONSUMER_KEY = "" | |||
TWITTER_CONSUMER_SECRET = "" | |||
FACEBOOK_APP_ID = "" | |||
FACEBOOK_API_SECRET = "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,6 +1,12 @@ | |||
<html> | <html> | ||
<head></head> | <head></head> | ||
<body> | <body> | ||
|
|||
{% for message in messages %} | |||
<p>{{ message }}</p> | |||
{% endfor %} | |||
|
|||
{% block main %}{% endblock %} | {% block main %}{% endblock %} | ||
|
|||
</body> | </body> | ||
</html> | </html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,5 +1,12 @@ | |||
{% extends "base.html" %} | {% extends "base.html" %} | ||
|
|
||
{% block main %} | {% 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 %} | {% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,11 +1,11 @@ | |||
|
|
||
from django.conf.urls.defaults import * | from django.conf.urls.defaults import * | ||
from django.conf import settings | from django.conf import settings | ||
from django.views.generic.simple import direct_to_template | |||
|
|
||
|
|
||
urlpatterns = patterns("", | 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("/"), | ("^%s/(?P<path>.*)$" % settings.MEDIA_URL.strip("/"), | ||
"django.views.static.serve", {"document_root": settings.MEDIA_ROOT}), | "django.views.static.serve", {"document_root": settings.MEDIA_ROOT}), | ||
) | ) |