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