def requestToken(request):
    '''
        takes {
            username: string,
            email: string
        }

        returns {
            errors: {
                username: '******'
                email: 'Unknown Email'
            }
            username: user
        }
    '''
    data = json.loads(request.POST['data'])
    user = None
    if 'username' in data:
        try:
            user = User.objects.get(username__iexact=data['username'])
        except User.DoesNotExist:
            user = None
    elif 'email' in data:
        try:
            user = User.objects.get(email__iexact=data['email'])
        except User.DoesNotExist:
            user = None
    if user:
        while True:
            code = ox.toAZ(
                random.randint(ox.fromAZ('AAAAAAAAAAAAAAAA'),
                               ox.fromAZ('AAAAAAAAAAAAAAAAA')))
            if models.UserProfile.objects.filter(reset_code=code).count() == 0:
                break
        user_profile = user.get_profile()
        user_profile.reset_code = code
        user_profile.save()

        template = loader.get_template('password_reset_email.txt')
        context = RequestContext(
            request, {
                'code': code,
                'sitename': settings.SITENAME,
                'footer': settings.CONFIG['site']['email']['footer'],
                'url': request.build_absolute_uri('/'),
            })
        message = template.render(context)
        subject = '%s - Reset Password' % settings.SITENAME
        user.email_user(subject, message)
        response = json_response({'username': user.username},
                                 text='password reset email sent')
    else:
        response = json_response({'errors': {}})
        if 'username' in data:
            response['data']['errors']['username'] = '******'
        elif 'email' in data:
            response['data']['errors']['email'] = 'Unknown Email'
        else:
            response = json_response(status=400, text='invalid data')
    return render_to_json_response(response)
Пример #2
0
 def set_public_id(self):
     if self.id:
         public_id = Annotation.objects.filter(item=self.item, id__lt=self.id).count() + 1
         if public_id > 1:
             previous = Annotation.objects.filter(item=self.item,
                 id__lt=self.id).order_by('-id')[0]
             if not previous.public_id:
                 previous.set_public_id()
             public_id = ox.fromAZ(previous.public_id.split('/')[-1]) + 1
         self.public_id = "%s/%s" % (self.item.itemId, ox.toAZ(public_id))
         Annotation.objects.filter(id=self.id).update(public_id=self.public_id)
Пример #3
0
 def json(self, keys=None):
     j = {
         'id': ox.toAZ(self.id),
         'date': self.date,
         'title': self.title,
         'text': self.text,
     }
     if keys:
         for key in j.keys():
             if key not in keys:
                 del j[key]
     return j
def findLogs(request):
    '''
        takes {
            query: {
                conditions: [
                    {
                        key: 'user',
                        value: 'something',
                        operator: '='
                    }
                ]
                operator: ","
            },
            sort: [{key: 'created', operator: '+'}],
            range: [int, int]
            keys: [string]
        }
        returns {
            items: [object]
        }

    '''
    data = json.loads(request.POST['data'])
    response = json_response()

    query = parse_query(data, request.user)
    qs = order_query(query['qs'], query['sort'])
    qs = qs.distinct()
    if 'keys' in data:
        qs = qs.select_related()
        qs = qs[query['range'][0]:query['range'][1]]
        response['data']['items'] = [p.json(data['keys']) for p in qs]
    elif 'position' in query:
        ids = [i.get_id() for i in qs]
        data['conditions'] = data['conditions'] + {
            'value': data['position'],
            'key': query['sort'][0]['key'],
            'operator': '^'
        }
        query = parse_query(data, request.user)
        qs = order_query(query['qs'], query['sort'])
        if qs.count() > 0:
            response['data']['position'] = utils.get_positions(ids, [qs[0].itemId])[0]
    elif 'positions' in data:
        ids = [ox.toAZ(i.id) for i in qs]
        response['data']['positions'] = utils.get_positions(ids, data['positions'])
    else:
        response['data']['items'] = qs.count()
    return render_to_json_response(response)
Пример #5
0
 def json(self, keys=None):
     j = {
         'created': self.created,
         'id': ox.toAZ(self.id),
         'line': self.line,
         'modified': self.modified,
         'text': self.text,
         'url': self.url,
         'user': self.user and self.user.username or '',
     }
     if keys:
         for key in j.keys():
             if key not in keys:
                 del j[key]
     return j
Пример #6
0
 def json(self, keys=None):
     j = {
         'created': self.created,
         'id': ox.toAZ(self.id),
         'line': self.line,
         'modified': self.modified,
         'text': self.text,
         'url': self.url,
         'user': self.user and self.user.username or '',
     }
     if keys:
         for key in j.keys():
             if key not in keys:
                 del j[key]
     return j
def sortClips(request):
    '''
       takes {
           edit: string
           sort: obect
        }
        returns {
        }
    '''
    data = json.loads(request.POST['data'])
    edit = get_edit_or_404_json(data['edit'])
    response = json_response()
    clips = models.Clip.objects.filter(edit=edit)
    clips = _order_clips(clips, data['sort'])
    response['data']['clips'] = [ox.toAZ(c['id']) for c in clips.values('id')]
    return render_to_json_response(response)
Пример #8
0
def user_json(user, keys=None):
    p = user.get_profile()
    j = {
        'disabled': not user.is_active,
        'email': user.email,
        'firstseen': user.date_joined,
        'id': ox.toAZ(user.id),
        'lastseen': user.last_login,
        'level': p.get_level(),
        'newsletter': p.newsletter,
        'notes': p.notes,
        'numberoflists': user.lists.count(),
        'username': user.username,
    }
    if keys:
        for key in j.keys():
            if key not in keys:
                del j[key]
    return j
Пример #9
0
def user_json(user, keys=None):
    p = user.get_profile()
    j = {
        'disabled': not user.is_active,
        'email': user.email,
        'firstseen': user.date_joined,
        'id': ox.toAZ(user.id),
        'lastseen': user.last_login,
        'level': p.get_level(),
        'newsletter': p.newsletter,
        'notes': p.notes,
        'numberoflists': user.lists.count(),
        'username': user.username,
    }
    if keys:
        for key in j.keys():
            if key not in keys:
                del j[key]
    return j
Пример #10
0
 def get_id(self):
     return ox.toAZ(self.id)
Пример #11
0
 def get_id(self):
     return self.user and ox.toAZ(self.user.id) or self.session_key
 def get_id(self):
     return ox.toAZ(self.id)
 def path(self, name=''):
     h = ox.toAZ(self.id)
     h = (7 - len(h)) * '0' + h
     return os.path.join('documents', h[:2], h[2:4], h[4:6], h[6:], name)
Пример #14
0
def requestToken(request):
    '''
        takes {
            username: string,
            email: string
        }

        returns {
            errors: {
                username: '******'
                email: 'Unknown Email'
            }
            username: user
        }
    '''
    data = json.loads(request.POST['data'])
    user = None
    if 'username' in data:
        try:
            user = User.objects.get(username__iexact=data['username'])
        except User.DoesNotExist:
            user = None
    elif 'email' in data:
        try:
            user = User.objects.get(email__iexact=data['email'])
        except User.DoesNotExist:
            user = None
    if user:
        while True:
            code = ox.toAZ(random.randint(ox.fromAZ('AAAAAAAAAAAAAAAA'),
                                          ox.fromAZ('AAAAAAAAAAAAAAAAA')))
            if models.UserProfile.objects.filter(reset_code=code).count() == 0:
                break
        user_profile = user.get_profile()
        user_profile.reset_code = code 
        user_profile.save()

        template = loader.get_template('password_reset_email.txt')
        context = RequestContext(request, {
            'code': code,
            'sitename': settings.SITENAME,
            'footer': settings.CONFIG['site']['email']['footer'],
            'url': request.build_absolute_uri('/'),
        })
        message = template.render(context)
        subject = '%s - Reset Password' % settings.SITENAME
        user.email_user(subject, message)
        response = json_response({
            'username': user.username
        }, text='password reset email sent')
    else:
        response = json_response({
            'errors': {
            }
        })
        if 'username' in data:
            response['data']['errors']['username'] = '******'
        elif 'email' in data:
            response['data']['errors']['email'] = 'Unknown Email'
        else:
            response = json_response(status=400, text='invalid data')
    return render_to_json_response(response)
Пример #15
0
 def get_id(self):
     return self.user and ox.toAZ(self.user.id) or self.session_key