functional framework in place
This commit is contained in:
parent
0e5ce9ac8c
commit
a577e52f1a
4 changed files with 79 additions and 23 deletions
90
mysecrets.py
90
mysecrets.py
|
@ -1,26 +1,70 @@
|
|||
import web
|
||||
from web import form
|
||||
|
||||
db = web.database(dbn='mysql', user='mysecrets', pw='horsebatteries',
|
||||
db='mysecrets')
|
||||
|
||||
|
||||
urls = (
|
||||
'/secret/', 'index',
|
||||
'/secret/api/(.*)', 'api'
|
||||
'/secret/api/(.*)', 'api',
|
||||
'/secret/(.*)', 'index'
|
||||
)
|
||||
|
||||
app = web.application(urls, globals())
|
||||
|
||||
class index:
|
||||
def GET(self):
|
||||
return '''\
|
||||
<html>
|
||||
<head>
|
||||
<title>mySecrets</title>
|
||||
</head>
|
||||
<body>
|
||||
These are mySecrets. There is nothing for you here.
|
||||
</body>
|
||||
</html>'''
|
||||
render = web.template.render('templates/')
|
||||
|
||||
create = form.Form(
|
||||
form.Textbox('base_url', description="domain"),
|
||||
form.Textbox('username'),
|
||||
form.Password('password'),
|
||||
)
|
||||
|
||||
|
||||
class index:
|
||||
def GET(self, method):
|
||||
if method == 'get':
|
||||
if web.input():
|
||||
i = web.input()
|
||||
selected = db.select('passwords', where='`base_url`="'+i.base_url+'"')
|
||||
|
||||
if len(selected) > 0:
|
||||
pairs = '<ul>'
|
||||
for p in selected:
|
||||
pairs += '<li>'+p.username+', '+p.password+'</li>'
|
||||
pairs += '</ul>'
|
||||
|
||||
else:
|
||||
pairs = "<p>Sorry buddy, you're outta luck</p>"
|
||||
|
||||
body = '<h1>'+i.base_url+'</h1>\n'+pairs
|
||||
|
||||
return render.page(i.base_url, body)
|
||||
|
||||
else:
|
||||
return render.page('get','<p>need input.</p>')
|
||||
|
||||
if method == 'new':
|
||||
f = create()
|
||||
|
||||
body = '<h1>Create</h1>\n<form class="form" method="get" \
|
||||
action="/secret/create">\n'+\
|
||||
f.render()+ '\n<input type="submit" name="submit" id="submit"/></form>'
|
||||
|
||||
return render.page('create',body)
|
||||
|
||||
|
||||
if method == 'create':
|
||||
i = web.input()
|
||||
n = db.insert('passwords', username=i.username, password=i.password, \
|
||||
base_url=i.base_url)
|
||||
|
||||
body = '<h1>'+i.base_url+'</h1><p>'+i.username+', '+i.password+'</p>'
|
||||
|
||||
return render.page('Created', body)
|
||||
|
||||
|
||||
else:
|
||||
return render.page('mySecrets', '<p>These are mySecrets. There is nothing for you here.</p>')
|
||||
|
||||
class api:
|
||||
def GET(self, method):
|
||||
|
@ -38,7 +82,7 @@ class api:
|
|||
|
||||
tmp = ''
|
||||
for pair in pairs:
|
||||
tmp += pair.username+','+pair.password+'\n'
|
||||
tmp += pair.username+','+pair.password+'\n'
|
||||
|
||||
return tmp
|
||||
|
||||
|
@ -46,14 +90,14 @@ class api:
|
|||
return 'mySecrets API ' + method
|
||||
|
||||
def POST(self, method):
|
||||
if method == "create":
|
||||
i = web.input()
|
||||
n = db.insert('passwords', username=i.username, password=i.password, \
|
||||
base_url=i.base_url)
|
||||
return 'Created.'
|
||||
else:
|
||||
return 'No method.'
|
||||
i = web.input()
|
||||
n = db.insert('passwords', username=i.username, password=i.password, \
|
||||
base_url=i.base_url)
|
||||
|
||||
body = '<h1>'+i.base_url+'</h1><p>'+i.username+', '+i.password+'</p>'
|
||||
|
||||
return render.page('Created', body)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run()
|
||||
app.run()
|
||||
|
|
1
static/create.js
Normal file
1
static/create.js
Normal file
|
@ -0,0 +1 @@
|
|||
// create.js
|
1
static/get.js
Normal file
1
static/get.js
Normal file
|
@ -0,0 +1 @@
|
|||
// get.js
|
10
templates/page.html
Normal file
10
templates/page.html
Normal file
|
@ -0,0 +1,10 @@
|
|||
$def with (title, body)
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>$title</title>
|
||||
</head>
|
||||
<body>
|
||||
$:body
|
||||
</body>
|
||||
</html>
|
Reference in a new issue