そのため、タイトルが進むにつれて、Facebookを使用して新しいユーザーを作成し、新しいプロファイルを作成することができます。ただし、ログインしていません。常に/ login /にリダイレクトされます(最後にいくつかの文字があります)。このコードでは、何が欠けている可能性がありますか?
私のsettings.py
SOCIAL_AUTH_DEFAULT_USERNAME = lambda u: slugify(u)
SOCIAL_AUTH_UUID_LENGTH = 10
SOCIAL_AUTH_EXTRA_DATA = False
SOCIAL_AUTH_EXPIRATION = 'expires'
SOCIAL_AUTH_INACTIVE_USER_URL = '/inactive/'
SOCIAL_AUTH_RAISE_EXCEPTIONS = DEBUG
SOCIAL_AUTH_CHANGE_SIGNAL_ONLY = True
SOCIAL_AUTH_ASSOCIATE_BY_MAIL = True
SOCIAL_AUTH_COMPLETE_URL_NAME = 'socialauth_complete'
SOCIAL_AUTH_ASSOCIATE_URL_NAME = 'socialauth_associate_complete'
AUTHENTICATION_BACKENDS = (
'social_auth.backends.facebook.FacebookBackend',
'django.contrib.auth.backends.ModelBackend',
)
TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
'social_auth.context_processors.social_auth_by_name_backends',
'social_auth.context_processors.social_auth_backends',
'social_auth.context_processors.social_auth_by_type_backends',
'social_auth.context_processors.social_auth_login_redirect',
)
私のmodels.py
signals.post_save.connect(create_profile, sender=User)
pre_update.connect(facebook_extra_values, sender=FacebookBackend)
class UserProfile(models.Model):
user = models.ForeignKey(User)
photo = ImageField(upload_to="profile_pictures")
def get_absolute_url(self):
return ('profiles_profile_detail', (), {'username':self.user.username})
get_absolute_url = models.permalink(get_absolute_url)
私のreceivers.py
def facebook_extra_values(sender, instance, response, details, **kwargs):
"""
post_save signal from User model; check bzuser.models
for the connection
"""
from .models import UserProfile
UserProfile(user=instance).save()
return True
私のurls.py
urlpatterns = patterns('',
url(r'^login/$', custom_login),
url(r'^logout/$', custom_logout),
url(r'^social_login/$', SocialLoginView.as_view(), name="social_login"),
(r'', include('registration.backends.default.urls')),
url(r'^register$', 'registration.views.register', {
'form_class': RegistrationFormUniqueEmail,
'backend': 'registration.backends.default.DefaultBackend'
}, name='registration_register'),
(r'^profiles/', include('profiles.urls')),
url(r'^profile', ProfileView.as_view(), name="profile_private"),
)
と私のviews.py
class ProfileView(TemplateView):
template_name = 'profile.html'
class SocialLoginView(TemplateView):
def get_context_data(self, **kwargs):
context = super(SocialLoginView, self).get_context_data(**kwargs)
context['title'] = _('Log In With Facebook or Twitter')
return context
template_name = 'social.html'
def custom_login(request):
if request.user.is_authenticated():
return HttpResponseRedirect(reverse('profiles_profile_detail',
kwargs={"username":request.user.username}))
else:
return login(request)
def custom_logout(request):
return logout_then_login(request)
と私のテンプレート:
{% extends 'base.html' %}
{% block content %}
<div class="widget">
<div class="title">
<img class="titleIcon" src="{{ STATIC_URL }}images/icons/dark/preview.png" />
<h6>Social Login</h6>
</div>
<div class="body textC">
<a class="wButton bluewB m10"
href="{% url socialauth_begin 'facebook' %}{% if request.GET.next %}?next={{ request.GET.next }}{% endif %}">
<span>Log In With Facebook</span>
</a>
</div>
</div>
{% endblock %}
前もって感謝します!
編集:AUTHENTICATION_BACKENDS定数を追加しました
アプリからのurls.py
urlpatterns = patterns('',
# project specific urls
url(r'', include('base.urls')),
url(r'', include('bzuser.urls')),
# 3rd party URLS
('^nexus/', include(nexus.site.urls)),
url(r'', include('social_auth.urls')),
)
編集:ソーシャル認証の包含URLを追加しました