def test_user_authenticated_ulogin_exists(self):
        """
        Tests received from view data when user is authenticated and
        ulogin exists too
        """
        username, password = '******', 'demo'
        user = User.objects.create_user(username=username,
                                        password=password,
                                        email='*****@*****.**')

        def handler(**kwargs):
            self.assertFalse(kwargs['registered'])

        ULoginUser.objects.create(user=user,
                                  network=response()['network'],
                                  uid=response()['uid'])

        assign.connect(receiver=handler,
                       sender=ULoginUser,
                       dispatch_uid='test')

        self.client.login(username=username, password=password)
        self.client.post(self.url, data={'token': '31337'})

        assign.disconnect(receiver=handler,
                          sender=ULoginUser,
                          dispatch_uid='test')
    def test_user_not_authenticated_ulogin_not_exists(self):
        """
        Tests received from view data when user is not authenticated and
        ulogin not exists
        """
        username, password = '******', 'demo'
        User.objects.create_user(username=username,
                                 password=password,
                                 email='*****@*****.**')

        def handler(**kwargs):
            self.assertTrue(kwargs['registered'])

        assign.connect(receiver=handler, sender=ULoginUser,
                       dispatch_uid='test')
        self.client.post(self.url, data={'token': '31337'})
        assign.disconnect(receiver=handler, sender=ULoginUser, dispatch_uid='test')
    def test_user_not_authenticated_ulogin_not_exists(self):
        """
        Tests received from view data when user is not authenticated and
        ulogin not exists
        """
        username, password = '******', 'demo'
        User.objects.create_user(username=username,
                                 password=password,
                                 email='*****@*****.**')

        def handler(**kwargs):
            self.assertTrue(kwargs['registered'])

        assign.connect(receiver=handler, sender=ULoginUser,
                       dispatch_uid='test')
        self.client.post(self.url, data={'token': '31337'})
        assign.disconnect(receiver=handler, sender=ULoginUser,
                          dispatch_uid='test')
Exemple #4
0
    def test_user_not_authenticated_ulogin_exists(self):
        """
        Tests received from view data when user is not authenticated and
        ulogin exists
        """
        def handler(**kwargs):
            ''
            self.assertFalse( kwargs['registered'] )

        username, password = '******', 'demo'
        user = User.objects.create_user(username=username,
                                   password=password,
                                   email='*****@*****.**')
        ULoginUser.objects.create(user=user, network=response()['network'],
                                         uid=response()['uid'])

        assign.connect(receiver=handler, sender=ULoginUser,
                       dispatch_uid='test')
        self.client.post(self.url, data={'token': '31337'})
Exemple #5
0
        user.first_name = json['first_name']
        user.last_name = json['last_name']
        user.email = json['email']
        user.save()

        data = {'ulogin': ulogin}

        for fld in ['sex', 'city', 'country']:
            if fld not in json:
                return
            data[fld] = json[fld]

        if 'bdate' in json and json['bdate']:
            d, m, y = json['bdate'].split('.')
            data['bdate'] = datetime.datetime(int(y), int(m), int(d))

        userinfo = UserInfo.objects.create(**data)

        for fld in ['photo', 'photo_big']:
            if fld not in json:
                continue
            getattr(userinfo,
                    fld).save(os.path.basename(json[fld]),
                              ContentFile(requests.get(json[fld]).raw.read()))
            userinfo.save()


assign.connect(catch_ulogin_signal,
               sender=ULoginUser,
               dispatch_uid='customize.models')
Exemple #6
0
        verbose_name_plural = u'Валюты'

    def __unicode__(self):
        return self.char_code


def catch_ulogin_signal(*args, **kwargs):
    """
    Обновляет модель пользователя: исправляет username, имя и фамилию на
    полученные от провайдера.

    В реальной жизни следует иметь в виду, что username должен быть уникальным,
    а в социальной сети может быть много "тёзок" и, как следствие,
    возможно нарушение уникальности.

    """
    user=kwargs['user']
    json=kwargs['ulogin_data']

    if kwargs['registered']:
        user.full_name = json['first_name'] = ' ' + json['last_name']
        user.email = json['email']
        user.save()

from django_ulogin.models import ULoginUser
from django_ulogin.signals import assign

assign.connect(receiver=catch_ulogin_signal,
               sender=ULoginUser,
               dispatch_uid='customize.models')
Exemple #7
0
        for field in ['city', 'gender']:
            if field in json:
                setattr(user, field, json.get(field))

        if 'bdate' in json and json['bdate']:
            d, m, y = json['bdate'].split('.')
            user.birth_date = datetime(int(y), int(m), int(d))

        photo_path = json.get('photo_big')
        if photo_path:
            img_temp = NamedTemporaryFile(delete=True)
            img_temp.write(urllib2.urlopen(photo_path).read())
            img_temp.flush()

            user.photo.save(os.path.basename(photo_path), File(img_temp))

        user.save()
    else:
        for field in ('first_name', 'last_name', 'city', 'gender'):
            if not getattr(user, field) and json.get(field):
                setattr(user, field, json.get(field))
        if not user.birth_date and 'bdate' in json and json['bdate']:
            d, m, y = json['bdate'].split('.')
            user.birth_date = datetime(int(y), int(m), int(d))
        user.save()


assign.connect(receiver=catch_ulogin_signal,
               sender=ULoginUser,
               dispatch_uid='accounts.models')
    user = kwargs['user']
    ulogin = kwargs['ulogin_user']
    json = kwargs['ulogin_data']

    user.first_name = json['first_name']
    user.last_name = json['last_name']
    user.email = json['email']
    user.save()

    data = {'ulogin': ulogin, 'user': user, 'json': json}

    for fld in ['sex', 'city', 'country', 'photo', 'photo_big']:
        if fld not in json:
            continue
        data[fld] = json[fld]

    if 'bdate' in json and json['bdate']:
        d, m, y = json['bdate'].split('.')
        data['bdate'] = datetime.datetime(int(y), int(m), int(d))

    userinfo, create = UserInfo.objects.get_or_create(**{
        'ulogin': ulogin,
        'user': user
    })
    for x, y in data.iteritems():
        setattr(userinfo, x, y)
    userinfo.save()


assign.connect(receiver=catch_ulogin_signal, sender=ULoginUser)
def catch_ulogin_signal(*args, **kwargs):
    user = kwargs['user']
    ulogin = kwargs['ulogin_user']
    json = kwargs['ulogin_data']

    user.first_name = json['first_name']
    user.last_name = json['last_name']
    user.email = json['email']
    user.save()

    data = {'ulogin': ulogin, 'user': user, 'json': json}

    for fld in ['sex', 'city', 'country', 'photo', 'photo_big']:
        if fld not in json:
            continue
        data[fld] = json[fld]

    if 'bdate' in json and json['bdate']:
        d, m, y = json['bdate'].split('.')
        data['bdate'] = datetime.datetime(int(y), int(m), int(d))

    userinfo, create = UserInfo.objects.get_or_create(**{'ulogin': ulogin,
                                                         'user': user})
    for x, y in data.iteritems():
        setattr(userinfo, x, y)
    userinfo.save()


assign.connect(receiver=catch_ulogin_signal,
               sender=ULoginUser)