Commit eb6e3c83 by Dányi Bence

webui: delete/add keys

parent 01c082b0
......@@ -95,4 +95,7 @@ urlpatterns = patterns('',
name='group_ajax_remove_member'),
url(r'^ajax/group/delete/$', 'school.views.group_ajax_delete',
name='group_ajax_delete'),
url(r'^key/add/$', 'one.views.key_add', name='key_add'),
url(r'^ajax/key/delete/$', 'one.views.key_ajax_delete',
name='key_ajax_delete'),
)
......@@ -18,7 +18,7 @@
<div class="clear"></div>
</div>
<div class="details">
<form style="padding-bottom: 10px" action="/key/add/">
<form style="padding-bottom: 10px" action="/key/add/" method="POST">
{% csrf_token %}
<textarea style="margin-bottom: 5px" name="key" placeholder="{% trans "Public key in OpenSSH format" %}"></textarea><br />
<input type="submit" style="margin-left: 10px;" value="{% trans "Save" %}" />
......
......@@ -14,7 +14,7 @@
{{key}}
</div>
<div class="actions">
<a href="#" class="remove" data-id="{{key.id}}">
<a href="#" class="remove delete-key-button" data-id="{{key.id}}">
<img src="/static/icons/minus-circle.png" alt="{% trans 'Remove' %}" />
</a>
</div>
......
......@@ -431,4 +431,28 @@ def vm_restart(request, iid, *args, **kwargs):
messages.error(request, _('Failed to restart virtual machine.'))
return redirect('/')
@login_required
@require_POST
def key_add(request):
try:
key=SshKey()
#TODO: validate key
key.key=request.POST['key']
key.user=request.user
key.save()
except:
messages.error(request, _('Failed to add public key'))
return redirect('/')
@login_required
@require_POST
def key_ajax_delete(request):
try:
#TODO: permission check
key=get_object_or_404(SshKey, id=request.POST['id'])
key.delete()
except:
messages.error(request, _('Failed to delete public key'))
return 'OK'
# vim: et sw=4 ai fenc=utf8 smarttab :
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment