Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add in social auth, with yahoo, google and openid
- Loading branch information
Showing
11 changed files
with
194 additions
and
1 deletion.
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
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
Empty file.
Empty file.
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,41 @@ | |||
from account.models import Account, EmailAddress | |||
|
|||
from social_auth.models import User | |||
from social_auth.backends.exceptions import AuthException | |||
from social_auth.backends.pipeline import warn_setting | |||
from social_auth.utils import setting | |||
from social_auth.signals import socialauth_not_registered | |||
|
|||
|
|||
def create_user(backend, details, response, uid, username, user=None, *args, **kwargs): | |||
"""Create user. Depends on get_username pipeline.""" | |||
if user: | |||
return {"user": user} | |||
if not username: | |||
return None | |||
|
|||
warn_setting("SOCIAL_AUTH_CREATE_USERS", "create_user") | |||
|
|||
if not setting("SOCIAL_AUTH_CREATE_USERS", True): | |||
# Send signal for cases where tracking failed registering is useful. | |||
socialauth_not_registered.send(sender=backend.__class__, uid=uid, response=response, details=details) | |||
return None | |||
|
|||
email = details.get("email") | |||
|
|||
if EmailAddress.objects.filter(email=email): | |||
# TODO - Make this fail gracefully back to sign up | |||
message = ( | |||
"The email address provided by the external " | |||
"service is already associated with another account. Please " | |||
"log in to that account first and associate your account." | |||
) | |||
raise AuthException(backend, message) | |||
else: | |||
user = User.objects.create_user(username=username, email=email) | |||
EmailAddress.objects.add_email(user, user.email, primary=True) | |||
|
|||
return { | |||
"user": user, | |||
"is_new": True | |||
} |
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,7 @@ | |||
from django.conf.urls import patterns, url | |||
|
|||
from symposion.social_auth.views import SocialAuths | |||
|
|||
urlpatterns = patterns("", | |||
url(r"^associations/$", SocialAuths.as_view(), name="social_auth_associations"), | |||
) |
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,44 @@ | |||
from django.http import HttpResponseRedirect | |||
from django.views.generic.list import ListView | |||
from django.utils.translation import ugettext as _ | |||
|
|||
from django.contrib import messages | |||
from django.contrib.auth import REDIRECT_FIELD_NAME | |||
from django.contrib.auth.decorators import login_required | |||
|
|||
from account.mixins import LoginRequiredMixin | |||
from social_auth.decorators import dsa_view | |||
from social_auth.models import UserSocialAuth | |||
from social_auth.utils import backend_setting | |||
from social_auth.views import DEFAULT_REDIRECT | |||
|
|||
|
|||
class SocialAuths(LoginRequiredMixin, ListView): | |||
|
|||
model = UserSocialAuth | |||
|
|||
def get_queryset(self): | |||
qs = super(SocialAuths, self).get_queryset() | |||
qs = qs.filter(user=self.request.user) | |||
return qs | |||
|
|||
|
|||
@login_required | |||
@dsa_view() | |||
def disconnect(request, backend, association_id=None): | |||
associated = request.user.social_auth.count() | |||
url = request.REQUEST.get(REDIRECT_FIELD_NAME, '') or backend_setting(backend, 'SOCIAL_AUTH_DISCONNECT_REDIRECT_URL') or DEFAULT_REDIRECT | |||
|
|||
if not request.user.has_usable_password() and associated <= 1: | |||
messages.error(request, _("Cannot remove the only Social Account without first setting a Password or adding another Social Account.")) | |||
return HttpResponseRedirect(url) | |||
|
|||
usa = request.user.social_auth.get(pk=association_id) | |||
|
|||
backend.disconnect(request.user, association_id) | |||
messages.success(request, _("Removed the %(provider)s account '%(uid)s'.") % { | |||
"provider": usa.provider, | |||
"uid": usa.extra_data.get("display", usa.uid) if usa.extra_data is not None else usa.uid, | |||
}) | |||
|
|||
return HttpResponseRedirect(url) |
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,19 @@ | |||
{% load i18n %} | |||
{% load url from future %} | |||
|
|||
<h4>{% trans "Sign in with another account:" %}</h4> | |||
<ul> | |||
<li> | |||
<a href="{% url "socialauth_begin" "google" %}">Sign-in using Google</a> | |||
</li> | |||
<li> | |||
<a href="{% url "socialauth_begin" "yahoo" %}">Sign-in using Yahoo!</a> | |||
</li> | |||
</ul> | |||
|
|||
<h4>{% trans "Sign in with OpenID" %}</h4> | |||
<form action="{% url "socialauth_begin" "openid" %}" method="POST" autocapitalize="off" class"form-inline"> | |||
{% csrf_token %} | |||
<input class="openid" type="text" name="openid_identifier" placeholder="Your OpenID Identifier" /> | |||
<input type="submit" value="{% trans "Sign in" %}" class="btn btn-primary" /> | |||
</form> |
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,27 @@ | |||
{% extends "site_base.html" %} | |||
|
|||
{% load url from future %} | |||
{% load i18n %} | |||
{% load bootstrap_tags %} | |||
|
|||
{% block head_title %}{% trans "Log in" %}{% endblock %} | |||
|
|||
{% block body %} | |||
|
|||
<form method="POST" action="{% url "account_login" %}" autocapitalize="off" class="form-horizontal"{% if form.is_multipart %} enctype="multipart/form-data"{% endif %}> | |||
<legend>{% trans "Log in to an existing account" %}</legend> | |||
{% csrf_token %} | |||
{{ form|as_bootstrap }} | |||
{% if redirect_field_value %} | |||
<input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}" /> | |||
{% endif %} | |||
<div class="form-actions"> | |||
<a href="{% url "account_password_reset" %}" class="btn">{% trans "Forgot your password?" %}</a> | |||
<button type="submit" class="btn btn-primary">{% trans "Log in" %}</button> | |||
</div> | |||
</form> | |||
{% endblock %} | |||
|
|||
{% block sidebar %} | |||
{% include "account/_openid_sidebar.html" %} | |||
{% 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 |
---|---|---|---|
@@ -0,0 +1,27 @@ | |||
{% extends "site_base.html" %} | |||
|
|||
{% load url from future %} | |||
{% load i18n %} | |||
{% load bootstrap_tags %} | |||
|
|||
{% block head_title %}{% trans "Create an account" %}{% endblock %} | |||
|
|||
{% block body %} | |||
<form id="signup_form" method="post" action="{% url "account_signup" %}" autocapitalize="off" class="form-horizontal"{% if form.is_multipart %} enctype="multipart/form-data"{% endif %}> | |||
<legend>{% trans "Create a new account" %}</legend> | |||
<fieldset> | |||
{% csrf_token %} | |||
{{ form|as_bootstrap }} | |||
{% if redirect_field_value %} | |||
<input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}" /> | |||
{% endif %} | |||
<div class="form-actions"> | |||
<button type="submit" class="btn btn-primary">{% trans "Create Account" %}</button> | |||
</div> | |||
</fieldset> | |||
</form> | |||
{% endblock %} | |||
|
|||
{% block sidebar %} | |||
{% include "account/_openid_sidebar.html" %} | |||
{% 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