本文整理汇总了Python中social_auth.models.UserSocialAuth.create_social_auth方法的典型用法代码示例。如果您正苦于以下问题:Python UserSocialAuth.create_social_auth方法的具体用法?Python UserSocialAuth.create_social_auth怎么用?Python UserSocialAuth.create_social_auth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类social_auth.models.UserSocialAuth
的用法示例。
在下文中一共展示了UserSocialAuth.create_social_auth方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_simple
# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import create_social_auth [as 别名]
def test_simple(self):
UserSocialAuth.create_social_auth(self.user, '1234', 'github')
self.login_as(self.user)
url = reverse('sentry-api-0-user-social-identities-index', kwargs={
'user_id': self.user.id,
})
response = self.client.get(url)
assert response.status_code == 200, response.content
assert len(response.data) == 1
assert response.data[0]['provider'] == 'github'
示例2: add_auth_id
# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import create_social_auth [as 别名]
def add_auth_id(self, auth_str):
"""
Add a social auth identifier for this user.
The `auth_str` should be in the format '{provider}:{uid}'
this is useful for adding multiple unique email addresses.
Example::
user = User.objects.get(username='foo')
user.add_auth_id('email:[email protected]')
"""
provider, uid = auth_str.split(':')
UserSocialAuth.create_social_auth(self, uid, provider)
示例3: vkontakte_view
# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import create_social_auth [as 别名]
def vkontakte_view(request, *args, **kwargs):
if request.method == 'POST':
user = UserSocialAuth.create_user(username=request.POST['uid'])
user.first_name = request.POST['firstname']
user.last_name = request.POST['lastname']
user.backend = 'django.contrib.auth.backends.ModelBackend'
user.save()
social = UserSocialAuth.create_social_auth(user, user.username, 'vkontakte')
request.session['social_auth_last_login_backend'] = social.provider
login(request, user)
else:
try:
social_user = UserSocialAuth.objects.get(user__username=request.GET['viewer_id'])
social_user.user.backend = 'django.contrib.auth.backends.ModelBackend'
login(request, social_user.user)
except UserSocialAuth.DoesNotExist:
return render_to_response('vkontakte_auth.html', RequestContext(request))
return render_to_response('vkontakte_app.html',
RequestContext(request))
示例4: test_can_disconnect
# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import create_social_auth [as 别名]
def test_can_disconnect(self):
auth = UserSocialAuth.create_social_auth(self.user, '1234', 'github')
url = reverse('sentry-api-0-user-social-identity-details', kwargs={
'user_id': self.user.id,
'identity_id': auth.id,
})
with self.settings(GITHUB_APP_ID='app-id', GITHUB_API_SECRET='secret'):
response = self.client.delete(url)
assert response.status_code == 204
assert not len(UserSocialAuth.objects.filter(user=self.user))
示例5: associate_user
# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import create_social_auth [as 别名]
def associate_user(backend, user, uid, social_user=None, *args, **kwargs):
"""Associate user social account with user instance."""
if social_user or not user:
return None
try:
social = UserSocialAuth.create_social_auth(user, uid, backend.name)
except IntegrityError:
# Protect for possible race condition, those bastard with FTL
# clicking capabilities, check issue #131:
# https://github.com/omab/django-social-auth/issues/131
return social_auth_user(backend, uid, user, social_user=social_user, *args, **kwargs)
else:
return {"social_user": social, "user": social.user, "new_association": True}
示例6: associate_user
# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import create_social_auth [as 别名]
def associate_user(backend, user, uid, social_user=None, *args, **kwargs):
"""Associate user social account with user instance."""
if social_user or not user:
return None
try:
social = UserSocialAuth.create_social_auth(user, uid, backend.name)
except Exception, e:
if not SOCIAL_AUTH_MODELS_MODULE.is_integrity_error(e):
raise
# Protect for possible race condition, those bastard with FTL
# clicking capabilities, check issue #131:
# https://github.com/omab/django-social-auth/issues/131
return social_auth_user(backend, uid, user, social_user=social_user,
*args, **kwargs)
示例7: test_login_user
# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import create_social_auth [as 别名]
def test_login_user(self):
uid = randint(1000, 9000)
user = UserSocialAuth.create_user(username=uid)
user.first_name = 'test_firstname'
user.last_name = 'test_lastname'
user.save()
social = UserSocialAuth.create_social_auth(user, user.username, 'vkontakte')
response = self.client.get(reverse('vk_app'), {'viewer_id':uid})
self.assertEqual(response.status_code, 200)
self.assertTrue(response.context['user'].is_authenticated())