当前位置: 首页>>代码示例>>Python>>正文


Python models.UserSocialAuth类代码示例

本文整理汇总了Python中social.apps.django_app.default.models.UserSocialAuth的典型用法代码示例。如果您正苦于以下问题:Python UserSocialAuth类的具体用法?Python UserSocialAuth怎么用?Python UserSocialAuth使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了UserSocialAuth类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _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:IuryAlves,项目名称:www.freedomsponsors.org,代码行数:7,代码来源:testdata.py

示例2: get_user_id

def get_user_id(auth_data):
    provider = auth_data['provider']
    uid = auth_data['uid']
    logger.debug('uid = {}'.format(uid))
    user_social_auth = UserSocialAuth.get_social_auth(provider, uid)
    if user_social_auth:
        user = YMUser.objects.get(id=user_social_auth.user_id)
    else:
        user = YMUser()
    if 'email' in auth_data:
        user.email = auth_data['email']
    if 'username' in auth_data:
        user.username = auth_data['username']
    if 'first_name' in auth_data:
        user.first_name = auth_data['first_name']
    if 'last_name' in auth_data:
        user.last_name = auth_data['last_name']
    if 'picture' in auth_data:
        user.icon_url = auth_data['picture']
    if 'locale' in auth_data:
        user.locale = auth_data['locale']
    # logger.debug('user save called...')
    user.save()
    if user_social_auth:
        return (user.id, False)
    user_social_auth = UserSocialAuth(user_id=user.id, provider=provider,
                                      uid=uid, extra_data=auth_data)
    user_social_auth.save()
    return (user.id, True)
开发者ID:EricDoug,项目名称:tomb,代码行数:29,代码来源:controls.py

示例3: ensure_social_user

    def ensure_social_user(self, provider, user_id, username, extra_data=None, firstname=None, lastname=None):
        from social.apps.django_app.default.models import UserSocialAuth
        import uuid

        try:
            social_auth = UserSocialAuth.objects.get(
                provider=provider,
                uid=user_id)
            user = social_auth.user

        except UserSocialAuth.DoesNotExist:
            internal_username = username
            while User.objects.filter(username=internal_username).exists():
                internal_username = username + uuid.uuid4().hex[:16]

            user = User.objects.create(
                username=internal_username,
                first_name=firstname or '',
                last_name=lastname or '')

            social_auth = UserSocialAuth(
                user=user,
                provider=provider,
                uid=user_id,
                extra_data=extra_data or {}
            )
            social_auth.save()

        return user, social_auth
开发者ID:LukeSwart,项目名称:shareabouts-api,代码行数:29,代码来源:profiles.py

示例4: save

	def save(self, profile_request):
		user = User.objects.create_user(
			username=self.cleaned_data['username'],
			email=self.cleaned_data['email'],
			first_name=self.cleaned_data['first_name'],
			last_name=self.cleaned_data['last_name'],
			)
		user.password = profile_request.password
		user.is_active = self.cleaned_data['is_active']
		user.is_staff = self.cleaned_data['is_staff']
		user.is_superuser = self.cleaned_data['is_superuser']
		user.groups = self.cleaned_data['groups']
		user.save()

		if profile_request.provider and profile_request.uid:
			social = UserSocialAuth(
				user=user,
				provider=profile_request.provider,
				uid=profile_request.uid,
				)
			social.save()

		user_profile = UserProfile.objects.get(user=user)
		user_profile.email_visible = self.cleaned_data['email_visible_to_others']
		user_profile.phone_number = self.cleaned_data['phone_number']
		user_profile.phone_visible = self.cleaned_data['phone_visible_to_others']
		user_profile.status = self.cleaned_data['status']
		user_profile.save()
		user_profile.current_room = self.cleaned_data['current_room']
		user_profile.former_rooms = self.cleaned_data['former_rooms']
		user_profile.former_houses = self.cleaned_data['former_houses']
		user_profile.save()

		return user
开发者ID:sudoroom,项目名称:farnsworth,代码行数:34,代码来源:forms.py

示例5: get_user_id

def get_user_id(auth_data):
    provider = auth_data['provider']
    uid = auth_data['uid']
    user = UserSocialAuth.get_social_auth(provider, uid)
    if user: return user.id
    user = YMUser()
    if 'email' in auth_data: user.email = auth_data['email']
    if 'username' in auth_data: user.username = auth_data['username']
    if 'first_name' in auth_data: user.first_name = auth_data['first_name']
    if 'last_name' in auth_data: user.last_name = auth_data['last_name']
    user.save()
    user_social_auth = UserSocialAuth(user_id = user.id, provider = provider,
                                    uid = uid, extra_data = auth_data)
    user_social_auth.save()
    return user.id
开发者ID:valdersoul,项目名称:tomb,代码行数:15,代码来源:controls.py

示例6: create_user

def create_user(backend, details, response, uid, username, user=None, *args, **kwargs):
    """
    Creates user. Depends on get_username pipeline.
    """
    if user:
        return {'user': user}
    if not username:
        return None
    email = details.get('email')
    original_email = None
    # email is required
    if not email:
        message = _("""your social account needs to have a verified email address in order to proceed.""")
        raise AuthFailed(backend, message)
    # Avoid hitting field max length
    if email and len(email) > 75:
        original_email = email
        email = ''
    return {
        'user': UserSocialAuth.create_user(username=username,
                                           email=email,
                                           sync_emailaddress=False),
        'original_email': original_email,
        'is_new': True
    }
开发者ID:globustech,项目名称:nodeshot,代码行数:25,代码来源:pipeline.py

示例7: social_auth_user

def social_auth_user(strategy, uid, user=None, *args, **kwargs):
    """
    Allows user to create a new account and associate a social account,
    even if that social account is already connected to a different
    user. It effectively 'steals' the social association from the
    existing user. This can be a useful option during the testing phase
    of a project.

    Return UserSocialAuth account for backend/uid pair or None if it
    doesn't exist.

    Delete UserSocialAuth if UserSocialAuth entry belongs to another
    user.
    """
    social = UserSocialAuth.get_social_auth(kwargs['backend'].name, uid)
    if social:
        if user and social.user != user:
            # Delete UserSocialAuth pairing so this account can now connect
            social.delete()
            social = None
        elif not user:
            user = social.user
    return {'social': social,
            'user': user,
            'is_new': user is None,
            'new_association': False}
开发者ID:baylee,项目名称:YAK-server,代码行数:26,代码来源:pipeline.py

示例8: download_sheet_with_user

def download_sheet_with_user(user, filename="membership.csv"):
    """
    Download the membership with a user's credentials

    :type user: users.models.User
    :param user:
    :return: boolean of successful download
    """
    try:
        social = UserSocialAuth.get_social_auth_for_user(user).get()
    except UserSocialAuth.DoesNotExist:
        return False

    extra = social.extra_data
    expiry = datetime.utcnow() + timedelta(seconds=int(extra["expires"]))
    credentials = OAuth2Credentials(
        extra["access_token"],
        settings.SOCIAL_AUTH_GOOGLE_OAUTH2_KEY,
        settings.SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET,
        extra["refresh_token"],
        expiry,
        GOOGLE_TOKEN_URI,
        None,
        revoke_uri=GOOGLE_REVOKE_URI,
    )
    service = build_service_from_credentials(credentials)
    try:
        file = service.files().get(fileId=settings.GOOGLE_MEMBERSHIP_FILE_ID).execute()
    except googleapiclient.errors.HttpError:
        return False

    url = file["exportLinks"]["text/csv"]
    resp, content = service._http.request(url)
    open(filename, "wb").write(content)
    return True
开发者ID:HackUCF,项目名称:ppl,代码行数:35,代码来源:api.py

示例9: __init__

    def __init__(self, user, request=None, provider='google-oauth2'):
        self.user = user
        self.request = request
        self.provider = provider

        self.strategy = load_strategy(request)
        self.user_social = UserSocialAuth.get_social_auth_for_user(user=self.user, provider=self.provider)[0]
        self.backend = self.user_social.get_backend_instance(strategy=self.strategy)
开发者ID:chwnam,项目名称:lifemotif,代码行数:8,代码来源:auth_dishes.py

示例10: setUp

	def setUp(self):
		provider = 'facebook'

		self.user = User.objects.create_user(email='[email protected]', password='password', username="me")
		self.user = User.objects.get(pk=self.user.pk)
		uid = '662706953856122'
		extra_data = '{"expires": "5108950", "id": "662706953856122", "access_token": "CAAH4lDiSMqkBAJWOEsle5ISozhx5xkPIF2ZA2sCpHsn4tIbR9WdYyw9ZAIBQN4XVMddWoXwvFNDrUZB8RSJcNJulE4byJn2Vnxffz9qyLPmz0lVakSZCqbPN2U6BzV3WPGZBl1ro5DvkKJzhRIOtyFy3Oi1yyvJjEk4f4bFIVCTN7VoJ2t1EdCHZBBG6uNZBnqiUj1vhIwOepnEHWkT2rZBZA"}'
		social_auth = UserSocialAuth(user=self.user, provider=provider, uid=uid, extra_data=extra_data)
		social_auth.save()

		self.user_friend = User.objects.create_user(email='[email protected]', password='password', username="friend")
		self.user_friend = User.objects.get(pk=self.user_friend.pk)
		uid = '10206250137793732'
		extra_data = '{"expires": "5183999", "id": "10206250137793732", "access_token": "CAAH4lDiSMqkBAJ4rz1HutjMkUv7gg3Blc3CR7caKWPTXwWQwoVvaleg4CWnJopnxRwoXl83JkbOZACRNeenEasyIrHOKKwQTieL9s9SaxZCbEqRZBwsC9StEn686dgshAqqtIly1ojrZBR7PSxXb9klwm0qg09qSqal98ZCZBkyGpdihlSzjfPqf7MpYR2IgejdEK9ScDzQiyeKpyQQ6ZBS"}'
		self.social_auth_friend = UserSocialAuth(user=self.user_friend, provider=provider, uid=uid, extra_data=extra_data)
		self.social_auth_friend.save()

		self.user_no_friend = User.objects.create_user(email='[email protected]', password='password', username="no_friend")
		self.user_no_friend = User.objects.get(pk=self.user_no_friend.pk)
		uid = '10153139013369780'
		extra_data = '{"expires": "5183999", "id": "10153139013369780", "access_token": "CAAH4lDiSMqkBACz9b3PYRoSgsxRUx19cdxxR8U5BWGRgVHlRwdHIL5HtMsCvlNaZBbZBK4qgr8AUPZAZBZCjIjPfjapLbyBDcelLi3rRAbGeImR8tuiK8naRQVW6sqTwP5GgZAX5BqIwFKZAlTgcCD2PzUsymZByJqld1UuSQVzMugM5V5yc9mKCgXJqhRy62MNULbZAQ0ZB543mOZAryBbZB0sn"}'
		social_auth = UserSocialAuth(user=self.user_no_friend, provider=provider, uid=uid, extra_data=extra_data)
		social_auth.save()

		self.url = '/api/facebook/friend/'
开发者ID:airsoull,项目名称:apitasty,代码行数:25,代码来源:tests.py

示例11: create_links

    def create_links(self):
        """
        Create all needed links to Django and/or UserSocialAuth.
        """
        extra_data = json.loads(self.extra_data)
        username = extra_data.get(
            'lis_person_name_full',
            extra_data.get('lis_person_sourcedid', self.user_id)
        )
        first_name = extra_data.get('lis_person_name_given', '')
        last_name = extra_data.get('lis_person_name_family', '')
        email = extra_data.get('lis_person_contact_email_primary', '').lower()

        defaults = {
            'first_name': first_name,
            'last_name': last_name,
        }

        if email:
            defaults['email'] = email
            social = UserSocialAuth.objects.filter(
                provider='email', uid=email
            ).first()
            if social:
                django_user = social.user
            else:
                django_user = User.objects.filter(email=email).first()
                if not django_user:
                    django_user, created = User.objects.get_or_create(
                        username=username, defaults=defaults
                    )
                social = UserSocialAuth(
                    user=django_user,
                    provider='email',
                    uid=email,
                    extra_data=extra_data
                )
                social.save()
        else:
            django_user, created = User.objects.get_or_create(
                username=username, defaults=defaults
            )
        self.django_user = django_user
        self.save()
开发者ID:VladimirFilonov,项目名称:socraticqs2,代码行数:44,代码来源:models.py

示例12: create_users

def create_users():
	User.objects.exclude(pk=1).delete()
	
	for pk, fields in users.iteritems():
		if pk != 1:
			if fields['email'] != '':
				existing = User.objects.filter(email = fields['email'])
				if existing.count() > 0:
					ou = existing[0]
					if ou.is_active == False and fields['is_active'] == True:
						replace_users[ou.pk] = pk
						for k,v in replace_users.iteritems():
							if v == ou.pk:
								replace_users[k] = pk
						ou.delete()
					elif ou.is_active == True and fields['is_active'] == False:
						replace_users[pk] = ou.pk
						for k,v in replace_users.iteritems():
							if v == pk:
								replace_users[k] = ou.pk
						continue
					else:
						replace_users[ou.pk] = pk
						for k,v in replace_users.iteritems():
							if v == ou.pk:
								replace_users[k] = pk
						ou.delete()

			#print "email:", fields['email']
			nu = User(pk=pk)
			nu.username = fields['username']
			if fields['email']:
				nu.email = fields['email']
				nu.status = 1
			nu.password = fields['password']
			nu.full_name = fields['profile']['full_name']
			nu.message = fields['profile']['message']
			nu.is_active = fields['is_active']
			nu.is_staff = fields['is_staff']
			nu.is_superuser = fields['is_superuser']
			nu.comment_count = fields['profile']['comment_count']
			nu.dateo_count = fields['profile']['item_count']
			nu.vote_count = fields['profile']['vote_count']
			nu.client_domain = datea
			nu.save()

			joined = date_parser(fields['date_joined'])
			lastlog = date_parser(fields['last_login'])
			User.objects.filter(pk=nu.pk).update(date_joined=joined, created=joined, last_login=lastlog)

	for pk, fields in usersSocial.iteritems():
		if fields['user'] != 1:
			nusoc = UserSocialAuth(pk=pk)
			nusoc.provider = fields['provider']
			nusoc.uid = fields['uid']
			nusoc.user_id = get_user(int(fields['user']))
			nusoc.extra_data = fields['extra_data']
			nusoc.save()
开发者ID:lafactura,项目名称:datea-migrate-db,代码行数:58,代码来源:import_data.py

示例13: profile_image_for_user

def profile_image_for_user(user):
    try:
        auth = UserSocialAuth.get_social_auth_for_user(user)[0]
        backend = auth.get_backend().name
        if backend == "google-oauth2":
            return HttpResponseRedirect(auth.extra_data["image"]["url"])
        elif backend == "facebook":
            return HttpResponseRedirect(fb_profile_image(auth.uid,50,50))
    except Exception, e:
        pass
开发者ID:michaelgiba,项目名称:JustOpenedDjango,代码行数:10,代码来源:user_tools.py

示例14: get_large_user_image

def get_large_user_image(user):
    try:
        auth = UserSocialAuth.get_social_auth_for_user(user)[0]
        backend = auth.get_backend().name
        if backend == "google-oauth2":
            url = auth.extra_data["image"]["url"]
            return HttpResponseRedirect("%s%i" % (url[:-2],200))
        elif backend == "facebook":
            return HttpResponseRedirect(fb_profile_image(auth.uid,200,200))
    except Exception, e:
        pass
开发者ID:michaelgiba,项目名称:JustOpenedDjango,代码行数:11,代码来源:user_tools.py

示例15: setUp

 def setUp(self):
     user = User.objects.create_user(username='596560',
                                     email='[email protected]',
                                     password='koichi-ezato')
     user_social_auth = UserSocialAuth()
     user_social_auth.provider = 'evernote-sandbox'
     user_social_auth.uid = '596560'
     user_social_auth.extra_data = '{"access_token": {"edam_webApiUrlPrefix": "https://sandbox.evernote.com/shard/s1/", "edam_shard": "s1", "oauth_token": "S=s1:U=91a50:E=158f7ee9efa:C=151a03d7140:P=185:A=koichi-ezato-3816:V=2:H=1a4e5efcc8f63951e17852d0c8019cab", "edam_expires": "1481628360442", "edam_userId": "596560", "edam_noteStoreUrl": "https://sandbox.evernote.com/shard/s1/notestore"}, "expires": 1481628360, "store_url": "https://sandbox.evernote.com/shard/s1/notestore", "oauth_token": "S=s1:U=91a50:E=158f7ee9efa:C=151a03d7140:P=185:A=koichi-ezato-3816:V=2:H=1a4e5efcc8f63951e17852d0c8019cab"}'
     user_social_auth.user = user
     user_social_auth.save()
开发者ID:koichi-ezato,项目名称:DevDoc,代码行数:10,代码来源:tests.py


注:本文中的social.apps.django_app.default.models.UserSocialAuth类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。