예제 #1
0
    def _create_user(self, data, email):
        username = self._find_available_username(data)

        first_name = data.get('first_name')
        last_name = data.get('last_name')
        facebook_uid = data.get('uid')
        img_url = data.get('pic_square')
        if email is None:
            email = FacebookAuthBackend._generate_email(first_name)

        user = User(username=username,
                    email=email,
                    first_name=first_name,
                    last_name=last_name)
        temp_password = User.objects.make_random_password(length=24)
        user.set_password(temp_password)
        user.save()

        if img_url:
            img = ContentFile(requests.get(img_url).content)
            name = img_url.split('/')[-1]
            user.picture.save(name, img, False)
        FacebookAccount.objects.create(uid=facebook_uid,
                                       user=user,
                                       avatar=img_url)

        return user
예제 #2
0
 def test_notifications_unicode(self):
     self.assertEqual(len(mail.outbox), 0)
     user = User(email=u'Leandro André[email protected]',
                 username='******')
     user.set_password("secret")
     user.save()
     self.assertEqual(len(mail.outbox), 1)
예제 #3
0
파일: tests.py 프로젝트: thi517/unisubs
 def test_update_non_profile_fields(self):
     # Updated non-profile fields shouldn't result in the signal
     u = User()
     with test_utils.mock_handler(signals.user_profile_changed) as handler:
         u.show_tutorial = False
         u.save()
         assert_false(handler.called)
예제 #4
0
파일: tests.py 프로젝트: thi517/unisubs
 def test_create(self):
     # We shouldn't emit the signal when we initially create a user
     with test_utils.mock_handler(signals.user_profile_changed) as handler:
         u = User()
         u.first_name = 'ben'
         u.save()
         assert_false(handler.called)
예제 #5
0
    def authenticate(self, access_token):
        '''authenticates the token by requesting user information from twitter
        '''
        twitter = oauthtwitter.OAuthApi(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, access_token)

        try:
            userinfo = twitter.GetUserInfo()
        except:
            # If we cannot get the user information, user cannot be authenticated
            raise

        screen_name = userinfo.screen_name
        img_url = userinfo.profile_image_url
        
        try:
            user_profile = TwitterUserProfile.objects.get(screen_name = screen_name)
            if user_profile.user.is_active:
                return user_profile.user
            else:
                return        
        except TwitterUserProfile.DoesNotExist:
            #Create new user
            same_name_count = User.objects.filter(username__startswith = screen_name).count()
            if same_name_count:
                username = '******' % (screen_name, same_name_count + 1)
            else:
                username = screen_name
            username = '******'+username
            
            name_count = AuthUser.objects.filter(username__startswith = username).count()
                
            if name_count:
                username = '******'%(username, name_count + 1)
                            
            user = User(username =  username)
            temp_password = User.objects.make_random_password(length=12)
            user.set_password(temp_password)
            name_data = userinfo.name.split()
            try:
                first_name, last_name = name_data[0], ' '.join(name_data[1:])
            except:
                first_name, last_name =  screen_name, ''
            user.first_name, user.last_name = first_name, last_name
            if img_url:
                img = ContentFile(urlopen(img_url).read())
                name = img_url.split('/')[-1]
                user.picture.save(name, img, False)            
            #user.email = '%s@twitteruser.%s.com'%(userinfo.screen_name, settings.SITE_NAME)
            user.save()
            userprofile = TwitterUserProfile(user = user, screen_name = screen_name)
            userprofile.access_token = access_token.key
            userprofile.url = userinfo.url
            userprofile.location = userinfo.location
            userprofile.description = userinfo.description
            userprofile.profile_image_url = userinfo.profile_image_url
            userprofile.save()
            AuthMeta(user=user, provider='Twitter').save()
            return user
예제 #6
0
    def authenticate(self, access_token):
        '''authenticates the token by requesting user information from twitter
        '''
        twitter = oauthtwitter.OAuthApi(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, access_token)

        try:
            userinfo = twitter.GetUserInfo()
        except:
            # If we cannot get the user information, user cannot be authenticated
            raise

        screen_name = userinfo.screen_name
        img_url = userinfo.profile_image_url
        
        try:
            user_profile = TwitterUserProfile.objects.get(screen_name = screen_name)
            if user_profile.user.is_active:
                return user_profile.user
            else:
                return        
        except TwitterUserProfile.DoesNotExist:
            #Create new user
            same_name_count = User.objects.filter(username__startswith = screen_name).count()
            if same_name_count:
                username = '******' % (screen_name, same_name_count + 1)
            else:
                username = screen_name
            username = '******'+username
            
            name_count = AuthUser.objects.filter(username__startswith = username).count()
                
            if name_count:
                username = '******'%(username, name_count + 1)
                            
            user = User(username =  username)
            temp_password = User.objects.make_random_password(length=12)
            user.set_password(temp_password)
            name_data = userinfo.name.split()
            try:
                first_name, last_name = name_data[0], ' '.join(name_data[1:])
            except:
                first_name, last_name =  screen_name, ''
            user.first_name, user.last_name = first_name, last_name
            if img_url:
                img = ContentFile(urlopen(img_url).read())
                name = img_url.split('/')[-1]
                user.picture.save(name, img, False)            
            #user.email = '%s@twitteruser.%s.com'%(userinfo.screen_name, settings.SITE_NAME)
            user.save()
            userprofile = TwitterUserProfile(user = user, screen_name = screen_name)
            userprofile.access_token = access_token.key
            userprofile.url = userinfo.url
            userprofile.location = userinfo.location
            userprofile.description = userinfo.description
            userprofile.profile_image_url = userinfo.profile_image_url
            userprofile.save()
            AuthMeta(user=user, provider='Twitter').save()
            return user
예제 #7
0
    def _create_user(self, access_token, data):
        username = self._find_available_username(data)

        twitter_username = data.screen_name
        first_name, last_name = self._get_first_last_name(data)
        avatar = data.profile_image_url

        email = '%s@twitteruser.%s.com' % (twitter_username, settings.SITE_NAME)

        user = User(username=username, email=email, first_name=first_name,
                    last_name=last_name)
        temp_password = User.objects.make_random_password(length=24)
        user.set_password(temp_password)
        user.save()

        TwitterAccount.objects.create(user=user, username=twitter_username,
                                      access_token=access_token.key,
                                      avatar=avatar)

        return user
예제 #8
0
        def test_contribuitors_do_bypass_moderation(self):
            lang = self.video.subtitle_language()
            member, created = TeamMember.objects.get_or_create(user=self.user, team=self.team)
            member.role=TeamMember.ROLE_MANAGER
            member.save()
            add_moderation(self.video, self.team, self.user)
            joe_doe = User(username="******", password="******", email="*****@*****.**")
            joe_doe.save()
            joe_member, c = TeamMember.objects.get_or_create(user=joe_doe, team=self.team)
            joe_member.save()
            v0 = self._create_versions(lang, 1, user=joe_doe)[0]
            self.assertEquals(v0.moderation_status,WAITING_MODERATION)
            joe_member.promote_to_contributor()
            joe_doe = refresh_obj(joe_doe)

            self.assertTrue(self.team.is_contributor(joe_doe, authenticated=False))
            v1 = self._create_versions(lang, 1, user=joe_doe)[0]
            metadata_manager.update_metadata(self.video.pk)
            v1 = refresh_obj(v1)
            self.assertEquals(v1.moderation_status, APPROVED)
예제 #9
0
    def _create_user(self, access_token, data, email):
        username = self._find_available_username(data)

        twitter_username = data.screen_name
        first_name, last_name = self._get_first_last_name(data)
        avatar = data.profile_image_url
        if email is None:
            email = TwitterAuthBackend._generate_email(twitter_username)

        user = User(username=username,
                    email=email,
                    first_name=first_name,
                    last_name=last_name)
        temp_password = User.objects.make_random_password(length=24)
        user.set_password(temp_password)
        user.save()

        TwitterAccount.objects.create(user=user,
                                      username=twitter_username,
                                      access_token=access_token.key,
                                      avatar=avatar)

        return user
예제 #10
0
파일: tests.py 프로젝트: appsembler/unisubs
 def test_notfications(self):
     self.assertEqual(len(mail.outbox), 0)
     user = User(email='*****@*****.**', username='******')
     user.set_password("secret")
     user.save()
     self.assertEqual(len(mail.outbox), 1)
예제 #11
0
    def test_email_diff_subtitles(self):
        initial_count = len(mail.outbox)
        # set a user who can receive notification
        # make sure we have a different author, else he won't get notified
        author = User(username='******',
                      email='*****@*****.**',
                      notify_by_email=True,
                      valid_email=True)
        author.save(send_email_confirmation=False)
        # bypass logic from hell
        author.valid_email = True
        author.save()

        # this is needed for the non_editor template check
        user2 = User(username='******',
                     email='*****@*****.**',
                     notify_by_email=True,
                     valid_email=True)
        user2.save(send_email_confirmation=False)
        # bypass logic from hell
        user2.valid_email = True
        user2.save()
        # version is indentical to previous one
        video, video_url = Video.add("http://wwww.example.com/video-diff.mp4",
                                     None)
        video.followers.add(author)
        video.followers.add(user2)

        language = SubtitleLanguage(video=video, language_code='en')
        language.save()
        subs_data = [
            [0, 1000, '1'],
            [1000, 2000, '2'],
        ]

        subtitles_1 = SubtitleSet.from_list('en', subs_data)
        old_version = language.add_version(subtitles=subtitles_1,
                                           author=author)

        # now we change the text on the second sub
        subs_data[1][2] = '2 changed'
        # add a regular sub
        subs_data.append([2000, 3000, 'new sub'])
        # add an unsyced
        subs_data.append([None, None, 'no sync'])
        subtitles_2 = SubtitleSet.from_list('en', subs_data)
        new_version = language.add_version(subtitles=subtitles_2)
        self.assertTrue(len(video.notification_list()) > 0)

        res = send_new_version_notification(new_version.pk)
        self.assertNotEqual(res, None)
        # we expect two emails, one is the new-edits-non-editor, and
        # the other for mail_notification.html
        self.assertEqual(len(mail.outbox), initial_count + 2)
        for email_number, email_msg in enumerate(mail.outbox):
            # make sure this is the right message
            self.assertIn("New edits to ", email_msg.subject)
            self.assertIn("video-diff.mp4", email_msg.subject)
            html = BeautifulSoup(email_msg.body)
            html_text = "".join(html.body(text=True)).replace("\n", "")
            if email_number == 0:
                # assert text and timing changes are correct
                self.assertIn('67% of the text', html_text)
                self.assertIn('33% of the timing was changed.', html_text)
            # find the listed text changes to make sure they match
            diff_table = html.findAll('table', attrs={'class': 'diffs'})[0]
            old_version_changes = []
            new_version_changes = []
            for i, node in enumerate(diff_table.findAll('td')):
                if i % 2 == 0:
                    old_version_changes.append(node.text)
                else:
                    new_version_changes.append(node.text)
            self.assertEqual(old_version_changes, [u'2', u'', u''])
            self.assertEqual(new_version_changes, [
                u'2 changed',
                u'new sub',
                u'no sync',
            ])
예제 #12
0
파일: views.py 프로젝트: oaleeapp/EguoWorld
def facebook_login(request,
                   next=None,
                   confirmed=False,
                   email=None,
                   form_data=None):
    data = parse_signed_request(
        request.COOKIES['fbsr_' + settings.FACEBOOK_APP_ID],
        settings.FACEBOOK_SECRET_KEY)
    if data is None or \
       datetime.datetime.now() - datetime.datetime.fromtimestamp(data['issued_at']) > datetime.timedelta(minutes=2):
        return redirect('auth:login')
    next = request.GET.get('next', settings.LOGIN_REDIRECT_URL)
    try:
        account = FacebookAccount.objects.get(uid=data['user_id'])
        user = account.user
        if user.is_active:
            user = authenticate(facebook=True, user=user)
            auth_login(request, user)
            return redirect(next)
        else:
            account.delete()
            raise FacebookAccount.DoesNotExist
    except FacebookAccount.DoesNotExist:
        if confirmed:
            if form_data is not None and \
               'avatar' in form_data and \
               'first_name' in form_data and \
               'last_name' in form_data and \
               len(form_data['first_name'] + form_data['last_name']) > 0:
                user_created = False
                first_name = form_data['first_name']
                last_name = form_data['last_name']
                facebook_uid = data['user_id']
                img_url = form_data['avatar']
                email = email
                username_to_try = username_base = form_data['first_name']
                index = 1
                temp_password = User.objects.make_random_password(length=24)
                while not user_created:
                    try:
                        user = User(username=username_to_try,
                                    email=email,
                                    first_name=first_name,
                                    last_name=last_name)
                        user.set_password(temp_password)
                        user.save()
                        user_created = True
                    except:
                        username_to_try = '%s%d' % (username_base, index)
                        index += 1
                if img_url:
                    img = ContentFile(requests.get(img_url).content)
                    name = img_url.split('/')[-1]
                    user.picture.save(name, img, False)
                    FacebookAccount.objects.create(uid=facebook_uid,
                                                   user=user,
                                                   avatar=img_url)
                user = authenticate(facebook=True, user=user)
                auth_login(request, user)
                return redirect('/')
        else:
            return redirect('auth:confirm_create_user', 'facebook', email)
    return redirect('auth:login')