我正在尝试安装和配置Django AllAuth,但我遇到了太多障碍.我担心我只是遗漏了一些可能会清除某些事情的基本概念.
1)为了获得基本的社会认证工作,需要在社交提供者(facebook,twitter等)内完成哪些设置.
2)如果是这种情况,那么如何在本地开发,因为乍一看twitter的API设置它会要求重定向URL,考虑到现在的所有内容都是本地托管的.
3)当我尝试去/accounts/login/它时,/accounts/profile/每次重定向.似乎无法弄清楚导致此重定向的原因.
4)我之前使用Userena进行用户身份验证,并且要添加django-social-auth但是当我进入它时给了我很多困难.然后我发现AllAuth似乎完全符合我的需要但又有一些问题.任何人都可以权衡这个决定,你会推荐一个超过另一个,如果是这样,为什么?谢谢你的帮助.
更新:Facebook错误:"应用程序配置不允许给定URL:应用程序的设置不允许使用一个或多个给定的URL.它必须与网站URL或Canvas URL匹配,或者域必须是子域名App的一个域名."
当我点击没关系时,它会重定向回我的网站.我的浏览器给了我一个安全错误,当我继续操作时,我最终回到我的网站上显示:"社交网络登录失败尝试通过您的社交网络帐户登录时出错."
我正在尝试使用django-allauth进行用户注册.我有这个表格
class UserProfileForm(forms.ModelForm):
class Meta:
model = UserProfile
fields = ('gender', 'country', 'city', 'birth_date', 'has_accepted_tos')
Run Code Online (Sandbox Code Playgroud)
并根据我在settings.py中设置的说明
ACCOUNT_SIGNUP_FORM_CLASS = "userprofile.forms.UserProfileForm"
Run Code Online (Sandbox Code Playgroud)
问题是,当表单呈现我的自定义表单要求性别,国家等呈现在顶部,然后标准用户字段,要求用户名,电子邮件和密码.这个顺序的东西:
密码2
我想按此顺序显示字段
用户名
我想覆盖django-allauth的默认形式,以便更改\添加默认小部件属性,类变量而不更改allauth形式的初始代码.我怎样才能做到这一点?
我的工作区:
1)安装了django-allauth,作为一个包通过pip;
2)配置设置,根据github上项目的建议;
3)本地创建的模板登录,注册;
4)创建了forms.py,它定义了一个子类形式django-allauth
from allauth.account import SigninForm
class mySigninForm (SigninForm):
username = ...//override variable
这是对的吗?
谢谢!
我正在尝试将django-allauth与自定义用户模型集成(子类化AbstractUser,但是当我测试注册表单时,由于字段(date_of_birth)为null,我得到完整性错误,但提交的值是u'1976-4- 6'
我正在学习新的自定义用户的东西,以及基于类的视图,因为我正在学习django-allauth,所以我有信心我做错了什么,但经过几天阅读github问题,几个教程,readthedocs和stackoverflow问题我仍然不清楚我做错了什么(我知道有一件事我做错了:在这里和那里尝试不同的解决方案,所以我肯定有一个错误的实现)
但是,我找不到如何将allauth与子类AbstractUser集成的好答案,所以如果有人能够启发我,我会非常感激.
(注意 - 当我以通过固定装置加载的用户身份登录时,网站或多或少有效,所以请假设非django-allauth遗漏是遗漏 - 如果您需要澄清下面的内容,我会很高兴编辑)
AUTH_USER_MODEL = 'userdata.CtrackUser'
ACCOUNT_AUTHENTICATION_METHOD = 'username_email'
ACCOUNT_SIGNUP_FORM_CLASS = 'userdata.forms.SignupForm'
LOGIN_REDIRECT_URL = '/profile'
SOCIALACCOUNT_QUERY_EMAIL = True
SOCIALACCOUNT_AUTO_SIGNUP = False
ACCOUNT_USER_MODEL_USERNAME_FIELD = 'username'
Run Code Online (Sandbox Code Playgroud)
class CtrackUser(AbstractUser):
date_of_birth = models.DateField(help_text='YYYY-MM-DD format')
gender = models.CharField(max_length=2,
choices=settings.GENDER_CHOICES, blank=True)
race = models.CharField(max_length=2, choices=settings.RACE_CHOICES, null=True, blank=True)
condition = models.ForeignKey(Condition, null=True, blank=True)
location = models.CharField(max_length=255, null=True, blank=True)
my_symptoms = models.ManyToManyField(Symptom)
is_admin = models.BooleanField(default=False)
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
Run Code Online (Sandbox Code Playgroud)
from django import forms
from django.conf …Run Code Online (Sandbox Code Playgroud) 我正在创建一个Web应用程序,使用Django作为后端,Angular作为前端.
localhost:9000当Django正在运行时localhost:8000,Angular正在Yeoman堆栈上运行,我正在使用grunt-contrib-proxy将所有$http调用从angular at 重定向/api到django端口.因此,例如,如果Angular要求localhost:9000/api/hello将重定向到,localhost:8000/api/hello并且django将为其提供服务.
我打算设置Django Rest Framework为/api路径提供所有Angular请求.
到现在为止还挺好.
现在,我已经配置了一个Django-allauth用于Oauth对第三方服务进行身份验证的工作安装.它使用普通的旧Django工作,但我不知道如何与Angular一起使用它.
唯一想到的是allauth通过django rest框架提供视图,但是在身份验证后重定向呢?我无法绕过它.
是不是更好地放弃这种方法并直接从前面(Angular)进行Oauth身份验证?
编辑:
我设法login从Angular 调用视图
在grunt-contrib-proxy中我添加了帐户上下文和重写规则:
context: ['/api', '/accounts'],
rewrite: {
'^/api': '/api',
'^/account': '/accounts'
}
Run Code Online (Sandbox Code Playgroud)我已经从angular进行了ajax调用,要求allaluth登录视图(例如对于github): $http.get('/accounts/github/login/?process=login')
问题是我回来了:
XMLHttpRequest cannot load https://github.com/login/oauth/authorize?scope=&state=BlaBla&redirect…ub%2Flogin%2Fcallback%2F&response_type=code&client_id=BlaBlaBla. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access. (index):1
Run Code Online (Sandbox Code Playgroud)
(BlaBla是我添加的).我想我做错了
我是python/Django宇宙的新手,刚刚开始了一个我非常兴奋的大项目.我需要让我的用户通过Facebook登录,我的应用程序有一个非常具体的用户流程.我已经建立了django-allauth,一切都按照我的需要运作.我已经覆盖了LOGIN_REDIRECT_URL,以便我的用户在登录时登陆我想要的页面.
但.当用户打开Facebook登录对话框然后关闭它而不登录时,authentication_error.html模板将被渲染allauth.socialaccount.helpers.render_authentication_error,这不是我想要的行为.我希望用户只需重定向到登录页面.
是的,我知道我可以通过将模板放在我的模板中来覆盖模板TEMPLATE_DIRS,但之后网址将不一样.
我得出结论我需要一个中间件来拦截对http请求的响应.
from django.shortcuts import redirect
class Middleware():
"""
A middleware to override allauth user flow
"""
def __init__(self):
self.url_to_check = "/accounts/facebook/login/token/"
def process_response(self, request, response):
"""
In case of failed faceboook login
"""
if request.path == self.url_to_check and\
not request.user.is_authenticated():
return redirect('/')
return response
Run Code Online (Sandbox Code Playgroud)
但我不确定我的解决方案的效率,也不确定pythonesquitude(我是juste想出了那个词).在没有使用中间件或信号的情况下,我还能做些什么来改变默认的django-allauth行为?
谢谢!
我试图使用rest-auth提供的序列化器来定义端点/rest-auth/user /的GET(*with headers)用户详细信息
(*with headers(Content-Type:application/json授权:Token 1a5472b2af03fc0e9de31fc0fc6dd81583087523))
我得到以下回溯:https://dpaste.de/oYay#L
我已经定义了自定义用户模型(使用电子邮件而不是用户名):
class UserManager(BaseUserManager):
def create_user(self, email, password, **kwargs):
user = self.model(
# lower-cases the host name of the email address
# (everything right of the @) to avoid case clashes
email=self.normalize_email(email),
is_active=True,
**kwargs
)
user.set_password(password)
user.save(using=self._db)
return user
def create_superuser(self, email, password, **kwargs):
user = self.model(
email=email,
is_staff=True,
is_superuser=True,
is_active=True,
**kwargs
)
user.set_password(password)
user.save(using=self._db)
return user
class MyUser(AbstractBaseUser, PermissionsMixin):
USERNAME_FIELD = 'email'
email = models.EmailField(unique=True)
Run Code Online (Sandbox Code Playgroud)
设置如下:
AUTH_USER_MODEL = …Run Code Online (Sandbox Code Playgroud) python django django-rest-framework django-allauth django-rest-auth
我正在尝试在Bootstrap模式下的django页面上创建登录和/或注册弹出窗口。
我用这个答案来创建一个上下文处理器,该处理器返回allauth登录表单,并将该表单的操作重定向到“ accounts / login /”
<form method='post' action='/accounts/login/' id='login'>
{% csrf_token %}
{{ login_form.as_p }}
<input type='submit' value='Log In'>
</form>
Run Code Online (Sandbox Code Playgroud)
与上下文处理器
from allauth.account.forms import LoginForm
def login_form(request):
return {
'login_form': LoginForm
}
Run Code Online (Sandbox Code Playgroud)
这很好用,我可以使用转到帐户/注销的按钮再次登录和注销。
直到我输入错误的用户为止,它没有显示我主页上模态中的错误,而是转到帐户/登录并在那里显示错误(这是预料之中的)。我想我需要将视图渲染到模态内,与此类似。
最佳做法是什么?
编辑:我发现了这个问题,它也没有得到回答。django allauth似乎不是这种行为的正确工具。
由于它通常是众所周知的工作流程(在操作之间进行登录),因此django是否有其他应用程序可以提供此功能?还有django-registration-redux,功能更强大吗?
问候朱利安
我正在尝试使用 Django-allauth 进行某些密码重置功能,但是,我正在尝试使用 django-allauth 禁用登录/注册。到目前为止,我还没有找到一种方法将用户重定向到我的自定义注册和登录或完全禁用这些 URL。我想知道是否有解决方法可以删除这些 URL?
我当前的方法是手动添加所有 URL,但不添加这些 URL,但这会导致我的social-login链接出现错误。
目前,我已将以下内容添加到我的网址中:
url(r"^accounts/logout/$", allauth_views.logout, name="account_logout"),
url(r"^accounts/password/change/$", allauth_views.password_change,name="account_change_password"),
url(r"^accounts/password/set/$", allauth_views.password_set, name="account_set_password"),
url(r"^accounts/inactive/$", allauth_views.account_inactive, name="account_inactive"),
# E-mail
url(r"^accounts/email/$", allauth_views.email, name="account_email"),
url(r"^accounts/confirm-email/$", allauth_views.email_verification_sent,name="account_email_verification_sent"),
url(r"^accounts/confirm-email/(?P<key>[-:\w]+)/$", allauth_views.confirm_email,name="account_confirm_email"),
# password reset
url(r"^accounts/password/reset/$", allauth_views.password_reset,name="account_reset_password"),
url(r"^accounts/password/reset/done/$", allauth_views.password_reset_done,name="account_reset_password_done"),
url(r"^accounts/password/reset/key/(?P<uidb36>[0-9A-Za-z]+)-(?P<key>.+)/$",allauth_views.password_reset_from_key,name="account_reset_password_from_key"),
url(r"^accounts/password/reset/key/done/$", allauth_views.password_reset_from_key_done,name="account_reset_password_from_key_done"),
# social account
path('socialaccount/login/cancelled/', allauth_socialviews.login_cancelled,name='socialaccount_login_cancelled'),
path('socialaccount/login/error/', allauth_socialviews.login_error,name='socialaccount_login_error'),
path('socialaccount/signup/', allauth_socialviews.signup, name='socialaccount_signup'),
path('socialaccount/connections/', allauth_socialviews.connections, name='socialaccount_connections'),
Run Code Online (Sandbox Code Playgroud)
但是,由于我有 Google 社交登录,因此出现错误:
Reverse for 'google_login' not found. 'google_login' is not a valid view function or pattern name
我怎样才能实现这个而不引起任何错误?
我在使用 dj_rest_auth jwt 包时遇到问题。当我注册一个新帐户时,它会为我提供访问令牌和刷新令牌作为响应,但是当我尝试使用凭据登录时,我得到的只是访问令牌,而刷新令牌完全是空的!我按照文档和我遵循的教程中的描述配置了代码。对这个问题有什么想法吗?请告诉我。
更新:我刚刚发现刷新令牌已在响应标头中正确设置,但我无法弄清楚为什么它不在响应正文中并且显示为空?!
设置.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'rest_framework',
'rest_framework.authtoken',
'allauth',
'allauth.account',
'allauth.socialaccount',
'dj_rest_auth',
'dj_rest_auth.registration',
'accounts.apps.AccountsConfig',
]
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': [
'accounts.permissions.IsStaffOrReadOnly',
],
'DEFAULT_AUTHENTICATION_CLASSES': [
'dj_rest_auth.jwt_auth.JWTCookieAuthentication',
],
}
SITE_ID = 1
REST_AUTH = {
'USE_JWT': True,
'JWT_AUTH_COOKIE': 'access',
'JWT_AUTH_REFRESH_COOKIE': 'refresh',
}
Run Code Online (Sandbox Code Playgroud)
回复:
{
"access_token": "eyJhbGciOiJ.....",
"refresh_token": "",
"user": {
"pk": 2,
"username": "test_user_0",
"email": "test0@mysite.co",
"first_name": "",
"last_name": ""
}
}
Run Code Online (Sandbox Code Playgroud) django jwt django-rest-framework django-allauth dj-rest-auth
django-allauth ×10
django ×9
python ×2
angularjs ×1
dj-rest-auth ×1
django-1.6 ×1
django-forms ×1
django-urls ×1
django-views ×1
facebook ×1
forms ×1
jwt ×1
rest ×1
social ×1
twitter ×1