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"
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'
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='******') user.add_auth_id('email:[email protected]') """ provider, uid = auth_str.split(':') UserSocialAuth.create_social_auth(self, uid, provider)
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 as 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) else: return { 'social_user': social, 'user': social.user, 'new_association': True }
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))
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))
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))
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='******') user.add_auth_id('email:[email protected]') """ provider, uid = auth_str.split(':') return UserSocialAuth.create_social_auth(self, uid, provider)
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}
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)
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.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}
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())
def test_can_disconnect(self): auth = UserSocialAuth.create_social_auth(self.user, "1234", "github") with self.settings(GITHUB_APP_ID="app-id", GITHUB_API_SECRET="secret"): self.get_valid_response(self.user.id, auth.id, status_code=204) assert not len(UserSocialAuth.objects.filter(user=self.user))
def test_simple(self): UserSocialAuth.create_social_auth(self.user, "1234", "github") response = self.get_valid_response(self.user.id) assert len(response.data) == 1 assert response.data[0]["provider"] == "github"