Пример #1
0
 def process_request(self, request):
     if request.user.is_authenticated():
         now = datetime.now()
         if now - request.user.last_access > settings.LAST_ACCESS_UPDATE_INTERVAL:
             request.user.last_access = now
             User.objects(id=request.user.id).update_one(
                 set__last_access=now)
Пример #2
0
    def setUp(self):
        self.cleanUp()

        self.c = Client()

        self.acc1 = User.create_user(email='*****@*****.**', password='******')
        self.acc2 = User.create_user(email='*****@*****.**', password='******')

        self.c.login(email='*****@*****.**', password='******')
Пример #3
0
    def setUp(self):
        self.cleanUp()

        self.c = Client()

        self.acc1 = User.create_user(email='*****@*****.**', password='******')
        self.acc2 = User.create_user(email='*****@*****.**', password='******')

        self.c.login(email='*****@*****.**', password='******')
Пример #4
0
    def setUp(self):
        User.objects.delete()

        self.c = Client()

        self.test_user = User.create_user(email='*****@*****.**', password='******')
        self.current_user = User.create_user(email='*****@*****.**', password='******')

        self.c.login(email='*****@*****.**', password='******')
Пример #5
0
    def setup_users(self):
        self.test_user = User.create_user(email='*****@*****.**', password='******')
        self.current_user = User.create_user(email='*****@*****.**', password='******')
        self.online_users.append(self.current_user)
        self.online_users.append(self.test_user)

        for i in range(USERS_COUNT):
            user = User.create_user(email='*****@*****.**' % i, password='******')
            user.save()
            self.online_users.append(user)
Пример #6
0
 def setUp(self):
     self.tearDown()
     self.c = Client()
     self.user_group_admin = User.create_user(
         email='*****@*****.**', password='******')
     self.user_other = User.create_user(email='*****@*****.**',
                                        password='******')
     self.user_superuser = User.create_user(email='*****@*****.**',
                                            password='******',
                                            is_superuser=True)
Пример #7
0
    def setup_users(self):
        self.test_user = User.create_user(email='*****@*****.**',
                                          password='******')
        self.current_user = User.create_user(email='*****@*****.**',
                                             password='******')
        self.online_users.append(self.current_user)
        self.online_users.append(self.test_user)

        for i in range(USERS_COUNT):
            user = User.create_user(email='*****@*****.**' % i,
                                    password='******')
            user.save()
            self.online_users.append(user)
Пример #8
0
 def wrapper():
     sender = cache.get('CALL_EVENT_%s' % request.user.id, None)
     if sender is None:
         return ''
     sender = User.objects(id=sender).first()
     if not sender:
         return ''
     return str(sender)
Пример #9
0
 def setUp(self):
     self.acc1 = User.create_user(email='*****@*****.**',
                                  password='******')
     self.news_object = News(title="test news title",
                             text="test news text",
                             preview_text="test news preview text",
                             author=self.acc1)
     self.news_object.save()
Пример #10
0
 def wrapper():
     sender = cache.get('CALL_EVENT_%s' % request.user.id, None)
     if sender is None:
         return ''
     sender = User.objects(id=sender).first()
     if not sender:
         return ''
     return str(sender)
Пример #11
0
    def test_last_name(self):
        email = RegisterTestCase.data_dict['email']
        data_dict = RegisterTestCase.data_dict.copy()

        for tpl in ['','      ','12345', u'Ять']:
            data_dict['last_name'] = tpl
            response = self.c.post('/', data_dict)
            self.assertEqual(response.status_code, 200)
            self.assertEqual(User.objects(email=email).count(), 0)
Пример #12
0
 def setUp(self):
     self.acc1 = User.create_user(email='*****@*****.**', password='******')
     self.news_object = News(
         title="test news title",
         text="test news text",
         preview_text="test news preview text",
         author=self.acc1 
     )
     self.news_object.save()
Пример #13
0
def user_list_file(request, format):
    mimetypes = dict(
            txt='text/plain',
            xml='xml/plain',
    )
    return direct_to_template(request,
                              'admin/user_list.%s' % format,
                              dict(list=User.objects(), mimetype=mimetypes[format])
    )
Пример #14
0
    def test_view_file_not_found(self):
        theme = Theme.from_zip(os.path.join(os.path.dirname(__file__),
                                            'files/theme1.zip'))
        client = Client()
        user = User.create_user(email='*****@*****.**', password='******')
        client.login(email='*****@*****.**', password='******')
        response = client.get(reverse('themes:file_view',
                                      kwargs=dict(theme_id=theme.id,
                                                  file_name='not_found.css')
                           ))

        self.failUnlessEqual(404, response.status_code)
Пример #15
0
def call_user(request, id, user_id=None):
    recipient = User.objects(id=id).first()
    if not recipient:
        return HttpResponse('NOT FOUND')
    if not recipient.is_online():
        return HttpResponse('OFFLINE')
    last_view = cache.get('LAST_VIEW_%s' % recipient.id, None)
    if last_view is None:
        user_id = user_id or request.user.id
        cache.set('CALL_EVENT_%s' % recipient.id, user_id, settings.VIDEO_CALL_INTERVAL_UPDATE)
        return HttpResponse('WHITE')
    return HttpResponse('OK')
Пример #16
0
def _send_invite(sender, email, name):
    if User.objects(email=email).count():
        return (email, _('User already registered'), False)

    invite = Invite(sender=sender,
                recipient_email=email,
                recipient_name=name)

    invite.save()
    invite.send()

    return (email, _('Invite sent'), True)
Пример #17
0
 def setUp(self):
     self.cleanUp()
     self.c = Client()
     self.user = User.create_user(email='*****@*****.**', password='******')
     self.base_url = reverse('operator')
     self.auth_dict = {
         'duser': settings.PKSPB_DUSER,
         'dpass': settings.PKSPB_DPASS,
         'cid': self.user.id,
         'sid': '1',
     }
     self.TRANS_COUNT = 100
Пример #18
0
def call_user(request, id):
    session_key = request.GET.get('session_key', None)
    if not session_key:
        return HttpResponse('Need session_key')
    engine = import_module(settings.SESSION_ENGINE)
    session = engine.SessionStore(session_key)
    user_id = session.get(SESSION_KEY, None)
    if not user_id:
        return HttpResponse('Bad session_key')
    user = User.objects(id=user_id).first()
    if not user:
        return HttpResponse('Can`t find request user')
    return ajax_call_user(request, id, user.id)
Пример #19
0
def call_user(request, id, user_id=None):
    recipient = User.objects(id=id).first()
    if not recipient:
        return HttpResponse('NOT FOUND')
    if not recipient.is_online():
        return HttpResponse('OFFLINE')
    last_view = cache.get('LAST_VIEW_%s' % recipient.id, None)
    if last_view is None:
        user_id = user_id or request.user.id
        cache.set('CALL_EVENT_%s' % recipient.id, user_id,
                  settings.VIDEO_CALL_INTERVAL_UPDATE)
        return HttpResponse('WHITE')
    return HttpResponse('OK')
Пример #20
0
def call_user(request, id):
    session_key = request.GET.get('session_key', None)
    if not session_key:
        return HttpResponse('Need session_key')
    engine = import_module(settings.SESSION_ENGINE)
    session = engine.SessionStore(session_key)
    user_id = session.get(SESSION_KEY, None)
    if not user_id:
        return HttpResponse('Bad session_key')
    user = User.objects(id=user_id).first()
    if not user:
        return HttpResponse('Can`t find request user')
    return ajax_call_user(request, id, user.id)
Пример #21
0
    def test_view(self):
        theme = Theme.from_zip(os.path.join(os.path.dirname(__file__),
                                            'files/theme1.zip'))
        client = Client()
        user = User.create_user(email='*****@*****.**', password='******')
        client.login(email='*****@*****.**', password='******')

        response = client.get(reverse('themes:file_view',
                                      kwargs=dict(theme_id=theme.id,
                                                  file_name='style.css')
                           ))

        self.failUnlessEqual(200, response.status_code)

        self.failIfEqual(-1, response.content.find('background-image'))
        self.assertEquals('text/css', response['Content-Type'])
Пример #22
0
    def test_phone(self):
        email = RegisterTestCase.data_dict['email']
        data_dict = RegisterTestCase.data_dict.copy()

        for tpl1,tpl2 in [
                ('1234','1234567'),
                ('1-23','123-4567'),
                ('1 23','123 4567'),
                ('qwe','qwertyu'),
                ('12','123456'),
                ('','1234567'),
                ('123',''),
                ]:
            data_dict['phone_0'] = tpl1
            data_dict['phone_1'] = tpl2
            response = self.c.post('/', data_dict)
            self.assertEqual(response.status_code, 200)
            self.assertEqual(User.objects(email=email).count(), 0)
Пример #23
0
 def setUp(self):
     self.tearDown()
     self.c = Client()
     self.user_group_admin = User.create_user(email='*****@*****.**', password='******')
     self.user_other = User.create_user(email='*****@*****.**', password='******')
     self.user_superuser = User.create_user(email='*****@*****.**', password='******', is_superuser=True)
Пример #24
0
 def handle(self, *args, **options):
     for user in User.objects().order_by('-date_joined'):
         print user.email, '\t', user.date_joined
Пример #25
0
def for_identity(identity, request):
    """
    uid: google,vkontakte,facebook,twitter,loginza,lastffm,
    language: google,flickr, yahoo
    email: google, yandex,facebook,loginza,flickr, yahoo
    name 
        first_name: google,vkontakte,facebook,loginza,
        last_name: google,vkontakte,facebook,loginza,
        full_name: google, yandex,facebook,twitter,loginza,flickr, yahoo, lastffm,
    dob: yandex,vkontakte,facebook,loginza,
    nickname: yandex,vkontakte,twitter,loginza,flickr, yahoo, lastffm,
    photo: vkontakte, facebook,twitter,loginza,flickr, yahoo, lastffm,
    gender: vkontakte,facebook,loginza,flickr, yahoo, lastffm,
    address
        home
            country: vkontakte, lastffm,
    web: twitter
        default: lastffm,
    biography: twitter,
    """
    try:
        user_map = UserMap.objects.get(identity=identity)
    except:
        # if there is authenticated user - map identity to that user
        # if not - create new user and mapping for him
        if request.user.is_authenticated():
            user = request.user
        else:
            loginza_data = json.loads(identity.data)
            loginza_name_dict = dict(first_name='', last_name='', full_name='')
            loginza_home_dict = dict(country='')
            loginza_address_dict = dict(home=loginza_home_dict)

            loginza_email = loginza_data.get('email', '')
            loginza_uid = loginza_data.get('uid', '')
            loginza_language = loginza_data.get('language', '')
            loginza_first_name = loginza_data.get('name', loginza_name_dict)\
                                             .get('first_name','')
            loginza_last_name = loginza_data.get('name', loginza_name_dict)\
                                            .get('last_name','')
            loginza_full_name = loginza_data.get('name', loginza_name_dict)\
                                            .get('full_name','')
            if not loginza_first_name and not loginza_last_name \
            and loginza_full_name:
                loginza_first_name = loginza_full_name
            loginza_dob = loginza_data.get('dob', '')
            loginza_nickname = loginza_data.get('nickname', '')
            loginza_photo = loginza_data.get('photo', '')
            loginza_gender = loginza_data.get('gender', '')
            loginza_country = loginza_data.get('address', loginza_address_dict)\
                                          .get('home', loginza_home_dict)\
                                          .get('country', '')
            loginza_web = loginza_data.get('web', '')
            if isinstance(loginza_web, dict):
                loginza_web = loginza_web.get('default', '')
            loginza_bio = loginza_data.get('biography', '')

            email = loginza_email if '@' in loginza_email else settings.DEFAULT_EMAIL

            if loginza_email:
                username = loginza_email
            elif loginza_nickname:
                username = loginza_nickname
            elif 'uid' in loginza_data:
                username = str(loginza_data['uid'])
            else:
                username = loginza_data['identity']

            # if nickname is not set - try to get it from email
            # e.g. [email protected] -> vgarvardt
            loginza_nickname = loginza_data.get('nickname', None)
            username = loginza_nickname if loginza_nickname is not None else email.split(
                '@')[0]
            if 'uid' in loginza_data:
                username = str(loginza_data['uid'])

            try:
                user = User.objects.get(username=username)
            except Exception, e:
                try:
                    user = User.objects.get(email=email)
                except:
                    user = User(username=username,
                                email=email,
                                first_name=loginza_first_name,
                                last_name=loginza_last_name)
                    user.save()
                    profile = user.profile
                    if loginza_dob:
                        profile.birthday = loginza_dob
                    if loginza_gender:
                        profile.sex = loginza_gender
                    if loginza_web:
                        profile.website = loginza_web
                    if loginza_dob or loginza_gender or loginza_web:
                        profile.save()
        user_map = UserMap(identity=identity, user=user)
        signals.created.send(request, user_map=user_map)
Пример #26
0
def cam_view_notify(request, format):
    """ API:
        ?session_key=<Fx24>&camera_id=<Fx24>&status=connect
        ?session_key=<Fx24>&camera_id=<Fx24>&status=next&time=<sec>
        ?session_key=<Fx24>&camera_id=<Fx24>&status=disconnect&time=<sec>

        0 OK

        -1 BAD PARAMS
        -500 INTERNAL ERROR
    """

    from apps.media.documents import File

    request_id = time()

    def log_debug(text):
        info = '\n'.join([
            "session_key=%s" % session_key,
            "user_id=%s" % user.id if user else None,
            "camera_id=%s" % camera_id,
        ])
        logger.debug('cam_view_notify %s\n%s\n%s' % (request_id, info, text))

    logger.debug('cam_view_notify %s\nrequest %s' %
                 (request_id, repr(request.GET.items())))

    user = None
    session_key = None
    camera_id = None
    try:
        if not request.GET:
            raise CameraAccessor.APIException("Bad params")
        status = request.GET.get('status', None)
        session_key = request.GET.get('session_key', None)
        camera_id = request.GET.get('camera_id', None)
        if not (status and session_key and camera_id):
            raise CameraAccessor.APIException("Bad params")
        extra_time = request.GET.get('time', None)
        if extra_time is not None:
            if not extra_time.isdigit():
                raise CameraAccessor.APIException("Time must by a digit")
            extra_time = int(extra_time)
            if extra_time > settings.TIME_INTERVAL_NOTIFY or extra_time < 0:
                raise CameraAccessor.APIException("Bad time interval")

        # extract data from session
        engine = import_module(settings.SESSION_ENGINE)
        session = engine.SessionStore(session_key)
        user_id = session.get(SESSION_KEY, None)
        if not user_id:
            raise CameraAccessor.APIException("Need user_id")
        user = User.objects(id=user_id).first()
        if not user:
            raise CameraAccessor.APIException("Bad user_id")
        camera = Camera.objects(id=camera_id).first()
        if not camera:
            raise CameraAccessor.APIException(
                "Can`t found camera by camera_id")

        result = CameraAccessor(status, user, camera, session, extra_time)
    except CameraAccessor.APIException, e:
        params = (-1, 0, 0)
        log_debug('api error\n%s\n%s' % (e, traceback.format_exc()))
Пример #27
0
def cam_view_notify(request, format):
    """ API:
        ?session_key=<Fx24>&camera_id=<Fx24>&status=connect
        ?session_key=<Fx24>&camera_id=<Fx24>&status=next&time=<sec>
        ?session_key=<Fx24>&camera_id=<Fx24>&status=disconnect&time=<sec>

        0 OK

        -1 BAD PARAMS
        -500 INTERNAL ERROR
    """

    from apps.media.documents import File

    request_id = time()
    def log_debug(text):
        info = '\n'.join([
            "session_key=%s" % session_key,
            "user_id=%s" % (user.id if user else None),
            "camera_id=%s" % camera_id,
        ])
        logger.debug('cam_view_notify %s\n%s\n%s' % (request_id, info, text))

    logger.debug('cam_view_notify %s\nrequest %s' % (request_id, repr(request.GET.items())))

    user = None
    session_key = None
    camera_id = None
    try:
        if not request.GET:
            raise CameraAccessor.APIException("Bad params")
        status = request.GET.get('status', None)
        session_key = request.GET.get('session_key', None)
        camera_id = request.GET.get('camera_id', None)
        if not (status and session_key and camera_id):
            raise CameraAccessor.APIException("Bad params")
        extra_time = request.GET.get('time', None)
        if extra_time is not None:
            if not extra_time.isdigit():
                raise CameraAccessor.APIException("Time must by a digit")
            extra_time = int(extra_time)
            if extra_time > settings.TIME_INTERVAL_NOTIFY or extra_time < 0:
                raise CameraAccessor.APIException("Bad time interval")

        # extract data from session
        engine = import_module(settings.SESSION_ENGINE)
        session = engine.SessionStore(session_key)
        user_id = session.get(SESSION_KEY, None)
        if not user_id:
            raise CameraAccessor.APIException("Need user_id")
        user = User.objects(id=user_id).first()
        if not user:
            raise CameraAccessor.APIException("Bad user_id")
        camera = Camera.objects(id=camera_id).first()
        if not camera:
            raise CameraAccessor.APIException("Can`t found camera by camera_id")

        result = CameraAccessor(status, user, camera, session, extra_time)
    except CameraAccessor.APIException, e:
        params = (-1, 0, 0)
        log_debug('api error\n%s\n%s' % (e, traceback.format_exc()))
Пример #28
0
def for_identity(identity, request):
    """
    uid: google,vkontakte,facebook,twitter,loginza,lastffm,
    language: google,flickr, yahoo
    email: google, yandex,facebook,loginza,flickr, yahoo
    name 
        first_name: google,vkontakte,facebook,loginza,
        last_name: google,vkontakte,facebook,loginza,
        full_name: google, yandex,facebook,twitter,loginza,flickr, yahoo, lastffm,
    dob: yandex,vkontakte,facebook,loginza,
    nickname: yandex,vkontakte,twitter,loginza,flickr, yahoo, lastffm,
    photo: vkontakte, facebook,twitter,loginza,flickr, yahoo, lastffm,
    gender: vkontakte,facebook,loginza,flickr, yahoo, lastffm,
    address
        home
            country: vkontakte, lastffm,
    web: twitter
        default: lastffm,
    biography: twitter,
    """
    try:
        user_map = UserMap.objects.get(identity=identity)
    except:
        # if there is authenticated user - map identity to that user
        # if not - create new user and mapping for him
        if request.user.is_authenticated():
            user = request.user
        else:
            loginza_data = json.loads(identity.data)
            loginza_name_dict = dict(first_name='', last_name='', full_name='')
            loginza_home_dict = dict(country='')
            loginza_address_dict = dict(home=loginza_home_dict)

            loginza_email = loginza_data.get('email', '')
            loginza_uid = loginza_data.get('uid', '')
            loginza_language = loginza_data.get('language', '')
            loginza_first_name = loginza_data.get('name', loginza_name_dict)\
                                             .get('first_name','')
            loginza_last_name = loginza_data.get('name', loginza_name_dict)\
                                            .get('last_name','')
            loginza_full_name = loginza_data.get('name', loginza_name_dict)\
                                            .get('full_name','')
            if not loginza_first_name and not loginza_last_name \
            and loginza_full_name:
                loginza_first_name = loginza_full_name
            loginza_dob = loginza_data.get('dob', '')
            loginza_nickname = loginza_data.get('nickname', '')
            loginza_photo = loginza_data.get('photo', '')
            loginza_gender = loginza_data.get('gender', '')
            loginza_country = loginza_data.get('address', loginza_address_dict)\
                                          .get('home', loginza_home_dict)\
                                          .get('country', '')
            loginza_web = loginza_data.get('web', '')
            if isinstance(loginza_web, dict):
                loginza_web = loginza_web.get('default', '')
            loginza_bio = loginza_data.get('biography', '')

            email = loginza_email if '@' in loginza_email else settings.DEFAULT_EMAIL

            if loginza_email:
                username = loginza_email
            elif loginza_nickname:
                username = loginza_nickname
            elif 'uid' in loginza_data:
                username = str(loginza_data['uid'])
            else:
                username = loginza_data['identity']

            # if nickname is not set - try to get it from email
            # e.g. [email protected] -> vgarvardt
            loginza_nickname = loginza_data.get('nickname', None)
            username = loginza_nickname if loginza_nickname is not None else email.split('@')[0]
            if 'uid' in loginza_data:
                username = str(loginza_data['uid'])

            
            try:
                user = User.objects.get(username=username)
            except Exception,e:
                try:    
                    user = User.objects.get(email=email)
                except:
                    user = User(username=username, email=email, 
                                first_name=loginza_first_name, 
                                last_name=loginza_last_name)
                    user.save()
                    profile = user.profile
                    if loginza_dob:
                        profile.birthday = loginza_dob
                    if loginza_gender:
                        profile.sex = loginza_gender
                    if loginza_web:
                        profile.website = loginza_web
                    if loginza_dob or loginza_gender or loginza_web:
                        profile.save()
        user_map = UserMap(identity=identity, user=user)
        signals.created.send(request, user_map=user_map)
Пример #29
0
    def setUp(self):
        self.tearDown()

        self.client = Client()

        self.camera_type_axis = CameraType(
            name='Axis',
            driver='axis.AxisDriver',
            is_controlled=False,
        )
        self.camera_type_axis.save()
        self.camera_type_axis_manage = CameraType(
            name='Axis Manage',
            driver='axis.AxisDriver',
            is_controlled=True,
        )
        self.camera_type_axis_manage.save()

        self.tariff_view_package = Tariff(
            name='View Package 1 min',
            description='View Package Description...',
            cost=1.0,
            duration=2,
            is_controlled=False,
        )
        self.tariff_view_package.save()

        self.tariff_view_time = Tariff(
            name='View Package Time',
            description='View Package Description...',
            cost=1.0,
            is_controlled=False,
        )
        self.tariff_view_time.save()

        self.tariff_manage_package = Tariff(
            name='Manage Package 1 min',
            description='Manage Package Description...',
            cost=2.0,
            duration=2,
            is_controlled=True,
        )
        self.tariff_manage_package.save()

        self.tariff_manage_time = Tariff(
            name='Manage Package Time',
            description='Manage Package Description...',
            cost=2.0,
            is_controlled=True,
        )
        self.tariff_manage_time.save()

        for i in xrange(1, 4):
            user = User.create_user(email='*****@*****.**' % i, password='******')
            user.cash = 1000000.0
            user.save()
            camera = Camera(
                name='Test Billing Camera %i' % i,
                owner=user,
                type=self.camera_type_axis_manage,
                stream_name='boston',
                camera_management_host='localhost.boston.com',
                camera_management_username='******',
                camera_management_password='******',
                is_view_enabled=True,
                is_view_public=True,
                is_view_paid=True,
                is_management_enabled=True,
                is_management_public=True,
                is_management_paid=True,
                is_managed=True,
                management_packet_tariff=self.tariff_manage_package,
                management_time_tariff=self.tariff_manage_time,
                view_packet_tariff=self.tariff_view_package,
                view_time_tariff=self.tariff_view_time,
            )
            camera.save()
Пример #30
0
 def process_request(self, request):
     if request.user.is_authenticated():
         now = datetime.now()
         if now - request.user.last_access > settings.LAST_ACCESS_UPDATE_INTERVAL:
             request.user.last_access = now
             User.objects(id=request.user.id).update_one(set__last_access=now)
Пример #31
0
def statistic(request):
    return direct_to_template(request, 'admin/statistic.html', {
        'users_active_count': User.objects(is_active=True).count(),
        'users_inactive_count': User.objects(is_active=False).count(),
        'users_online_count': User.objects(last_access__gt=User.get_delta_time()).count(),
    })
Пример #32
0
 def user(self):
     return User.objects(id=self.user_id).first()