refactor libraryauth
try to keep all the user reg stuff in libraryauth, in prep for splitting it offpull/1/head
parent
4ff63359b3
commit
33a1482cc7
|
@ -40,6 +40,7 @@ from django.utils.translation import ugettext_lazy as _
|
|||
regluit imports
|
||||
'''
|
||||
import regluit
|
||||
from regluit.libraryauth.auth import AVATARS
|
||||
import regluit.core.isbn
|
||||
import regluit.core.cc as cc
|
||||
from regluit.core.epub import personalize, ungluify, test_epub, ask_epub
|
||||
|
@ -2234,7 +2235,7 @@ def pledger2():
|
|||
pledger2.instance=None
|
||||
|
||||
ANONYMOUS_AVATAR = '/static/images/header/avatar.png'
|
||||
(NO_AVATAR, GRAVATAR, TWITTER, FACEBOOK, UNGLUEITAR) = (0, 1, 2, 3, 4)
|
||||
(NO_AVATAR, GRAVATAR, TWITTER, FACEBOOK, UNGLUEITAR) = AVATARS
|
||||
|
||||
class Libpref(models.Model):
|
||||
user = models.OneToOneField(settings.AUTH_USER_MODEL, related_name='libpref')
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
{% block doccontent %}
|
||||
|
||||
{% if request.user.is_authenticated %}
|
||||
{% ifequal request.user.password '!' %}
|
||||
{% if not request.user.has_usable_password %}
|
||||
<div>
|
||||
Because you registered using your account on another site (such as Google), you'll need to reset your password before you can change it.
|
||||
</div>
|
||||
|
@ -22,7 +22,7 @@
|
|||
<p><input type='submit' value="Change password" /></p>
|
||||
|
||||
</form>
|
||||
{% endifequal %}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<div>You must be logged in to change your password.</div>
|
||||
<a href="{% url 'superlogin' %}?next={% if request.GET.next %}{{ request.GET.next|urlencode }}{% else %}/next/{% endif %}" class="nounderline"><div class="actionbutton">Log in</div></a>
|
||||
|
|
|
@ -323,14 +323,6 @@ def stub(request):
|
|||
def acks(request, work):
|
||||
return render(request,'front_matter.html', {'campaign': work.last_campaign()})
|
||||
|
||||
|
||||
@login_required
|
||||
def social_auth_reset_password(request):
|
||||
if not request.user.has_usable_password():
|
||||
request.user.set_password('%010x' % random.randrange(16**10))
|
||||
request.user.save()
|
||||
return password_reset(request)
|
||||
|
||||
def work(request, work_id, action='display'):
|
||||
work = safe_get_work(work_id)
|
||||
alert=''
|
||||
|
|
|
@ -10,8 +10,9 @@ 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
|
||||
|
||||
ANONYMOUS_AVATAR = '/static/images/header/avatar.png'
|
||||
(NO_AVATAR, GRAVATAR, TWITTER, FACEBOOK, PRIVATETAR) = (0, 1, 2, 3, 4)
|
||||
AVATARS = (NO_AVATAR, GRAVATAR, TWITTER, FACEBOOK, PRIVATETAR)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -33,7 +34,7 @@ def facebook_extra_values( user, extra_data):
|
|||
try:
|
||||
facebook_id = extra_data.get('id')
|
||||
user.profile.facebook_id = facebook_id
|
||||
if user.profile.avatar_source is None or user.profile.avatar_source is UNGLUEITAR:
|
||||
if user.profile.avatar_source is None or user.profile.avatar_source is PRIVATETAR:
|
||||
user.profile.avatar_source = FACEBOOK
|
||||
user.profile.save()
|
||||
return True
|
||||
|
@ -46,9 +47,9 @@ def twitter_extra_values( user, extra_data):
|
|||
twitter_id = extra_data.get('screen_name')
|
||||
profile_image_url = extra_data.get('profile_image_url_https')
|
||||
user.profile.twitter_id = twitter_id
|
||||
if user.profile.avatar_source is None or user.profile.avatar_source in (TWITTER, UNGLUEITAR):
|
||||
if user.profile.avatar_source is None or user.profile.avatar_source in (TWITTER, PRIVATETAR):
|
||||
user.profile.pic_url = profile_image_url
|
||||
if user.profile.avatar_source is None or user.profile.avatar_source is UNGLUEITAR:
|
||||
if user.profile.avatar_source is None or user.profile.avatar_source is PRIVATETAR:
|
||||
user.profile.avatar_source = TWITTER
|
||||
user.profile.save()
|
||||
return True
|
|
@ -55,6 +55,7 @@ urlpatterns = [
|
|||
template_name='registration/welcome.html',
|
||||
extra_context={'suppress_search_box': True,}
|
||||
) ),
|
||||
url(r'^socialauth/reset_password/$', views.social_auth_reset_password, name="social_auth_reset_password"),
|
||||
url(r'^socialauth/', include('social.apps.django_app.urls', namespace='social')),
|
||||
url('accounts/', include('email_change.urls')),
|
||||
url(r'^accounts/', include('registration.backends.model_activation.urls')),
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
import logging
|
||||
import random
|
||||
from django.conf import settings
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
from django.contrib.auth.views import login
|
||||
from django.contrib.auth.views import login, password_reset
|
||||
|
||||
from django.contrib.auth import login as login_to_user
|
||||
from django.contrib.auth import load_backend
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
@ -264,5 +266,11 @@ def edit_user(request, redirect_to=None):
|
|||
return HttpResponseRedirect(redirect_to if redirect_to else reverse('home')) # Redirect after POST
|
||||
return render(request,'registration/user_change_form.html', {'form': form})
|
||||
|
||||
@login_required
|
||||
def social_auth_reset_password(request):
|
||||
if not request.user.has_usable_password():
|
||||
request.user.set_password('%010x' % random.randrange(16**10))
|
||||
request.user.save()
|
||||
return password_reset(request)
|
||||
|
||||
|
||||
|
|
|
@ -129,7 +129,7 @@ MIDDLEWARE_CLASSES = (
|
|||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'maintenancemode.middleware.MaintenanceModeMiddleware',
|
||||
'regluit.core.auth.SocialAuthExceptionMiddlewareWithoutMessages',
|
||||
'regluit.libraryauth.auth.SocialAuthExceptionMiddlewareWithoutMessages',
|
||||
'django.middleware.locale.LocaleMiddleware',
|
||||
'regluit.questionnaire.request_cache.RequestCacheMiddleware',
|
||||
)
|
||||
|
@ -269,14 +269,14 @@ SOCIAL_AUTH_PIPELINE = (
|
|||
'social.pipeline.social_auth.auth_allowed',
|
||||
|
||||
# Checks if the current social-account is already associated in the site.
|
||||
'regluit.core.auth.selective_social_user',
|
||||
'regluit.libraryauth.auth.selective_social_user',
|
||||
|
||||
# Make up a username for this person, appends a random string at the end if
|
||||
# there's any collision.
|
||||
'social.pipeline.user.get_username',
|
||||
|
||||
# make username < 222 in length
|
||||
'regluit.core.auth.chop_username',
|
||||
'regluit.libraryauth.auth.chop_username',
|
||||
|
||||
# Send a validation email to the user to verify its email address.
|
||||
# Disabled by default.
|
||||
|
@ -284,7 +284,7 @@ SOCIAL_AUTH_PIPELINE = (
|
|||
|
||||
# Associates the current social details with another user account with
|
||||
# a similar email address. don't use twitter or facebook to log in
|
||||
'regluit.core.auth.selectively_associate_by_email',
|
||||
'regluit.libraryauth.auth.selectively_associate_by_email',
|
||||
|
||||
# Create a user account if we haven't found one yet.
|
||||
'social.pipeline.user.create_user',
|
||||
|
@ -297,7 +297,7 @@ SOCIAL_AUTH_PIPELINE = (
|
|||
'social.pipeline.social_auth.load_extra_data',
|
||||
|
||||
# add extra data to user profile
|
||||
'regluit.core.auth.deliver_extra_data',
|
||||
'regluit.libraryauth.auth.deliver_extra_data',
|
||||
|
||||
# Update the user record with any changed info from the auth service.
|
||||
'social.pipeline.user.user_details'
|
||||
|
|
2
urls.py
2
urls.py
|
@ -1,7 +1,6 @@
|
|||
from django.conf.urls import patterns, url, include
|
||||
from django.contrib.sitemaps.views import index, sitemap
|
||||
|
||||
from frontend.views import social_auth_reset_password
|
||||
from regluit.admin import site
|
||||
from regluit.core.sitemaps import WorkSitemap, PublisherSitemap
|
||||
|
||||
|
@ -11,7 +10,6 @@ sitemaps = {
|
|||
}
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^socialauth/reset_password/$', social_auth_reset_password, name="social_auth_reset_password"),
|
||||
url(r'^api/', include('regluit.api.urls')),
|
||||
url(r'', include('regluit.frontend.urls')),
|
||||
url(r'', include('regluit.payment.urls')),
|
||||
|
|
Loading…
Reference in New Issue