Merge branch 'develop' into hosting_i18n
This commit is contained in:
commit
31e9377818
14 changed files with 381 additions and 298 deletions
|
|
@ -4,6 +4,7 @@ from django import forms
|
|||
from membership.models import CustomUser
|
||||
from django.contrib.auth import authenticate
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from utils.stripe_utils import StripeUtils
|
||||
|
||||
|
|
@ -57,21 +58,19 @@ class HostingUserSignupForm(forms.ModelForm):
|
|||
|
||||
|
||||
class UserHostingKeyForm(forms.ModelForm):
|
||||
private_key = forms.CharField(widget=forms.PasswordInput(), required=False)
|
||||
public_key = forms.CharField(widget=forms.PasswordInput(), required=False)
|
||||
user = forms.models.ModelChoiceField(queryset=CustomUser.objects.all(), required=False)
|
||||
name = forms.CharField(required=False)
|
||||
private_key = forms.CharField(widget=forms.HiddenInput(), required=False)
|
||||
public_key = forms.CharField(widget=forms.Textarea(), required=False,
|
||||
help_text=_('Paste here your public key'))
|
||||
user = forms.models.ModelChoiceField(queryset=CustomUser.objects.all(),
|
||||
required=False, widget=forms.HiddenInput())
|
||||
name = forms.CharField(required=True)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.request = kwargs.pop("request")
|
||||
super(UserHostingKeyForm, self).__init__(*args, **kwargs)
|
||||
# self.initial['user'].initial = self.request.user.id
|
||||
# print(self.fields)
|
||||
|
||||
def clean_name(self):
|
||||
return "dcl-priv-key-%s" % (
|
||||
''.join(random.choice(string.ascii_lowercase) for i in range(7))
|
||||
)
|
||||
return self.data.get('name')
|
||||
|
||||
def clean_user(self):
|
||||
return self.request.user
|
||||
|
|
@ -90,4 +89,4 @@ class UserHostingKeyForm(forms.ModelForm):
|
|||
|
||||
class Meta:
|
||||
model = UserHostingKey
|
||||
fields = ['user', 'public_key', 'name']
|
||||
fields = ['user', 'name', 'public_key']
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2017-05-30 13:47+0000\n"
|
||||
"POT-Creation-Date: 2017-06-01 21:03+0000\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
|
|
@ -18,6 +18,10 @@ msgstr ""
|
|||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||
|
||||
#: hosting/forms.py:63
|
||||
msgid "Paste here your public key"
|
||||
msgstr "Fügen Sie Ihren public key ein"
|
||||
|
||||
#: hosting/templates/hosting/base_short.html:68
|
||||
#: hosting/templates/hosting/base_short.html:139
|
||||
msgid "My Virtual Machines"
|
||||
|
|
@ -143,7 +147,7 @@ msgid "Customers"
|
|||
msgstr "Kunden"
|
||||
|
||||
#: hosting/templates/hosting/bills.html:16
|
||||
#: hosting/templates/hosting/virtual_machine_key.html:45
|
||||
#: hosting/templates/hosting/virtual_machine_key.html:42
|
||||
msgid "Name"
|
||||
msgstr ""
|
||||
|
||||
|
|
@ -330,7 +334,7 @@ msgstr "Betrag"
|
|||
|
||||
#: hosting/templates/hosting/orders.html:19
|
||||
#: hosting/templates/hosting/virtual_machine_detail.html:30
|
||||
#: hosting/templates/hosting/virtual_machine_key.html:47
|
||||
#: hosting/templates/hosting/virtual_machine_key.html:44
|
||||
#: hosting/templates/hosting/virtual_machines.html:31
|
||||
msgid "Status"
|
||||
msgstr ""
|
||||
|
|
@ -449,7 +453,7 @@ msgstr "Beenden"
|
|||
msgid "Access Key"
|
||||
msgstr "Zugriffsschlüssel"
|
||||
|
||||
#: hosting/templates/hosting/virtual_machine_key.html:22
|
||||
#: hosting/templates/hosting/virtual_machine_key.html:25
|
||||
msgid "Upload your own key. "
|
||||
msgstr "Laden Sie ihren Schlüssel hoch"
|
||||
|
||||
|
|
@ -461,7 +465,7 @@ msgstr "Schlüssel hochladen"
|
|||
msgid "Or generate a new key pair."
|
||||
msgstr "Oder erstellen Sie ein neues Schlüsselpaar"
|
||||
|
||||
#: hosting/templates/hosting/virtual_machine_key.html:37
|
||||
#: hosting/templates/hosting/virtual_machine_key.html:31
|
||||
msgid "Generate Key Pair"
|
||||
msgstr "Schlüsselpaar generieren"
|
||||
|
||||
|
|
@ -472,30 +476,30 @@ msgstr ""
|
|||
"Verwenden Sie Ihren privaten SSH Schlüssel um sich mit Ihren Maschinen zu "
|
||||
"verbinden. Falls Sie ihn verloren haben kontaktieren Sie uns."
|
||||
|
||||
#: hosting/templates/hosting/virtual_machine_key.html:46
|
||||
#: hosting/templates/hosting/virtual_machine_key.html:43
|
||||
msgid "Created at"
|
||||
msgstr "Erstellt am"
|
||||
|
||||
#: hosting/templates/hosting/virtual_machine_key.html:68
|
||||
#: hosting/templates/hosting/virtual_machine_key.html:81
|
||||
#: hosting/templates/hosting/virtual_machine_key.html:66
|
||||
#: hosting/templates/hosting/virtual_machine_key.html:79
|
||||
msgid "Warning!"
|
||||
msgstr "Achtung!"
|
||||
|
||||
#: hosting/templates/hosting/virtual_machine_key.html:68
|
||||
#: hosting/templates/hosting/virtual_machine_key.html:66
|
||||
msgid "You can download your SSH private key once. Don't lost your key"
|
||||
msgstr ""
|
||||
"Sie können ihren privaten SSH Schlüssel nur einmal herunterladen. Bewaren "
|
||||
"Sie ihn sicher auf."
|
||||
|
||||
#: hosting/templates/hosting/virtual_machine_key.html:76
|
||||
#: hosting/templates/hosting/virtual_machine_key.html:74
|
||||
msgid "Copy to Clipboard"
|
||||
msgstr "Kopieren"
|
||||
|
||||
#: hosting/templates/hosting/virtual_machine_key.html:77
|
||||
#: hosting/templates/hosting/virtual_machine_key.html:75
|
||||
msgid "Download"
|
||||
msgstr ""
|
||||
|
||||
#: hosting/templates/hosting/virtual_machine_key.html:81
|
||||
#: hosting/templates/hosting/virtual_machine_key.html:79
|
||||
msgid ""
|
||||
"Your SSH private key was already generated and downloaded, if you lost it, "
|
||||
"contact us. "
|
||||
|
|
@ -503,7 +507,7 @@ msgstr ""
|
|||
"Ihr privater SSH Schlüssel wurde bereits generiert und heruntergeladen, "
|
||||
"falls Sie ihn verloren haben kontaktieren Sie uns."
|
||||
|
||||
#: hosting/templates/hosting/virtual_machine_key.html:84
|
||||
#: hosting/templates/hosting/virtual_machine_key.html:82
|
||||
msgid "Generate my key"
|
||||
msgstr "Generiere meinen Schlüssel"
|
||||
|
||||
|
|
|
|||
|
|
@ -73,11 +73,7 @@
|
|||
<i class="fa fa-credit-card"></i> {% trans "My Orders"%}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{% url 'hosting:key_pair' %}">
|
||||
<i class="fa fa-key" aria-hidden="true"></i> {% trans "Keys"%}
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="{% url 'hosting:notifications' %}">
|
||||
<i class="fa fa-bell"></i> {% trans "Notifications "%}
|
||||
|
|
@ -88,6 +84,11 @@
|
|||
<i class="glyphicon glyphicon-user"></i> {{request.user.name}} <span class="caret"></span></a>
|
||||
<ul id="g-account-menu" class="dropdown-menu" role="menu">
|
||||
<li><a href="{% url 'hosting:logout' %}"><i class="glyphicon glyphicon-lock"></i>{% trans "Logout"%} </a></li>
|
||||
<li>
|
||||
<a href="{% url 'hosting:key_pair' %}">
|
||||
<i class="fa fa-key"></i> {% trans "Keys"%}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<!--
|
||||
|
|
@ -128,7 +129,7 @@
|
|||
<footer class="navbar-fixed-bottom">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div class="col-lg-12 hidden-xs">
|
||||
<ul class="list-inline">
|
||||
<li>
|
||||
<a href="#">{% trans "Home"%}</a>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<div class="row">
|
||||
<div class="col-md-9 col-md-offset-2">
|
||||
<div class="col-sm-12">
|
||||
<form method="POST" action="" >
|
||||
<form method="POST" action="" novalidate>
|
||||
{% csrf_token %}
|
||||
<h3><i class="fa fa-key" aria-hidden="true"></i>{% trans "Access Key"%} </h3>
|
||||
{% if messages %}
|
||||
|
|
@ -15,26 +15,24 @@
|
|||
<span>{{ message }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
<hr/>
|
||||
{% if not user_key %}
|
||||
<h3>
|
||||
{% endif %}
|
||||
{% for field in form %}
|
||||
|
||||
{% bootstrap_field field %}
|
||||
{% endfor %}
|
||||
{% buttons %}
|
||||
<button type="submit" class="btn btn-success">
|
||||
{% trans "Upload your own key. "%}
|
||||
</h3>
|
||||
<div class="form-group">
|
||||
<label for="comment">Paste here your public key</label>
|
||||
<textarea class="form-control" rows="6" name="public_key"></textarea>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<button class="btn btn-success">{% trans "Upload Key"%} </a>
|
||||
</div>
|
||||
|
||||
<h3>
|
||||
{% trans "Or generate a new key pair."%}
|
||||
|
||||
</h3>
|
||||
<div class="form-group">
|
||||
</button>
|
||||
<br />
|
||||
<br />
|
||||
{% trans "Or generate a new key pair."%} <br />
|
||||
<br />
|
||||
<button class="btn btn-success">{% trans "Generate Key Pair"%} </a>
|
||||
</button>
|
||||
|
||||
{% endbuttons %}
|
||||
<div class="form-group">
|
||||
</div>
|
||||
{% else %}
|
||||
<h5> {% trans "Use your created key to access to the machine. If you lost it, contact us." %} </h5>
|
||||
|
|
@ -49,6 +47,7 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for user_key in keys %}
|
||||
<tr>
|
||||
<td scope="row">{{user_key.name}}</td>
|
||||
<td>{{user_key.created_at}}</td>
|
||||
|
|
@ -57,9 +56,9 @@
|
|||
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
</form>
|
||||
|
||||
{% if private_key %}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
|
||||
test_user_can_add_key()
|
||||
|
|
|
|||
|
|
@ -301,16 +301,12 @@ class GenerateVMSSHKeysView(LoginRequiredMixin, FormView):
|
|||
self
|
||||
).get_context_data(**kwargs)
|
||||
|
||||
try:
|
||||
user_key = UserHostingKey.objects.get(
|
||||
user=self.request.user
|
||||
)
|
||||
|
||||
except UserHostingKey.DoesNotExist:
|
||||
user_key = None
|
||||
user_keys = UserHostingKey.objects.filter(
|
||||
user=self.request.user
|
||||
)
|
||||
|
||||
context.update({
|
||||
'user_key': user_key
|
||||
'keys': user_keys
|
||||
})
|
||||
|
||||
return context
|
||||
|
|
@ -351,24 +347,14 @@ class GenerateVMSSHKeysView(LoginRequiredMixin, FormView):
|
|||
opennebula_user = user_pool.get_by_name(owner.email)
|
||||
|
||||
# Get user ssh key
|
||||
user_key = UserHostingKey.objects.get(user=owner)
|
||||
public_key = form.cleaned_data.get('public_key')
|
||||
# Add ssh key to user
|
||||
manager.oneadmin_client.call('user.update', opennebula_user.id,
|
||||
'<CONTEXT><SSH_PUBLIC_KEY>{ssh_key}</SSH_PUBLIC_KEY></CONTEXT>'.format(ssh_key=user_key.public_key))
|
||||
'<CONTEXT><SSH_PUBLIC_KEY>{key}</SSH_PUBLIC_KEY></CONTEXT>'.format(key=public_key))
|
||||
|
||||
return render(self.request, self.template_name, context)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
|
||||
try:
|
||||
UserHostingKey.objects.get(
|
||||
user=self.request.user
|
||||
)
|
||||
return HttpResponseRedirect(reverse('hosting:key_pair'))
|
||||
|
||||
except UserHostingKey.DoesNotExist:
|
||||
pass
|
||||
|
||||
form = self.get_form()
|
||||
if form.is_valid():
|
||||
return self.form_valid(form)
|
||||
|
|
@ -421,11 +407,7 @@ class PaymentVMView(LoginRequiredMixin, FormView):
|
|||
return context
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
try:
|
||||
UserHostingKey.objects.get(
|
||||
user=self.request.user
|
||||
)
|
||||
except UserHostingKey.DoesNotExist:
|
||||
if not UserHostingKey.objects.filter( user=self.request.user).exists():
|
||||
messages.success(
|
||||
request,
|
||||
'In order to create a VM, you create/upload your SSH KEY first.'
|
||||
|
|
@ -487,14 +469,16 @@ class PaymentVMView(LoginRequiredMixin, FormView):
|
|||
manager = OpenNebulaManager(email=owner.email,
|
||||
password=owner.password)
|
||||
# Get user ssh key
|
||||
try:
|
||||
user_key = UserHostingKey.objects.get(
|
||||
user=self.request.user
|
||||
)
|
||||
|
||||
except UserHostingKey.DoesNotExist:
|
||||
pass
|
||||
|
||||
if not UserHostingKey.objects.filter( user=self.request.user).exists():
|
||||
context.update({
|
||||
'sshError': 'error',
|
||||
'form': form
|
||||
})
|
||||
return render(request, self.template_name, context)
|
||||
# For now just get first one
|
||||
user_key = UserHostingKey.objects.filter(
|
||||
user=self.request.user).first()
|
||||
|
||||
# Create a vm using logged user
|
||||
vm_id = manager.create_vm(
|
||||
template_id=vm_template_id,
|
||||
|
|
@ -639,11 +623,7 @@ class CreateVirtualMachinesView(LoginRequiredMixin, View):
|
|||
|
||||
def get(self, request, *args, **kwargs):
|
||||
|
||||
try:
|
||||
UserHostingKey.objects.get(
|
||||
user=self.request.user
|
||||
)
|
||||
except UserHostingKey.DoesNotExist:
|
||||
if not UserHostingKey.objects.filter( user=self.request.user).exists():
|
||||
messages.success(
|
||||
request,
|
||||
'In order to create a VM, you need to create/upload your SSH KEY first.'
|
||||
|
|
@ -667,7 +647,7 @@ class CreateVirtualMachinesView(LoginRequiredMixin, View):
|
|||
)
|
||||
context = {
|
||||
'error': 'connection'
|
||||
}
|
||||
}
|
||||
|
||||
return render(request, self.template_name, context)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue