Commit 1e687ed1 authored by BERJON Matthieu's avatar BERJON Matthieu
Browse files

Update of the SSH add view



I updated the SSH view, created the new route, changed the class naming
convention and update the template accordingly.
Signed-off-by: BERJON Matthieu's avatarMatthieu Berjon <matthieu.berjon@inria.fr>
parent f91b45c9
......@@ -31,8 +31,8 @@ urlpatterns = [
url(r'^profile/$', views.UserUpdate.as_view(), name='user_detail'),
url(r'^profile/token/update$', views.UserToken.as_view(), name='user_token'),
url(r'^profile/ssh/add/$', views.UserSSHAdd.as_view(), name='user_ssh_add'),
url(r'^settings/security/ssh/add/$', views.UserSecuritySSHAddView.as_view(), name='security_ssh_add_settings'),
url(r'^settings/security/ssh/delete/$', views.UserSecuritySSHDeleteView.as_view(), name='security_ssh_delete_settings'),
url(r'^settings/runners/$', views.UserRunnerListView.as_view(), name='user_runner_list'),
url(r'^settings/runners/add/$', views.UserRunnerCreateView.as_view(), name='user_runner_create'),
......
......@@ -725,16 +725,6 @@ class UserRunnerDeleteView(SuccessMessageMixin, LoginRequiredMixin, DeleteView):
template_name = 'user_runner_delete.html'
class UserSecuritySSHAddView(SuccessMessageMixin, LoginRequiredMixin, UpdateView):
form_class = SSHForm
template_name = 'security_ssh_update_form.html'
success_message = 'SSH key added successfully.'
def get_success_url(self):
return reverse('main:security_settings')
def get_object(self):
return AllgoUser.objects.get(user_id=self.request.user.id)
class UserSecuritySSHDeleteView(LoginRequiredMixin, RedirectView):
......@@ -822,6 +812,7 @@ class UserUpdate(SuccessMessageMixin, LoginRequiredMixin, UpdateView):
token = queryset.token
if key:
fingerprint, comment = get_ssh_data(key)
kwargs['sshkey'] = True
kwargs['ssh_comment'] = comment
kwargs['ssh_fingerprint'] = fingerprint
if token:
......@@ -841,3 +832,14 @@ class UserToken(LoginRequiredMixin, RedirectView):
messages.add_message(self.request, messages.SUCCESS, 'Token generated successfully.')
return reverse('main:user_detail')
class UserSSHAdd(SuccessMessageMixin, LoginRequiredMixin, UpdateView):
form_class = SSHForm
template_name = 'user_ssh_form.html'
success_message = 'SSH key added successfully.'
def get_success_url(self):
return reverse('main:user_detail')
def get_object(self):
return AllgoUser.objects.get(user_id=self.request.user.id)
{% extends "base.html" %}
{% load htmlattrs %}
{% block title %}Security: SSH key{% endblock %}
{% block breadcrumb %}
<li class="breadcrumb-item"><a href="{% url 'main:user_detail' %}">Profile</a></li>
<li class="breadcrumb-item active" aria-current="page">Add SSH key</li>
{% endblock %}
{% block content %}
<div class="container">
<div class="allgo-page">
<form method="post">
{% csrf_token %}
<div class="form-group">
{{ form.sshkey.label_tag }}
<small class="form-text text-muted">
Before you can add an SSH key you need to
<a href="https://gitlab.inria.fr/help/ssh/README#generating-a-new-ssh-key-pair">generate one</a>
or use an
<a href="https://gitlab.inria.fr/help/ssh/README#locating-an-existing-ssh-key-pair">existing key.</a>
</small>
{{ form.sshkey | attr:"placeholder:Example ssh-rsa ...." | add_class:"form-control" }}
</div>
<input type="submit" class="btn btn-primary" value="Update" />
</form>
</div>
</div>
{% endblock %}
{% block messages %}
{{ block.super }}
{% include 'partials/_form_messages.html' %}
{% endblock %}
......@@ -41,7 +41,7 @@
<hr>
<h5>SSH key</h5>
{% if security.sshkey %}
{% if sshkey %}
<p>
This a list of SSH keys associated with your account. Remove any keys
that you do not recognize.
......@@ -76,7 +76,7 @@
</div>
</div>
{% else %}
<p>You don't have any SSH key saved, please <a href="{% url 'main:security_ssh_add_settings' %}" title="Add a SSH key">add one</a>.</p>
<p>You don't have any SSH key saved, please <a href="{% url 'main:user_ssh_add' %}" title="Add a SSH key">add one</a>.</p>
{% endif %}
<hr>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment