我一直在使用当前项目进行社交身份验证,但是遇到一个错误,根据使用的社交媒体平台登录,还会导致两个错误。
从社交媒体平台成功重定向后,我从“定制模型管理器”创建用户收到错误消息,该用户用户必须输入Google身份验证的密码或用户必须输入Facebook的密码验证。
从以上这些错误中可以总结出,Django正在尝试从社交平台重定向后立即创建用户帐户。
我的第一个问题是,这种行为是否应视为正常现象,因为如果用户已经拥有一个帐户,可能会有些麻烦。
第二,如果行为正常,那么我应该如何完成注册过程。
File "C:\Users\SAM\Envs\my_django_environment\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\SAM\Envs\my_django_environment\lib\site-packages\django\core\handlers\base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\SAM\Envs\my_django_environment\lib\site-packages\django\core\handlers\base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\SAM\Envs\my_django_environment\lib\site-packages\django\views\decorators\cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "C:\Users\SAM\Envs\my_django_environment\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "C:\Users\SAM\Envs\my_django_environment\lib\site-packages\social_django\utils.py", line 49, in wrapper
return func(request, backend, *args, **kwargs)
File "C:\Users\SAM\Envs\my_django_environment\lib\site-packages\social_django\views.py", line 33, in complete
*args, **kwargs)
File "C:\Users\SAM\Envs\my_django_environment\lib\site-packages\social_core\actions.py", line 43, in do_complete
user = backend.complete(user=user, *args, **kwargs)
File "C:\Users\SAM\Envs\my_django_environment\lib\site-packages\social_core\backends\base.py", line 40, in complete
return self.auth_complete(*args, **kwargs)
File "C:\Users\SAM\Envs\my_django_environment\lib\site-packages\social_core\utils.py", line 259, in wrapper
return func(*args, **kwargs)
File "C:\Users\SAM\Envs\my_django_environment\lib\site-packages\social_core\backends\facebook.py", line 111, in auth_complete
return self.do_auth(access_token, response, *args, **kwargs)
File "C:\Users\SAM\Envs\my_django_environment\lib\site-packages\social_core\backends\facebook.py", line 153, in do_auth
return self.strategy.authenticate(*args, **kwargs)
File "C:\Users\SAM\Envs\my_django_environment\lib\site-packages\social_django\strategy.py", line 107, in authenticate
return authenticate(*args, **kwargs)
File "C:\Users\SAM\Envs\my_django_environment\lib\site-packages\django\contrib\auth\__init__.py", line 73, in authenticate
user = backend.authenticate(request, **credentials)
File "C:\Users\SAM\Envs\my_django_environment\lib\site-packages\social_core\backends\base.py", line 80, in authenticate
return self.pipeline(pipeline, *args, **kwargs)
File "C:\Users\SAM\Envs\my_django_environment\lib\site-packages\social_core\backends\base.py", line 83, in pipeline
out = self.run_pipeline(pipeline, pipeline_index, *args, **kwargs)
File "C:\Users\SAM\Envs\my_django_environment\lib\site-packages\social_core\backends\base.py", line 113, in run_pipeline
result = func(*args, **out) or {}
File "C:\Users\SAM\Envs\my_django_environment\lib\site-packages\social_core\pipeline\user.py", line 75, in create_user
'user': strategy.create_user(**fields)
File "C:\Users\SAM\Envs\my_django_environment\lib\site-packages\social_core\strategy.py", line 53, in create_user
return self.storage.user.create_user(*args, **kwargs)
File "C:\Users\SAM\Envs\my_django_environment\lib\site-packages\social_django\storage.py", line 79, in create_user
user = cls.user_model().objects.create_user(*args, **kwargs)
File "C:\Users\SAM\Desktop\Crackerbox\users\models.py", line 14, in create_user
raise ValueError("User must enter an email address.")
ValueError: User must enter an email address.
[31/Jan/2019 19:29:32] "GET /oauth/complete/facebook/?granted_scopes=public_profile&denied_scopes&code=AQBt4yAKBum6I8F_XanHwnD-i_9ZTAXhVxOKt0WRQNER7HON2jlO5WTQlmuizKZ0ChI7tJvLT4pp_wLmO5X5gCWAcWqyJYZwyE4UqBJS1WUIL984W-vCawU24M0WsWKW27dhxqAK2ClgXDBTK3YfitvbjdPNEse7dLIBTyNDg926j7IKtQ_dpjsVECmEuAhZOM_vE3TQ5BOElalMxw8laBjWFi_vbhPdPAgFjKtwE3chE_d17n5samw_uamKNmegqYpmX2iZje2xIix56dLZuCvuAwAQaqfYjExgujOe9ZhYE2XHP7M9fG_TYBy-zW1Q8yIFR8iwsCWmQWeLl1jreWvl&state=7UPt8glMyksSPvFzJR4okb1PDvUbgMWK HTTP/1.1" 500 176183
自定义用户模型
def create_user(self, email,username, password=None, is_active=True, is_admin= False, is_staff = False, is_profiled =False):
if not email:
raise ValueError("User must enter an email address.")
if not password:
raise ValueError("User must enter a password.")
if not username:
raise ValueError("User must enter a username.")
user_obj = self.model(email= self.normalize_email(email),
username = username )
user_obj.set_password(password)
user_obj.staff = is_staff
user_obj.admin = is_admin
user_obj.active = is_active
user_obj.profiled = is_profiled
user_obj.username = username
user_obj.save(using= self._db)
return user_obj
谢谢
答案 0 :(得分:0)
是的,pytjon-social-auth
如果未检测到用户是否已经在您的网站上创建帐户,则会自动创建该用户。
引发的错误是因为你正迫使这些值支票上的自定义create_user
方法。如果您的正常功能需要这些值,则可以选择以下几种方法:
partial pipeline
功能向用户显示可以填写必填字段的表单。如果这些字段不强制你的应用程序,然后尝试删除该约束。
答案 1 :(得分:0)
在电子邮件之后添加自己的请求
def create_user(self, email,username, password=None, is_active=True, is_admin= False, is_staff = False, is_profiled =False):