Beispiel #1
0
def auth_send_password_reset_email():
    """Send out password reset email (JSON)"""
    add_headers(bottle.response)
    if bottle.request.method in ['HEAD','OPTIONS']:
        return []
    backend.send_password_reset_email(
        username=param_get('username'),
        email_addr=param_get('email_address'))
    return dict()
Beispiel #2
0
def auth_require():
    """Only authenticated users can see this"""
    add_headers(bottle.response)
    if bottle.request.method in ['HEAD','OPTIONS']:
        return []
    try:
        if backend.require():
            return dict()
    except:
        pass
    return dict(success=False, errmsg='Access Denied')
Beispiel #3
0
def auth_register():
    """Send out registration email (JSON)"""
    add_headers(bottle.response)
    if bottle.request.method in ['HEAD','OPTIONS']:
        return []
    try:
        desc=mk_uuid()
        backend.register(param_get('username'), param_get('password'),
                     param_get('email_address'), description=desc)
    except:
        return dict(success=False,errmsg='Registration Failed',
                    language='python',trace=tb.format_exc().split('\n'))
    return dict()
Beispiel #4
0
def auth_login():
    """Authenticate users (JSON)"""
    add_headers(bottle.response)
    if bottle.request.method in ['HEAD','OPTIONS']:
        return []
    username = param_get('username')
    password = param_get('password')
    try:
        if backend.login(username, password):
            print "IDENT VERIFIED"
            return dict(desc=backend.current_user.description)
    except:
        pass
    print "IDENT UNVERIFIED"
    return dict(success=False, errmsg='Access Denied')
Beispiel #5
0
def login():
    add_headers(bottle.response)
    #print "AUTH LOGIN", dict(bottle.request.params)
    #print "AUTH LOGIN", (bottle.request.body)
    d = bottle.request.body.read()
    #print "AUTH LOGIN", repr(d)
    j = json.loads(d)
    print "AUTH LOGIN", repr(j)

    inp = dict( data=j )
    print "AUTH LOGIN INPUT", repr(inp)

    ret = login_user( j['u'], j['p'] )
    print "AUTH LOGIN -RET-", repr(ret)

    return dict(result=ret)
Beispiel #6
0
def stream2():
    add_headers(bottle.response)
    q=Queue()
    myid = str(id(q))
    QM[myid] = q
    RemotePortToQ[remote_port()] = q
    print "QAZ open X b XXX", remote_port(), id(q)
    bottle.response.content_type  = 'text/event-stream'
    bottle.response.cache_control = 'no-cache'
    # Set client-side auto-reconnect timeout, ms.
    yield 'retry: 100\n\ndata: hello '+myid+'\n\n'
    while 1:
        arr = []
        data = q.get()
        if 'id'    in data:  arr.append('id: %s' % data['id'])
        if 'event' in data:  arr.append('event: %s' % data['event'])
        dat = data['data']
        if type(dat)!=list:  arr.append('data: '+json.dumps(dat))
        else:
            for x in dat:    arr.append('data: '+json.dumps(x))
            pass
        arr.append('\n')
        yield '\n'.join(arr)
Beispiel #7
0
def login():
    add_headers(bottle.response)
    return ''
Beispiel #8
0
def error404(error):
    add_headers(bottle.response)
    return 'Nothing here, sorry'
Beispiel #9
0
def auth_logout():
    """Log out (JSON)"""
    add_headers(bottle.response)
    if bottle.request.method in ['HEAD','OPTIONS']:
        return []
    backend.logout()