commit
153a582cf0
31
core/auth.py
31
core/auth.py
|
@ -1,8 +1,14 @@
|
|||
import logging
|
||||
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import redirect
|
||||
from django.utils.http import urlquote
|
||||
|
||||
from social.pipeline.social_auth import associate_by_email
|
||||
from social.apps.django_app.default.models import UserSocialAuth
|
||||
from social.exceptions import AuthAlreadyAssociated
|
||||
from social.apps.django_app.middleware import SocialAuthExceptionMiddleware
|
||||
from social.exceptions import (AuthAlreadyAssociated,SocialAuthBaseException)
|
||||
from social.utils import social_logger
|
||||
|
||||
from regluit.core.models import TWITTER, FACEBOOK, UNGLUEITAR
|
||||
|
||||
|
@ -75,3 +81,26 @@ def selective_social_user(backend, uid, user=None, *args, **kwargs):
|
|||
'user': user,
|
||||
'is_new': user is None,
|
||||
'new_association': False}
|
||||
|
||||
# http://stackoverflow.com/a/19361220
|
||||
# adapting https://github.com/omab/python-social-auth/blob/v0.2.10/social/apps/django_app/middleware.py#L25
|
||||
|
||||
class SocialAuthExceptionMiddlewareWithoutMessages(SocialAuthExceptionMiddleware):
|
||||
"""
|
||||
a modification of SocialAuthExceptionMiddleware to pass backend and message without
|
||||
attempting django.messages
|
||||
"""
|
||||
def process_exception(self, request, exception):
|
||||
|
||||
if isinstance(exception, SocialAuthBaseException):
|
||||
backend = getattr(request, 'backend', None)
|
||||
backend_name = getattr(backend, 'name', 'unknown-backend')
|
||||
|
||||
message = self.get_message(request, exception)
|
||||
social_logger.error(message)
|
||||
|
||||
url = self.get_redirect_uri(request, exception)
|
||||
url += ('?' in url and '&' or '?') + \
|
||||
'message={0}&backend={1}'.format(urlquote(message),
|
||||
backend_name)
|
||||
return redirect(url)
|
||||
|
|
|
@ -28,6 +28,7 @@ Make sure the username box has your <b>username, not your email</b> -- some brow
|
|||
<br /><br />
|
||||
<div class="google_signup">
|
||||
<a class="btn btn-social btn-google-plus" href="{% url 'social:begin' "google-oauth2" %}?next={% url 'receive_gift' gift.acq.nonce %}" ><i class="fa fa-google"></i>Sign in with Google</a>
|
||||
<a class="btn btn-social btn-yahoo" href="{% url 'social:begin' "yahoo" %}?next={% url 'receive_gift' gift.acq.nonce %}" ><i class="fa fa-yahoo"></i>Sign in with Yahoo!</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
|
|
@ -169,9 +169,12 @@ function put_un_in_cookie2(){
|
|||
<div class="button">
|
||||
<input type="submit" class="signup" value="Sign Up Now" onclick="this.disabled=true,this.form.submit();" />
|
||||
</div>
|
||||
<div class="google_signup">
|
||||
<div class="google_signup" style="padding-bottom: 10px;">
|
||||
<a class="btn btn-social btn-google-plus" href="{% url 'social:begin' "google-oauth2" %}?next={% if request.GET.next %}{{ request.GET.next|urlencode }}{% else %}/next/{% endif %}" ><i class="fa fa-google"></i>Sign Up with Google</a>
|
||||
</div>
|
||||
<div class="google_signup">
|
||||
<a class="btn btn-social btn-yahoo" href="{% url 'social:begin' "yahoo" %}?next={% if request.GET.next %}{{ request.GET.next|urlencode }}{% else %}/next/{% endif %}" ><i class="fa fa-yahoo"></i>Sign Up with Yahoo!</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
{% extends "registration/from_pledge.html" %}
|
||||
{% block login_pitch %}<h3>OK, you don't want to use Google to sign in, so try another way. </h3>{% endblock %}
|
||||
{% block login_pitch %}<h3>OK, we're running into a problem using {{ request.GET.backend }} to sign in, so try another way. </h3>{% endblock %}
|
|
@ -62,9 +62,11 @@ function put_un_in_cookie(){
|
|||
|
||||
</div>
|
||||
<div class="halfcolumn1 login_box">
|
||||
<h3>Use Google to Sign In:</h3>
|
||||
<div class="google_signup{% if socials.google %} errorlist{% endif %}">
|
||||
<h3>Use Google or Yahoo to Sign In:</h3>
|
||||
<div class="google_signup{% if socials %} errorlist{% endif %}">
|
||||
<a class="btn btn-social btn-google-plus" href="{% url 'social:begin' "google-oauth2" %}?next={{ next }}" ><i class="fa fa-google"></i>Sign in with Google</a>
|
||||
|
||||
<a class="btn btn-social btn-yahoo" href="{% url 'social:begin' "yahoo" %}?next={{ next }}" ><i class="fa fa-yahoo"></i>Sign in with Yahoo!</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="halfcolumn1 login_box">
|
||||
|
|
|
@ -34,6 +34,7 @@ Make sure the username box has your <b>username, not your email</b> -- some brow
|
|||
<br /><br />
|
||||
|
||||
<a class="btn btn-social btn-google-plus" href="{% url 'social:begin' "google-oauth2" %}?next={% if request.GET.next %}{{ request.GET.next|urlencode }}{% else %}{{ request.get_full_path|urlencode}}{% endif %}" ><i class="fa fa-google"></i>Sign in with Google</a>
|
||||
<a class="btn btn-social btn-yahoo" href="{% url 'social:begin' "yahoo" %}?next={% if request.GET.next %}{{ request.GET.next|urlencode }}{% else %}{{ request.get_full_path|urlencode}}{% endif %}" ><i class="fa fa-yahoo"></i>Sign in with Yahoo!</a>
|
||||
{% else %}
|
||||
<div>
|
||||
You are already logged in as <a href="{% url 'supporter' user %}">{{ user.username }}</a>.
|
||||
|
|
|
@ -27,6 +27,7 @@ function put_un_in_cookie(){
|
|||
<div class="google_signup">
|
||||
<h3>...or</h3>
|
||||
<a class="btn btn-social btn-google-plus" href="{% url 'social:begin' "google-oauth2" %}?next={% if request.GET.next %}{{ request.GET.next|urlencode }}{% else %}/next/{% endif %}" ><i class="fa fa-google"></i>Sign in with Google</a>
|
||||
<a class="btn btn-social btn-yahoo" href="{% url 'social:begin' "yahoo" %}?next={% if request.GET.next %}{{ request.GET.next|urlencode }}{% else %}/next/{% endif %}" ><i class="fa fa-yahoo"></i>Sign in with Yahoo!</a>
|
||||
</div>
|
||||
{% else %}
|
||||
<div>
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
{% block doccontent %}
|
||||
<div id="welcomesearch">
|
||||
<p>Welcome, {{user.username}}!</p><p id="link-to-next"></p>
|
||||
<label>What book would you give to the world? </label>
|
||||
<label>Search and add free-licenced books! </label>
|
||||
<form action="{% url 'search' %}" method="get">
|
||||
<input type="text" id="watermark" onfocus="imgfocus()" onblur="imgblur(0)" size="25" class="inputbox" name="q" value="{{ q }}">
|
||||
<input type="text" onfocus="imgfocus()" onblur="imgblur(0)" size="25" class="inputbox" name="q" value="{{ q }}">
|
||||
<input type="submit" class="greenbutton" value="Search">
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -303,9 +303,9 @@ function highlightTarget(targetdiv) {
|
|||
|
||||
<div id="js-maincontainer-bot-block">
|
||||
<div id="js-search">
|
||||
<label>What book would you give to the world? </label>
|
||||
<label>Search and add free-licenced books! </label>
|
||||
<form action="{% url 'search' %}" method="get">
|
||||
<input type="text" id="watermark" onfocus="imgfocus()" onblur="imgblur(0)" size="25" class="inputbox" name="q" value="{{ q }}">
|
||||
<input type="text" onfocus="imgfocus()" onblur="imgblur(0)" size="25" class="inputbox" name="q" value="{{ q }}">
|
||||
<input type="submit" class="greenbutton" value="Search">
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -104,7 +104,7 @@ MIDDLEWARE_CLASSES = (
|
|||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'maintenancemode.middleware.MaintenanceModeMiddleware',
|
||||
'social.apps.django_app.middleware.SocialAuthExceptionMiddleware'
|
||||
'regluit.core.auth.SocialAuthExceptionMiddlewareWithoutMessages',
|
||||
)
|
||||
|
||||
ROOT_URLCONF = 'regluit.urls'
|
||||
|
|
Loading…
Reference in New Issue