Example DBBasic apps (an API, a blog and a microblog) and a template for new DBBasic modules.

0 downloads

Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-examples.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-examples.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-examples.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 Add official module template for creating DBBasic packages 17cf88a 1 year, 1 month ago History
login.py · 803 bytes · 24 lines
1from dbbasic_web.responses import html, redirect
2from dbbasic_web.templating import render
3from dbbasic_sessions import create_session
4from dbbasic_accounts import Accounts
5
6accounts = Accounts('.', domain='localhost')
7
8def handle(request):
9 if request.method == 'POST':
10 email = request.param('email', '')
11 password = request.param('password', '')
12
13 user = accounts.login(email, password)
14 if not user:
15 return html(render('login.html', error='Invalid credentials'))
16
17 token = create_session(str(user.uid))
18
19 # Set session cookie
20 status, headers, body = redirect('/')
21 headers.append(('set-cookie', f'session={token}; HttpOnly; Max-Age=2592000; Path=/'))
22 return status, headers, body
23
24 return html(render('login.html'))