2018-03-22 01:23:31 +00:00
|
|
|
import bottle
|
|
|
|
from bottle import get, post, redirect, request, response, view
|
|
|
|
from db import DBPlugin
|
|
|
|
|
|
|
|
|
|
|
|
@get('/')
|
|
|
|
@view('template/propaganda.tpl')
|
|
|
|
def propaganda():
|
2018-03-22 10:22:28 +00:00
|
|
|
pass
|
2018-03-22 01:23:31 +00:00
|
|
|
|
|
|
|
@post('/register', db='db')
|
|
|
|
@view('template/register.tpl')
|
|
|
|
def register_post(db):
|
|
|
|
email = request.forms.get('email', '')
|
|
|
|
password = request.forms.get('pass', '')
|
|
|
|
password_repeat = request.forms.get('pass-repeat', '')
|
|
|
|
if password != password_repeat:
|
|
|
|
return dict(error='Passwords do not match.')
|
|
|
|
if db.by_email(email):
|
|
|
|
return dict(error='Email address already in use.')
|
|
|
|
# send confirmation mail
|
2018-03-22 10:22:28 +00:00
|
|
|
confirm_link = request.url + "/../confirm/" + db.token(email, password)
|
|
|
|
db.send_confirmation_mail(confirm_link, email)
|
|
|
|
return dict(info='Confirmation mail sent.')
|
2018-03-22 01:23:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
@get('/confirm/<token>', db='db')
|
|
|
|
@view('template/propaganda.tpl')
|
|
|
|
def confirm(db, token):
|
|
|
|
# create db-entry
|
|
|
|
if db.register(token):
|
2018-03-22 10:22:28 +00:00
|
|
|
# :todo show info "Account creation successful."
|
2018-03-22 01:23:31 +00:00
|
|
|
return redirect('/settings')
|
|
|
|
return dict(error='Account creation failed.')
|
|
|
|
|
|
|
|
|
|
|
|
@post('/login', db='db')
|
|
|
|
@view('template/login.tpl')
|
|
|
|
def login_post(db):
|
|
|
|
# check login
|
|
|
|
if db.authenticate(request.forms.get('email', ''),
|
|
|
|
request.forms.get('pass', '')):
|
|
|
|
return redirect('/settings')
|
|
|
|
return dict(error='Authentication failed.')
|
|
|
|
|
|
|
|
|
|
|
|
@get('/settings', user='user')
|
|
|
|
@view('template/settings.tpl')
|
|
|
|
def settings(user):
|
|
|
|
return user.state()
|
|
|
|
|
|
|
|
|
|
|
|
@get('/api/state', user='user')
|
|
|
|
def api_enable(user):
|
|
|
|
return user.state()
|
|
|
|
|
|
|
|
|
|
|
|
@get('/static/<filename:path>')
|
|
|
|
def static(filename):
|
|
|
|
return bottle.static_file(filename, root='static')
|
|
|
|
|
2018-03-22 10:22:28 +00:00
|
|
|
@get('/logout/')
|
|
|
|
def logout():
|
|
|
|
# clear auth cookie
|
|
|
|
response.set_cookie('uid', '', expires=0, path="/")
|
|
|
|
# :todo show info "Logout successful."
|
|
|
|
return redirect('/')
|
|
|
|
|
2018-03-22 01:23:31 +00:00
|
|
|
|
|
|
|
bottle.install(DBPlugin('/'))
|
|
|
|
bottle.run(host='localhost', port=8080)
|