new app tool
This commit is contained in:
parent
50865a6619
commit
818c874352
33
buckler.py
33
buckler.py
|
@ -28,6 +28,23 @@ routes = web.RouteTableDef()
|
|||
@auth.auth_required
|
||||
async def index(request):
|
||||
"""The index page."""
|
||||
if request.method == 'POST':
|
||||
data = await request.post()
|
||||
form = data.get('form_name')
|
||||
|
||||
forms_ = {
|
||||
'invite_user': forms.invite_user,
|
||||
'change_password': forms.change_password,
|
||||
'delete_key': forms.delete_key,
|
||||
'delele_session': forms.delete_session,
|
||||
'new_app': forms.new_app,
|
||||
}
|
||||
|
||||
if not forms_.get(form):
|
||||
errors = {'main': "Unknown form id: {form}"}
|
||||
else:
|
||||
errors = await forms_[form](request)
|
||||
|
||||
async with request.app['pool'].acquire() as conn:
|
||||
avail_sites = await conn.fetch(
|
||||
"SELECT app_info.name, app_info.url "
|
||||
|
@ -58,22 +75,6 @@ async def index(request):
|
|||
users[user_perm['username']][apps[index]['name']] = True
|
||||
users_json = json.dumps(users)
|
||||
|
||||
if request.method == 'POST':
|
||||
data = await request.post()
|
||||
form = data.get('form_name')
|
||||
|
||||
forms_ = {
|
||||
'invite_user': forms.invite_user,
|
||||
'change_password': forms.change_password,
|
||||
'delete_key': forms.delete_key,
|
||||
'delele_session': forms.delete_session,
|
||||
}
|
||||
|
||||
if not forms_[form]:
|
||||
errors = defaultdict['main'].append("Unknown form id: {form}")
|
||||
else:
|
||||
errors = await forms_[form](request)
|
||||
|
||||
return render_template("index.html", request, locals())
|
||||
|
||||
|
||||
|
|
17
forms.py
17
forms.py
|
@ -2,6 +2,8 @@
|
|||
"""
|
||||
Co-routines for handling various forms in Buckler.
|
||||
"""
|
||||
from passlib.hash import argon2
|
||||
|
||||
import tools
|
||||
|
||||
|
||||
|
@ -86,3 +88,18 @@ async def delete_session(request):
|
|||
"WHERE id = $1 AND user_id = $2",
|
||||
session_id, request['session']['id'])
|
||||
return {}
|
||||
|
||||
|
||||
async def new_app(request):
|
||||
data = await request.post()
|
||||
app_name = data.get('app_name')
|
||||
app_url = data.get('app_url')
|
||||
app_key = data.get('app_key')
|
||||
key_hash = argon2.hash(app_key)
|
||||
|
||||
async with request.app['pool'].acquire() as conn:
|
||||
await conn.execute(
|
||||
"INSERT INTO app_info (name, url, key_hash) "
|
||||
"VALUES ($1, $2, $3)",
|
||||
app_name, app_url, key_hash)
|
||||
return {}
|
||||
|
|
|
@ -74,6 +74,31 @@
|
|||
</form>
|
||||
</article>
|
||||
</section>
|
||||
<br>
|
||||
<section class="sub_section">
|
||||
<h3>Add New App</h3>
|
||||
<article style="display: none;">
|
||||
<hr>
|
||||
<form method="post" enctype="application/x-www-form-urlencoded">
|
||||
<input name="form_name" type="hidden" value="new_app">
|
||||
<table id="new_app" class="no_borders">
|
||||
<tr>
|
||||
<td><label for="new_app_name">App Name</label></td>
|
||||
<td><input id="new_app_name" name="app_name" type="text"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="new_app_url">App URL</label></td>
|
||||
<td><input id="new_app_url" name="app_url" type="text"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="new_app_key">App Key</label></td>
|
||||
<td><input id="new_app_key" name="app_key" type="password"></td>
|
||||
</tr>
|
||||
</table>
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
</article>
|
||||
</section>
|
||||
</article>
|
||||
</section>
|
||||
{% endif %}
|
||||
|
|
Loading…
Reference in New Issue
Block a user