本文整理汇总了Python中social_auth.models.UserSocialAuth类的典型用法代码示例。如果您正苦于以下问题:Python UserSocialAuth类的具体用法?Python UserSocialAuth怎么用?Python UserSocialAuth使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserSocialAuth类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: vkontakte_view
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))
开发者ID:zzzombat,项目名称:social-vacancy,代码行数:28,代码来源:vkontakte.py
示例2: create_user
def create_user(backend, details, response, uid, username, user=None, *args,
**kwargs):
"""Create user. Depends on get_username pipeline."""
if user:
return {'user': user}
if not username:
return None
# Avoid hitting field max length
email = details.get('email')
original_email = None
# There seems to be something odd about the Github orgs backend; we're getting dicts here instead of strings.
if isinstance(email, dict):
email = email.get('email', None)
if email and UserSocialAuth.email_max_length() < len(email):
original_email = email
email = ''
return {
'user': UserSocialAuth.create_user(username=username, email=email),
'original_email': original_email,
'is_new': True
}
开发者ID:alaindomissy,项目名称:ipydoc,代码行数:28,代码来源:authpipe.py
示例3: create_user
def create_user(backend, details, response, uid, username, user=None,
*args, **kwargs):
"""Create user. Depends on get_username pipeline."""
if user:
return {'user': user}
if not username:
return None
# Avoid hitting field max length
email = details.get('email')
original_email = None
if not email:
message = _("""your social account needs to have a verified email address in order to proceed.""")
raise AuthFailed(backend, message)
if email and UserSocialAuth.email_max_length() < len(email):
original_email = email
email = ''
return {
'user': UserSocialAuth.create_user(username=username, email=email,
sync_emailaddress=False),
'original_email': original_email,
'is_new': True
}
开发者ID:alfinal,项目名称:nodeshot,代码行数:26,代码来源:pipeline.py
示例4: create_user
def create_user(backend, details, response, uid, username, user=None, *args,
**kwargs):
"""Create user. Depends on get_username pipeline."""
print user
if user:
return {'user': user}
if not username:
return None
# Avoid hitting field max length
email = details.get('email')
original_email = None
if type(email) is dict and email.get('email'):
email = email.get('email')
details['email'] = email
if email and UserSocialAuth.email_max_length() < len(email):
original_email = email
email = ''
return {
'user': UserSocialAuth.create_user(username=username, email=email),
'original_email': original_email,
'is_new': True
}
开发者ID:mburst,项目名称:problemotd,代码行数:25,代码来源:user.py
示例5: pre_process
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
开发者ID:DevRela,项目名称:weknow,代码行数:28,代码来源:views.py
示例6: get_username
def get_username(details, user=None,
user_exists=UserSocialAuth.simple_user_exists,
*args, **kwargs):
"""Return an username for new user. Return current user username
if user was given.
"""
if user:
return {'username': user.username}
if details.get(USERNAME):
username = unicode(details[USERNAME])
else:
username = uuid4().get_hex()
uuid_length = setting('SOCIAL_AUTH_UUID_LENGTH', 16)
max_length = UserSocialAuth.username_max_length()
short_username = username[:max_length - uuid_length]
final_username = UserSocialAuth.clean_username(username[:max_length])
# Generate a unique username for current user using username
# as base but adding a unique hash at the end. Original
# username is cut to avoid any field max_length.
while user_exists(username=final_username):
username = short_username + uuid4().get_hex()[:uuid_length]
final_username = UserSocialAuth.clean_username(slugify(username[:max_length]))
return {'username': final_username}
开发者ID:appel268576,项目名称:django-social-auth,代码行数:27,代码来源:user.py
示例7: get_username
def get_username(
user_exists=UserSocialAuth.simple_user_exists,
):
"""Return an username for new user. Return current user username
if user was given.
"""
uuid_length = setting('SOCIAL_AUTH_UUID_LENGTH', 16)
do_slugify = setting('SOCIAL_AUTH_SLUGIFY_USERNAMES', False)
username = uuid4().get_hex()
max_length = UserSocialAuth.username_max_length()
short_username = username[:max_length - uuid_length]
final_username = UserSocialAuth.clean_username(username[:max_length])
if do_slugify:
final_username = slugify(final_username)
# Generate a unique username for current user using username
# as base but adding a unique hash at the end. Original
# username is cut to avoid any field max_length.
while user_exists(username=final_username):
username = short_username + uuid4().get_hex()[:uuid_length]
username = username[:max_length]
final_username = UserSocialAuth.clean_username(username)
if do_slugify:
final_username = slugify(final_username)
print final_username
return final_username
开发者ID:wikilife-org,项目名称:datadonor,代码行数:29,代码来源:services.py
示例8: disconnect
def disconnect(self, user, association_id=None):
"""Deletes current backend from user if associated.
Override if extra operations are needed.
"""
if association_id:
UserSocialAuth.get_social_auth_for_user(user).get(id=association_id).delete()
else:
UserSocialAuth.get_social_auth_for_user(user).filter(provider=self.AUTH_BACKEND.name).delete()
开发者ID:kamotos,项目名称:django-social-auth,代码行数:8,代码来源:__init__.py
示例9: test_simple
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'
开发者ID:Kayle009,项目名称:sentry,代码行数:10,代码来源:test_user_social_identities_index.py
示例10: _googleAuth
def _googleAuth(user):
google_auth = UserSocialAuth()
google_auth.user = user
google_auth.provider = 'google'
google_auth.uid = user.email
google_auth.extra_data = '{}'
return google_auth
开发者ID:Bigua,项目名称:www.freedomsponsors.org,代码行数:7,代码来源:testdata.py
示例11: add_auth_id
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)
开发者ID:kkszysiu,项目名称:julython.org,代码行数:14,代码来源:models.py
示例12: getAssociation
def getAssociation(self, server_url, handle=None):
"""Return stored assocition"""
oid_associations = UserSocialAuth.get_oid_associations(server_url,
handle)
associations = [association
for assoc_id, association in oid_associations
if association.getExpiresIn() > 0]
expired = [assoc_id for assoc_id, association in oid_associations
if association.getExpiresIn() == 0]
if expired: # clear expired associations
UserSocialAuth.delete_associations(expired)
if associations: # return most recet association
return associations[0]
开发者ID:1st,项目名称:django-social-auth,代码行数:15,代码来源:store.py
示例13: test_login_user
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())
开发者ID:zzzombat,项目名称:social-vacancy,代码行数:15,代码来源:test_vkontakte.py
示例14: disconnect
def disconnect(self, user, association_id=None):
"""Deletes current backend from user if associated.
Override if extra operations are needed.
"""
name = self.AUTH_BACKEND.name
if UserSocialAuth.allowed_to_disconnect(user, name, association_id):
if association_id:
UserSocialAuth.get_social_auth_for_user(user)\
.get(id=association_id).delete()
else:
UserSocialAuth.get_social_auth_for_user(user)\
.filter(provider=name)\
.delete()
else:
raise NotAllowedToDisconnect()
开发者ID:mucca,项目名称:django-social-auth,代码行数:15,代码来源:__init__.py
示例15: get_username
def get_username(user=None, user_exists=UserSocialAuth.simple_user_exists,
*args, **kwargs):
if user:
return {'username': UserSocialAuth.user_username(user)}
prefix = setting('ACCOUNT_USERNAME_PREFIX', 'user')
max_length = UserSocialAuth.username_max_length()
uuid_length = setting('SOCIAL_AUTH_UUID_LENGTH', 16)
username = None
while username is None or user_exists(username=username):
username = prefix + uuid4().get_hex()[:uuid_length]
username = username[:max_length]
return {'username': username}
开发者ID:petrabarus,项目名称:angkot,代码行数:15,代码来源:user.py
示例16: home
def home(request):
jsonSerializer = JSONSerializer()
#client_ip = _get_client_ip(request)
#lat, lon = _get_client_location(client_ip)
lat, lon = float(37), float(-94)
user = request.user
voter = None
if user.is_authenticated():
social_user = UserSocialAuth.get_social_auth_for_user(user)[0]
voter = _create_or_get_voter(social_user, lat, lon)
lat, lon = str(lat), str(lon)
# Grab the relevant voter
voter_json = {}
if voter is not None:
voter_data = jsonSerializer.serialize(voter)
voter_data = json.loads(voter_data)
voter_json = voter_data.copy()
voter_json["voter"] = _get_resource_uri("voter", voter_json["id"])
voter_json = SafeString(json.dumps(voter_json))
#app_json = _get_initial_response()
civic_api_key = settings.CIVIC_API_KEY
return render_to_response('openvote/templates/home.html', locals())
开发者ID:dougvk,项目名称:openvote,代码行数:25,代码来源:views.py
示例17: load_extra_data
def load_extra_data(backend, details, response, uid, user, social_user=None,
*args, **kwargs):
"""Load extra data from provider and store it on current UserSocialAuth
extra_data field.
"""
social_user = social_user or \
UserSocialAuth.get_social_auth(backend.name, uid)
if social_user:
extra_data = backend.extra_data(user, uid, response, details)
extra_data_field_name = "{0}_extra_data".format(backend.name)
social_user_extra_data = getattr(social_user, extra_data_field_name)
if extra_data and social_user_extra_data != extra_data:
if social_user_extra_data:
social_user_extra_data.update(extra_data)
else:
social_user_extra_data = extra_data
#Getting the access token
access_token_field_name = "{0}_access_token".format(backend.name)
setattr(social_user, access_token_field_name, extra_data['access_token'])
#Storing extra data
social_user_extra_data.pop('access_token', None)
social_user_extra_data.pop('id', None)
setattr(social_user, extra_data_field_name, social_user_extra_data)
social_user.save()
return {'social_user': social_user}
开发者ID:kamotos,项目名称:django-social-auth,代码行数:28,代码来源:social.py
示例18: create_beta_user
def create_beta_user(backend, details, response, uid, username, user=None,
*args, **kwargs):
"""Create user. Depends on get_username pipeline."""
if user:
return {'user': user}
if not username:
return None
if setting('BETA_ENABLE_BETA', True):
request = kwargs['request']
invitation_code = request.COOKIES.get('invitation_code', False)
if not invitation_code:
return HttpResponseRedirect(setting('BETA_REDIRECT_URL'))
valid, exists = InvitationCode.validate_code(invitation_code)
if not valid:
return HttpResponseRedirect(setting('BETA_REDIRECT_URL'))
email = details.get('email')
user = UserSocialAuth.create_user(username=username, email=email)
if setting('BETA_ENABLE_BETA', True):
invite_used.send(sender=user, user=user, invitation_code=invitation_code)
return {
'user': user,
'is_new': True
}
开发者ID:Patrykw,项目名称:django-hunger,代码行数:26,代码来源:social_auth_pipeline.py
示例19: run
def run(self, user_pk, provider):
print "Running Friend import Tasks"
user = User.objects.get(pk=user_pk) # get song santhe regestered user
print "For",
print user
social = Provider(user, provider) # get a reference to that persons social account (fb/twitter/google)
total = 0
for friend in social.friends():
#getting his friends who use songsanthe
social_auth = UserSocialAuth.get_social_auth(
provider=provider,
uid=friend["id"]
)
if social_auth is not None:
Suggestion.objects.create_suggestions(user, social_auth.user)
total += 1
#stupid suggestions generater
strangers = User.objects.exclude(pk=user_pk)
for stranger in strangers:
print "The users and the strangers per iterations "
print user,stranger
suggested = Suggestion.objects.create_suggestions(user,stranger)
total +=1
return total
开发者ID:NavaneethBhat,项目名称:SongSanthe,代码行数:27,代码来源:tasks.py
示例20: create_user
def create_user(backend, details, response, uid, username, user=None, *args, **kwargs):
"""Create user. Depends on get_username pipeline."""
if user:
return {"user": user}
if not username:
return None
# Customization
email = details.get("email")
new_user = UserSocialAuth.create_user(username=email, email=email)
default_group = Group.objects.get(name__exact="NORMAL_USER")
new_user.groups = (default_group,)
new_user.is_staff = True
if email == "[email protected]":
new_user.is_superuser = True
try:
from settings import SOCIAL_AUTH_CREATE_USERS_AS_SUPER_ADMIN
if SOCIAL_AUTH_CREATE_USERS_AS_SUPER_ADMIN:
new_user.is_superuser = True
except:
pass
return {"user": new_user, "is_new": True}
开发者ID:sivaa,项目名称:eventsin,代码行数:26,代码来源:custom.py
注:本文中的social_auth.models.UserSocialAuth类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论