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
register.py · 896 bytes · 25 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 name = request.param('name', '')
13
14 try:
15 user = accounts.register(email, password, name=name)
16 token = create_session(str(user.uid))
17
18 # Set session cookie
19 status, headers, body = redirect('/')
20 headers.append(('set-cookie', f'session={token}; HttpOnly; Max-Age=2592000; Path=/'))
21 return status, headers, body
22 except ValueError as e:
23 return html(render('register.html', error=str(e)))
24
25 return html(render('register.html'))