我设法设置 allauth 来处理我的项目并使用社交媒体登录。不过我想知道他们是否有任何选项可以将获取 Facebook 的电子邮件设置为用户名。我阅读了他们的文档,但在变量中看不到任何内容。
我找到了这个链接,但是他们改变了 Django 的核心文件。我希望能找到更合适的东西。
我当前的配置:
ACCOUNT_USER_MODEL_EMAIL_FIELD = 'email'
ACCOUNT_USER_MODEL_USERNAME_FIELD = 'email'
SOCIALACCOUNT_QUERY_EMAIL = True
SOCIALACCOUNT_EMAIL_REQUIRED = True
Run Code Online (Sandbox Code Playgroud)
另外,是否可以仅使用 Allauth 的社交媒体登录/创建?我可以看到,如果您访问 localhost/accounts/create/ (或类似的网址),则可以创建一个帐户。我不需要它,因为我有自己的帐户创建页面。
from django import forms
from allauth.account.forms import (LoginForm, ChangePasswordForm,
ResetPasswordForm, SetPasswordForm, ResetPasswordKeyForm)
from django.contrib.auth import get_user_model
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Div, Submit, HTML, Button, Row, Field
from crispy_forms.bootstrap import AppendedText, PrependedText, FormActions
from django.core.urlresolvers import reverse
class MySignupForm(forms.Form):
class Meta:
model = get_user_model()
fields = ['email', 'first_name', 'last_name']
def __init__(self, *args, **kwargs):
super(MySignupForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.fields["email"].widget.input_type = "email" # ugly hack
self.helper.form_method = "POST"
self.helper.form_action = "account_signup"
self.helper.form_id = "signup_form"
self.helper.form_class = "signup" …Run Code Online (Sandbox Code Playgroud) 现在我使用 rest_auth 重置密码,无论发送的电子邮件和 URL 像这样打开,但我在其上添加值:这是我单击电子邮件中发送的 URL 时的页面:

在填写字段并提出发布请求后,我得到了这个:这是我得到的错误:

这是我的网址:
urlpatterns = [
path('', include('rest_auth.urls')),
path('login/', LoginView.as_view(), name='account_login'),
path('registration/', include('rest_auth.registration.urls')),
path('registration/', RegisterView.as_view(), name='account_signup'),
re_path(r'^account-confirm-email/', VerifyEmailView.as_view(),
name='account_email_verification_sent'),
re_path(r'^account-confirm-email/(?P<key>[-:\w]+)/$', VerifyEmailView.as_view(),
name='account_confirm_email'),
re_path(r'^password/reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', PasswordResetConfirmView.as_view(),
name='password_reset_confirm')
]
Run Code Online (Sandbox Code Playgroud)
视图是但它内置于 rest_auth 中:
class PasswordResetConfirmView(GenericAPIView):
"""
Password reset e-mail link is confirmed, therefore
this resets the user's password.
Accepts the following POST parameters: token, uid,
new_password1, new_password2
Returns the success/fail message.
"""
serializer_class = PasswordResetConfirmSerializer
permission_classes = (AllowAny,)
@sensitive_post_parameters_m
def dispatch(self, *args, **kwargs):
return super(PasswordResetConfirmView, self).dispatch(*args, **kwargs)
def …Run Code Online (Sandbox Code Playgroud) django django-rest-framework django-allauth django-rest-auth
我正在尝试使用 Elastic Beanstalk 在 AWS 上为我的 Django 网站设置电子邮件功能。我已激活简单电子邮件服务(SES)并验证了两个电子邮件地址以进行测试。此外,我已按照说明安装和设置Dango-SES。但是,当我尝试假装是新用户在我的网站上注册时,我在浏览器中收到此错误(回溯):
Environment:
Django Version: 1.9
Python Version: 2.7.12
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'crispy_forms',
'newsletter',
'allauth',
'allauth.account',
'allauth.socialaccount',
'ajaxuploader')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.models.Session')
Traceback:
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
149. response = self.process_exception_by_middleware(e, request)
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
147. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/views/generic/base.py" in view
68. return self.dispatch(request, *args, **kwargs)
File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
67. return bound_func(*args, **kwargs) …Run Code Online (Sandbox Code Playgroud) email django amazon-web-services django-allauth amazon-elastic-beanstalk
我已成功将 Google、Instagram 和 Vkontakte 与 django-allauth 集成,但在使用 Facebook 时遇到问题。
发生的情况如下:
我已设置 SSL 证书。
脸书设置:
管理员设置:
在此先感谢您的帮助!
我正在尝试设置 Django AllAuth Twitter 登录。当用户使用 Twitter 进行身份验证并重定向到我的网站时,Django AllAuth 会引发错误“无法访问 api.twitter.com 上的私有资源”,我在这里非常迷失。我的settings.py中有以下设置:
SOCIALACCOUNT_PROVIDERS = {
"twitter": {
# From https://developer.twitter.com
"APP": {
"client_id": os.environ["TWITTER_API_KEY"],
"secret": os.environ["TWITTER_API_SECRET"],
}
},
}
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪:
DEBUG Signing request <PreparedRequest [POST]> using client <Client client_key={consuner_key}, client_secret=****, resource_owner_key=None, resource_owner_secret=None, signature_method=HMAC-SHA1, signature_type=AUTH_HEADER, callback_uri=None, rsa_key=None, verifier=None, realm=None, encoding=utf-8, decoding=utf-8, nonce=None, timestamp=None>
DEBUG Including body in call to sign: False
DEBUG Collected params: [('oauth_callback', 'http://127.0.0.1:8000/accounts/twitter/login/callback/'), ('oauth_nonce', '107239631555922908281648822311'), ('oauth_timestamp', '1648822311'), ('oauth_version', '1.0'), ('oauth_signature_method', 'HMAC-SHA1'), ('oauth_consumer_key', '{consuner_key}')]
DEBUG Normalized params: oauth_callback=http%3A%2F%2F127.0.0.1%3A8000%2Faccounts%2Ftwitter%2Flogin%2Fcallback%2F&oauth_consumer_key={consuner_key}&oauth_nonce=107239631555922908281648822311&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1648822311&oauth_version=1.0
DEBUG Normalized …Run Code Online (Sandbox Code Playgroud) 我的网站在生产中启动并运行了一段时间后,我的用户突然登录该网站时遇到了问题。
我已经使用login_required装饰器保护了某些视图/页面,并且我也在使用django admin。当匿名用户访问这些页面中的任何一个时,他将被重定向到登录页面。当该匿名用户添加其凭据时,POST请求成功,并且将其重定向到初始页面。同时,用户将获得一个新的sessionid(如预期的那样)。但是,现在结果变得非常不可靠。当按reload或导航到其他页面(需要登录)时,可能会发生以下两种情况之一:a)识别用户并正确显示该页面b)将用户重定向到登录页面。我已经通过外壳检查了会话的内容,并且那里没有任何变化。
通过负载平衡器和8个应用程序服务器为生产站点提供服务。甚至更陌生:如果我在测试服务器上测试相同的代码(具有相同的设置),那么负载均衡且基本上没有流量,则一切正常。
我在Ubuntu上使用Apache和mod_wsgi在SSL后面的守护进程模式下运行Django 1.6,并且正在使用会话数据库后端。我正在使用django-allauth.account进行帐户管理/登录。我的会话设置如下:
SESSION_COOKIE_HTTPONLY = True
SESSION_COOKIE_AGE = 60*60*24
SESSION_COOKIE_SECURE = True
Run Code Online (Sandbox Code Playgroud)
更新
为了获得更多调试信息,我创建了以下中间件:
from django.conf import settings
class SessionDebugMiddleware(object):
def process_response(self, request, response):
session = request.session
user = getattr(request, 'user', None)
if user:
user=user.id
session_key = request.COOKIES.get(settings.SESSION_COOKIE_NAME, None)
response['X-Meta-Requ'] = '{0},{1},{2},{3}'.format(session_key, session.get('_auth_user_id'), session.get('_auth_user_backend','---'), user)
return response
Run Code Online (Sandbox Code Playgroud)
如果我按了10次刷新按钮,
它似乎是随机的,不遵循任何逻辑。
所以我有以下问题/想法?
无论如何,这可能与负载平衡有关吗?我的理解是,使用数据库会话后端时,Django不需要粘性会话。
这可能与线程问题有关吗?
这可能与高负载有关吗?
这是否与解码问题有关:https : //github.com/django/django/blob/master/django/contrib/sessions/backends/base.py#L83。但是为什么那个解码问题应该不一致。而且我还没有找到任何引用“会话数据已损坏”的日志条目。
任何其他提示都欢迎。
我正在使用Django,Django REST框架,Django-rest-auth和Django-allauth编写服务器应用程序。我有一种用于在用户之间传递消息的方法,只有在接收者登录后才应该发生这种情况。
但是,is_authenticated()即使用户已注销(似乎叫rest-auth/logout/,该对象又应调用Django的注销),该用户对象的方法似乎仍返回True 。是什么原因造成的?我在这里想念什么吗?
这是我的代码:
class SendMessage(generics.CreateAPIView):
permission_classes = (permissions.IsAuthenticated,)
serializer_class = MessageSerializer
def perform_create(self, serializer):
m = self.request.data['msg']
targetUser = User.objects.get(pk = self.request.data['user'])
if targetUser.is_authenticated():
# Send message
else:
# Don't send message
Run Code Online (Sandbox Code Playgroud) authentication django django-rest-framework django-allauth django-rest-auth
我使用标准表格作为确认电子邮件:从allauth.account.views导入Confirm_email作为allauthemailconfirmation
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^rest-auth/', include('rest_auth.urls')),
url(r'^accounts/', include('allauth.urls')),
url(r'^rest-auth/registration/account-confirm-email/(?P<key>\w+)/$', allauthemailconfirmation, name="account_confirm_email"),
url(r'^rest-auth/registration/', include('rest_auth.registration.urls')),
]
Run Code Online (Sandbox Code Playgroud)
设定:
LOGIN_REDIRECT_URL='/'
ACCOUNT_EMAIL_VERIFICATION='mandatory'
ACCOUNT_CONFIRM_EMAIL_ON_GET=False
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = True
ACCOUNT_LOGIN_ON_EMAIL_CONFIRMATION = False
Run Code Online (Sandbox Code Playgroud)
我正确地收到了一封电子邮件,但是当您尝试链接时:
ImproperlyConfigured at /rest-auth/registration/account-confirm-email/MTU:1bn1OD:dQ_mCYi6Zpr8h2aKS9J9BvNdDjA/
TemplateResponseMixin requires either a definition of 'template_name' or an implementation of 'get_template_names()'
Run Code Online (Sandbox Code Playgroud) python django django-rest-framework django-allauth django-rest-auth
我尝试迁移文件后出现此错误
PS C:\ djangoproject\src> python manage.py makemigrations Traceback(最近一次调用最后一次):文件"manage.py",第15行,在execute_from_command_line(sys.argv)文件"C:\ Program Files\Python36\lib\site-packages\django\core\management__init __.py",第371行,在execute_from_command_line utility.execute()文件"C:\ Program Files\Python36\lib\site-packages\django\core\management__init __.py",第347行,执行django.setup()文件"C:\ Program Files\Python36\lib\site-packages\django__init __.py",第24行,在安装程序apps.populate(settings.INSTALLED_APPS)文件"C:\ Program Files\Python36\lib\site-packages\django\apps\registry.py",第93行,填充"duplicates:%s"%app_config.label) django.core.exceptions.ImproperlyConfigured:应用程序标签不是唯一的,重复: AUTH
请帮忙.
python django django-admin django-authentication django-allauth
django ×10
django-allauth ×10
python ×4
cryptography ×1
django-admin ×1
email ×1
forms ×1
import ×1
login ×1
security ×1
session ×1
twitter ×1