Ejemplo n.º 1
0
def unauthorized(message='Action NOT allowed', code=401):
    ''' Returns proper value to indicate the user has no access to this ressource

    :arg message: Message to show to the user
    :type message: `unicode` or `str`
    :arg code: HTTP error code, defaults to ``401``
    :type code: int
    '''
    if request.identity:
        return {'error': True, 'message': message, 'code': code}
    else:
        return rdr('/login?from='+request.path)
Ejemplo n.º 2
0
def log_in():
    request.identity = Authenticator()
    if request.forms.get('login_name', ''):
        session = request.identity.session
        session['logged_in'] = sha1(request.forms.get('login_password', '')).hexdigest()
        session['login'] = request.forms.get('login_name', '')
        log.debug('LOGGING-IN! session=%r', session)
        session.save()
        return rdr(request.params.get('from', '/'))
    else:
        html='''
        <h1>Connect to drink</h1>
        <form name="login_form" id="login_form" class="autovalidate" action="/login" method="post">
            <div class="label"><label for="ilogin">Authenticate as:</label></div>
            <div><input type="text" class="required" name="login_name" id="ilogin" /></div>
            <div class="label"><label for="ipasswd">Password:</label></div>
            <div><input type="password" class="required" name="login_password" id="ipassword" /></div>
            <div><input type="hidden" name="from" value="%s" /></div>
            <div><input class="submit" type="submit" value="Log in!"/></div>
        </form>

        '''%request.params.get('from', '/')
        return default_view(db.db['pages'], page='main.html', html=html, classes={}, no_auth=True)
Ejemplo n.º 3
0
def log_out():
    log.debug('LOGGING-OUT!')
    session = bottle.request.environ.get('beaker.session')
    session['logged_in'] = ''
    session.save()
    return rdr('/')
Ejemplo n.º 4
0
def main_index():
    rdr('/pages/')
Ejemplo n.º 5
0
def glob_index(objpath="/"):
    request.identity = Authenticator()
    try:
        o = get_object(db.db, objpath)
    except AttributeError, e:
        return abort(404, "%s not found"%objpath)

    if callable(o):
        o = o()

    t = type(o)

    if t == dict:
        if not request.is_ajax:
            if 'redirect' in o:
                return rdr(omni(o['redirect']).encode('utf-8'))
            if 'error' in o:
                return abort(o['code'], o['message'])
        response.content_type = "application/json"
        return dumps(o)
    elif hasattr(o, 'drink_name'): # isinstance(o, 'Model') but more implicit
        try:
            return getattr(o, o.default_action)()
        except AttributeError:
            o = o[o.default_action]
            return getattr(o, o.default_action)()
    elif t in (list, tuple):
        response.content_type = "application/json"
        return dumps(o)
    return o