Пример #1
0
def login(request):
    type = request.form.get('do')
    token = request.form.get('token')
    username = request.form.get('user')
    passwd = request.form.get('pw')
    if not (username and passwd and type and token) or not is_valid_token(
            type, token):
        return serve_text('')
    user = get_user(username)
    if type == 'reg' and user is None:
        user = register(username, passwd)
    if user and user.is_valid_pw(passwd):
        request.login(username)
        todo = request.form.get('reason')
        if not todo:
            response = serve_text('ok')
        else:
            response = exec_todo(request, user, todo)
        #remember user for n hours
        hours = 24 * (30 if request.form.get('rem') == 'on' else 1)
        request.session.save_cookie(response,
                                    expires=cookie_expires(hours),
                                    max_age=cookie_lifespan(hours))
        return response
    return serve_text('')
Пример #2
0
def user_exists(request):
    name = request.args.get('name')
    if not name:
        raise Forbidden
    user = get_user(name)
    if user is not None:
        return serve_text('username taken.')
    else:
        return serve_text('') 
Пример #3
0
def user_exists(request):
    name = request.args.get('name')
    if not name:
        raise Forbidden
    user = get_user(name)
    if user is not None:
        return serve_text('username taken.')
    else:
        return serve_text('')
Пример #4
0
def clearcache(request):
    cache.clear()
    #cache.delete('view_simple_search')
    #cache.delete('view_simple_about')
    #cache.delete('view_simple_links')
    #cache.delete('view_simple_robots')
    return serve_text('cache cleared: ' + datetime.now().isoformat(' '))
Пример #5
0
def autocomplete(request, name):
    query = request.args.get('q')
    if not query:
        raise NotFound
    if name == 'tags':
        res = session.query(Tag).filter(Tag.name.ilike(query+'%')).limit(10)
        suggestions = '\n'.join(r.name for r in res)
    elif name == 'reddits':
        res = session.query(Subreddit).filter(Subreddit.url.ilike(query+'%')).order_by(Subreddit.subscribers.desc()).limit(10)
        suggestions = '\n'.join(r.url for r in res)
    return serve_text(suggestions)
Пример #6
0
def login(request):
    type = request.form.get('do')
    token = request.form.get('token')
    username = request.form.get('user')
    passwd = request.form.get('pw')
    if not (username and passwd and type and token) or not is_valid_token(type, token):
        return serve_text('')
    user = get_user(username)
    if type == 'reg' and user is None:
        user = register(username, passwd)
    if user and user.is_valid_pw(passwd):
        request.login(username)
        todo = request.form.get('reason')
        if not todo:
            response = serve_text('ok')
        else:
            response = exec_todo(request, user, todo)   
        #remember user for n hours
        hours = 24 * (30 if request.form.get('rem') == 'on' else 1)
        request.session.save_cookie(response, expires=cookie_expires(hours), max_age=cookie_lifespan(hours))
        return response
    return serve_text('')
Пример #7
0
def autocomplete(request, name):
    query = request.args.get('q')
    if not query:
        raise NotFound
    if name == 'tags':
        res = session.query(Tag).filter(Tag.name.ilike(query + '%')).limit(10)
        suggestions = '\n'.join(r.name for r in res)
    elif name == 'reddits':
        res = session.query(Subreddit).filter(
            Subreddit.url.ilike(query + '%')).order_by(
                Subreddit.subscribers.desc()).limit(10)
        suggestions = '\n'.join(r.url for r in res)
    return serve_text(suggestions)
Пример #8
0
def code(request):
    return serve_text('bla')
Пример #9
0
def robots(request):
    txt = 'User-agent: * \nDisallow: /login \nDisallow: /api/ \nAllow: /'
    return serve_text(txt)
Пример #10
0
def code(request):
    return serve_text('bla')
Пример #11
0
def robots(request):
    txt = 'User-agent: * \nDisallow: /login \nDisallow: /api/ \nAllow: /'
    return serve_text(txt)
Пример #12
0
def restartmonitors(request):
    out = commands.getoutput('supervisorctl -c /home/www/vhost/metareddit/supervisord.conf restart all')
    return serve_text('monitors restarted: ' + out)
Пример #13
0
def cleandb(request):
    rm = Monitor()
    rm.cleandb()
    return serve_text('db cleaned: ' + datetime.now().isoformat(' '))