本文整理汇总了Python中social_auth.models.UserSocialAuth.save方法的典型用法代码示例。如果您正苦于以下问题:Python UserSocialAuth.save方法的具体用法?Python UserSocialAuth.save怎么用?Python UserSocialAuth.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类social_auth.models.UserSocialAuth
的用法示例。
在下文中一共展示了UserSocialAuth.save方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pre_process
# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import save [as 别名]
def pre_process(self):
"""在处理命令前检查用户的状态。
- 先检查用户是否存在,不存在先保存用户。
- 再检查用户是否已在某个状态,如有,则把用户状态保存至实例。
"""
social = UserSocialAuth.objects.filter(provider='weixin',
uid=self.wxreq.FromUserName)
if social:
social = social[0]
self.user = social.user
else:
try:
user = User.objects.create_user('default_' +
str(random.randint(1, 10000)))
user.save()
user.username = 'wx_%d' % user.id
user.save()
self.user = user
social = UserSocialAuth(user=user, provider='weixin',
uid=self.wxreq.FromUserName)
social.save()
except:
log_err()
ss = UserState.objects.filter(user=social.user.username)
if ss:
self.wxstate = ss[0]
else:
self.wxstate = None
示例2: associate_user
# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import save [as 别名]
def associate_user(backend, user, uid, social_user=None, *args, **kwargs):
"""Associate user social account with user instance."""
if social_user:
return None
try:
social = UserSocialAuth(user=user, uid=str(uid),
provider=backend.name)
social.save()
except Exception:
# 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}
示例3: create_fb_user
# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import save [as 别名]
def create_fb_user(accesstoken,expires,id,first_name,last_name):
try:
user = User.objects.create_user(id, '', '')
except IntegrityError:
explan = 'The user is already in our database'
return render_to_response('info.xml', {"explan":explan})
#useri = User.objects.get(username__exact='YoYuUm')
user.first_name=first_name
user.last_name=last_name
user.save()
fuser = UserSocialAuth(user = user,
provider = 'facebook',
uid = id,
extra_data = '{"access_token": "'+ accesstoken + '", "expires": "'+expires+'", "id": "'+id+'"}'
);
fuser.save();
示例4: testAssociation
# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import save [as 别名]
def testAssociation(self):
resp = self.c.get(reverse('settings'), follow=True)
self.assertNotIn('facebook', resp.context)
self.assertNotIn('google', resp.context)
self.assertNotIn('twitter', resp.context)
self.assertNotIn('odesk', resp.context)
self.u.get_profile().odesk_uid = '~~97784d8733806815'
self.u.get_profile().full_name = "Testing Test"
self.u.get_profile().save()
Worker.objects.create_odesk(external_id='~~97784d8733806815').save()
# Odesk assoc
resp = self.c.get(reverse('settings'))
self.assertIn('odesk', resp.context)
# Facebook assoc
usa = UserSocialAuth(user=self.u, provider='facebook', uid='Tester')
usa.save()
resp = self.c.get(reverse('settings'))
self.assertIn('facebook', resp.context)
# Google assoc
usa = UserSocialAuth(user=self.u, provider='google-oauth2', uid='Tester')
usa.save()
resp = self.c.get(reverse('settings'))
self.assertIn('google', resp.context)
# Twitter assoc
usa = UserSocialAuth(user=self.u, provider='twitter', uid='Tester')
usa.save()
resp = self.c.get(reverse('settings'))
self.assertIn('twitter', resp.context)
示例5: authenticate
# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import save [as 别名]
def authenticate(self, *args, **kwargs):
"""Authenticate user using social credentials
Authentication is made if this is the correct backend, backend
verification is made by kwargs inspection for current backend
name presence.
"""
# Validate backend and arguments. Require that the Social Auth
# response be passed in as a keyword argument, to make sure we
# don't match the username/password calling conventions of
# authenticate.
if not (self.name and kwargs.get(self.name) and 'response' in kwargs):
return None
response = kwargs.get('response')
details = self.get_user_details(response)
uid = self.get_user_id(details, response)
is_new = False
user = kwargs.get('user')
try:
social_user = self.get_social_auth_user(uid)
except UserSocialAuth.DoesNotExist:
if user is None and HOLD_SOCIAL_USER and not CREATE_USERS:
# create fake user, and create social user in session
user = User()
user.is_fake = True
social_user = UserSocialAuth(user=user, uid=uid, provider=self.name)
user.social_user = social_user
if LOAD_EXTRA_DATA:
extra_data = self.extra_data(user, uid, response, details)
if extra_data and social_user.extra_data != extra_data:
social_user.extra_data = extra_data
# todo: get request
#self.request.session[SESSION_USER_NAME] = UserSocialAuth.objects.get(id=social_user.id)
#request.session['tmpUserProfile'] = user.get_profile()
# sending pre_update signal
self.update_user_details(user, response, details, is_new)
return user
if user is None: # new user
if not CREATE_USERS or not kwargs.get('create_user', True):
# Send signal for cases where tracking failed registering
# is useful.
socialauth_not_registered.send(sender=self.__class__,
uid=uid,
response=response,
details=details)
return None
email = details.get('email')
if email and ASSOCIATE_BY_MAIL:
# try to associate accounts registered with the same email
# address, only if it's a single object. ValueError is
# raised if multiple objects are returned
try:
user = User.objects.get(email=email)
except MultipleObjectsReturned:
raise ValueError('Not unique email address supplied')
except User.DoesNotExist:
user = None
if not user:
username = self.username(details)
user = User.objects.create_user(username=username,
email=email)
is_new = True
try:
social_user = self.associate_auth(user, uid, response, details)
except IntegrityError:
# Protect for possible race condition, those bastard with FTL
# clicking capabilities
social_user = self.get_social_auth_user(uid)
# Raise ValueError if this account was registered by another user.
if user and user != social_user.user:
raise ValueError('Account already in use.', social_user)
user = social_user.user
# Flag user "new" status
setattr(user, 'is_new', is_new)
# Update extra_data storage, unless disabled by setting
if LOAD_EXTRA_DATA:
extra_data = self.extra_data(user, uid, response, details)
if extra_data and social_user.extra_data != extra_data:
social_user.extra_data = extra_data
social_user.save()
user.social_user = social_user
# Update user account data.
self.update_user_details(user, response, details, is_new)
return user