diff --git a/hosting/forms.py b/hosting/forms.py index b48a52ef..e5a14d48 100644 --- a/hosting/forms.py +++ b/hosting/forms.py @@ -1,3 +1,5 @@ +import datetime + from django import forms from membership.models import CustomUser from django.contrib.auth import authenticate @@ -7,6 +9,10 @@ from django.utils.translation import ugettext_lazy as _ from .models import UserHostingKey +def generate_ssh_key_name(): + return 'dcl-generated-key-' + datetime.datetime.now().strftime('%m%d%y%H%M') + + class HostingUserLoginForm(forms.Form): email = forms.CharField(widget=forms.EmailInput()) @@ -64,7 +70,7 @@ class UserHostingKeyForm(forms.ModelForm): ) user = forms.models.ModelChoiceField(queryset=CustomUser.objects.all(), required=False, widget=forms.HiddenInput()) - name = forms.CharField(required=True, widget=forms.TextInput( + name = forms.CharField(required=False, widget=forms.TextInput( attrs={'class': 'form_key_name', 'placeholder': 'Give a name to your key',})) def __init__(self, *args, **kwargs): @@ -80,7 +86,8 @@ class UserHostingKeyForm(forms.ModelForm): def clean(self): cleaned_data = self.cleaned_data - + if not self.cleaned_data.get('name', ''): + self.cleaned_data['name'] = generate_ssh_key_name() if not cleaned_data.get('public_key'): private_key, public_key = UserHostingKey.generate_keys() cleaned_data.update({ diff --git a/hosting/static/hosting/css/user_keys.css b/hosting/static/hosting/css/user_keys.css index 416b9e44..4f8a27b7 100644 --- a/hosting/static/hosting/css/user_keys.css +++ b/hosting/static/hosting/css/user_keys.css @@ -1,3 +1,6 @@ +h2,h3,h4,h5{ + font-family: 'Lato-Light', sans-serif; +} .ssh-keys-table thead tr th, .ssh-keys-table tbody tr td{ color: #717274; @@ -97,29 +100,48 @@ display: flex; flex-direction: row; align-items: center; - justify-content: center; + justify-content: space-between; } -.choice-container div:first-of-type{ - border-right: 1px solid #c9c6c6; -} - .choice-container div{ padding-top: 30px; padding-bottom: 30px; display: flex; align-items: center; flex-direction: column; - width: 50%; + width: 49%; } .choice-container div h3{ margin: auto; width: 95%; text-align: center; + font-family: 'Lato-Light', sans-serif; } .choice-container div h3 img:hover{ cursor: pointer; } -.dashboard-container { +.choice-container div.choice-container-line{ + padding-top: 0; + padding-bottom: 0; + border: 1px solid #c9c6c6; + height: 250px; + width:1px; +} +@media screen and (max-width: 768px){ + .choice-container div.choice-container-line{ + display: none; + } + .choice-container{ + flex-direction: column; + } + .choice-container div{ + width: 100%; + } + .choice-container div h3 { + font-size: 16px; + } +} + +.dashboard-choice-container { max-width: 930px !important; } .choice-button{ @@ -128,14 +150,19 @@ border-radius: 0; color: white; margin-top: 70px; -} -.choice-button a{ - color: white; font-size: 20px; } +@media screen and (max-width: 768px){ + .choice-button{ + margin-top: 20px; + } +} .upload-btn{ background-color: #337ab7; } +.form_key_name{ + width:60%; +} .form_public_key, .form_key_name{ border:none; @@ -233,3 +260,6 @@ .form-ssh h3{ margin-bottom: 40px; } +.custom_form_button{ + border-radius: 0; +} diff --git a/hosting/templates/hosting/choice_ssh_keys.html b/hosting/templates/hosting/choice_ssh_keys.html index 7da48342..3882a988 100644 --- a/hosting/templates/hosting/choice_ssh_keys.html +++ b/hosting/templates/hosting/choice_ssh_keys.html @@ -2,7 +2,7 @@ {% load staticfiles bootstrap3 i18n %} {% block content %}
-
+
@@ -20,17 +20,24 @@

I want to generate a new key pair.

- +
+ {% csrf_token %} + +
+
+

I want to use my existing public key.

- +
+ +
diff --git a/hosting/templates/hosting/user_key.html b/hosting/templates/hosting/user_key.html index b98f4b38..7f8897c5 100644 --- a/hosting/templates/hosting/user_key.html +++ b/hosting/templates/hosting/user_key.html @@ -22,13 +22,13 @@ {% buttons %}

{% trans "Use your created key to access to the machine." %}

-

{% trans "Or you can generate a new key pair."%}

-
diff --git a/hosting/views.py b/hosting/views.py index 184f170f..2d05dbd9 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -24,7 +24,7 @@ from utils.forms import BillingAddressForm, PasswordResetRequestForm, UserBillin from utils.views import PasswordResetViewMixin, PasswordResetConfirmViewMixin, LoginViewMixin from utils.mailer import BaseEmail from .models import HostingOrder, HostingBill, HostingPlan, UserHostingKey -from .forms import HostingUserSignupForm, HostingUserLoginForm, UserHostingKeyForm +from .forms import HostingUserSignupForm, HostingUserLoginForm, UserHostingKeyForm, generate_ssh_key_name from .mixins import ProcessVMSelectionMixin from opennebula_api.models import OpenNebulaManager @@ -376,6 +376,13 @@ class SSHKeyChoiceView(LoginRequiredMixin, View): context = {} return render(request, self.template_name, context) + def post(self, request, *args, **kwargs): + print('post method HERE!!!') + name = generate_ssh_key_name() + private_key, public_key = UserHostingKey.generate_keys() + UserHostingKey.objects.create(user=request.user, public_key=public_key, name=name) + return redirect(reverse_lazy('hosting:ssh_keys'), foo='bar') + class SSHKeyCreateView(LoginRequiredMixin, FormView): form_class = UserHostingKeyForm @@ -430,6 +437,9 @@ class SSHKeyCreateView(LoginRequiredMixin, FormView): def post(self, request, *args, **kwargs): print(self.request.POST.dict()) form = self.get_form() + required = 'add_ssh' in self.request.POST + form.fields['name'].required = required + form.fields['public_key'].required = required if form.is_valid(): return self.form_valid(form) else: