mirror of
https://github.com/retspen/webvirtcloud
synced 2024-12-25 23:55:24 +00:00
Added profile page
This commit is contained in:
parent
a2b1fc499e
commit
9497eb7c89
4 changed files with 83 additions and 13 deletions
|
@ -16,6 +16,30 @@ def profile(request):
|
||||||
if not request.user.is_authenticated():
|
if not request.user.is_authenticated():
|
||||||
return HttpResponseRedirect(reverse('index'))
|
return HttpResponseRedirect(reverse('index'))
|
||||||
|
|
||||||
|
error_messages = []
|
||||||
|
user = User.objects.get(id=request.user.id)
|
||||||
|
|
||||||
|
if request.method == 'POST':
|
||||||
|
if 'username' in request.POST:
|
||||||
|
username = request.POST.get('username', '')
|
||||||
|
email = request.POST.get('email', '')
|
||||||
|
user.first_name = username
|
||||||
|
user.email = email
|
||||||
|
user.save()
|
||||||
|
return HttpResponseRedirect(request.get_full_path())
|
||||||
|
if 'oldpasswd' in request.POST:
|
||||||
|
oldpasswd = request.POST.get('oldpasswd', '')
|
||||||
|
password1 = request.POST.get('passwd1', '')
|
||||||
|
password2 = request.POST.get('passwd2', '')
|
||||||
|
if password1 and password2 and password1 != password2:
|
||||||
|
error_messages.append("Passwords don't match")
|
||||||
|
if not user.check_password(oldpasswd):
|
||||||
|
error_messages.append("Old password is wrong!")
|
||||||
|
if not error_messages:
|
||||||
|
user.set_password(password1)
|
||||||
|
user.save()
|
||||||
|
return HttpResponseRedirect(request.get_full_path())
|
||||||
|
|
||||||
return render(request, 'profile.html', locals())
|
return render(request, 'profile.html', locals())
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -411,7 +411,7 @@ def instance(request, compute_id, vname):
|
||||||
return render(request, 'instance.html', locals())
|
return render(request, 'instance.html', locals())
|
||||||
|
|
||||||
|
|
||||||
def inst_status(request, compute_id, vname):
|
def inst_status(request, host_id, vname):
|
||||||
"""
|
"""
|
||||||
:param request:
|
:param request:
|
||||||
:return:
|
:return:
|
||||||
|
@ -420,7 +420,9 @@ def inst_status(request, compute_id, vname):
|
||||||
if not request.user.is_authenticated():
|
if not request.user.is_authenticated():
|
||||||
return HttpResponseRedirect(reverse('login'))
|
return HttpResponseRedirect(reverse('login'))
|
||||||
|
|
||||||
compute = Compute.objects.get(id=compute_id)
|
compute = Compute.objects.get(id=host_id)
|
||||||
|
response = HttpResponse()
|
||||||
|
response['Content-Type'] = "text/javascript"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
conn = wvmInstance(compute.hostname,
|
conn = wvmInstance(compute.hostname,
|
||||||
|
@ -428,14 +430,10 @@ def inst_status(request, compute_id, vname):
|
||||||
compute.password,
|
compute.password,
|
||||||
compute.type,
|
compute.type,
|
||||||
vname)
|
vname)
|
||||||
status = conn.get_status()
|
data = json.dumps({'status': conn.get_status()})
|
||||||
conn.close()
|
conn.close()
|
||||||
except libvirtError:
|
except libvirtError:
|
||||||
status = None
|
data = json.dumps({'error': 'Error 500'})
|
||||||
|
|
||||||
data = json.dumps({'status': status})
|
|
||||||
response = HttpResponse()
|
|
||||||
response['Content-Type'] = "text/javascript"
|
|
||||||
response.write(data)
|
response.write(data)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% block title %}{% trans "Logs" %}{% endblock %}
|
{% block title %}{% trans "Profile" %}{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<!-- Page Heading -->
|
<!-- Page Heading -->
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
@ -14,7 +14,58 @@
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-12">
|
<div class="col-lg-12">
|
||||||
|
<h3 class="page-header">{% trans "Edit Profile" %}</h3>
|
||||||
|
<form class="form-horizontal" method="post" action="" role="form">{% csrf_token %}
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-2 control-label">{% trans "Login" %}</label>
|
||||||
|
<div class="col-sm-4">
|
||||||
|
<input type="text" class="form-control" value="{{ request.user.username }}" disabled>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group bridge_name_form_group_dhcp">
|
||||||
|
<label class="col-sm-2 control-label">{% trans "Username" %}</label>
|
||||||
|
<div class="col-sm-4">
|
||||||
|
<input type="text" class="form-control" name="username" value="{{ request.user.first_name }}" pattern="[0-9a-zA-Z]+">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group bridge_name_form_group_dhcp">
|
||||||
|
<label class="col-sm-2 control-label">{% trans "Email" %}</label>
|
||||||
|
<div class="col-sm-4">
|
||||||
|
<input type="email" class="form-control" name="email" value="{{ request.user.email }}">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="col-sm-offset-2 col-sm-10">
|
||||||
|
<button type="submit" class="btn btn-primary">{% trans "Change" %}</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<h3 class="page-header">{% trans "Edit Password" %}</h3>
|
||||||
|
<form class="form-horizontal" method="post" action="" role="form">{% csrf_token %}
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-2 control-label">{% trans "Old password" %}</label>
|
||||||
|
<div class="col-sm-4">
|
||||||
|
<input type="password" class="form-control" name="oldpasswd" value="">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group bridge_name_form_group_dhcp">
|
||||||
|
<label class="col-sm-2 control-label">{% trans "New password" %}</label>
|
||||||
|
<div class="col-sm-4">
|
||||||
|
<input type="password" class="form-control" name="passwd1" value="">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group bridge_name_form_group_dhcp">
|
||||||
|
<label class="col-sm-2 control-label">{% trans "Retry password" %}</label>
|
||||||
|
<div class="col-sm-4">
|
||||||
|
<input type="password" class="form-control" name="passwd2" value="">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="col-sm-offset-2 col-sm-10">
|
||||||
|
<button type="submit" class="btn btn-primary">{% trans "Change" %}</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
|
@ -347,9 +347,7 @@ class wvmInstance(wvmConnect):
|
||||||
else:
|
else:
|
||||||
rd_diff_usage = 0
|
rd_diff_usage = 0
|
||||||
wr_diff_usage = 0
|
wr_diff_usage = 0
|
||||||
|
|
||||||
dev_usage.append({'dev': dev[1], 'rd': rd_diff_usage, 'wr': wr_diff_usage})
|
dev_usage.append({'dev': dev[1], 'rd': rd_diff_usage, 'wr': wr_diff_usage})
|
||||||
|
|
||||||
return dev_usage
|
return dev_usage
|
||||||
|
|
||||||
def net_usage(self):
|
def net_usage(self):
|
||||||
|
@ -371,7 +369,6 @@ class wvmInstance(wvmConnect):
|
||||||
else:
|
else:
|
||||||
for i, dev in enumerate(self.get_net_device()):
|
for i, dev in enumerate(self.get_net_device()):
|
||||||
dev_usage.append({'dev': i, 'rx': 0, 'tx': 0})
|
dev_usage.append({'dev': i, 'rx': 0, 'tx': 0})
|
||||||
|
|
||||||
return dev_usage
|
return dev_usage
|
||||||
|
|
||||||
def get_telnet_port(self):
|
def get_telnet_port(self):
|
||||||
|
|
Loading…
Reference in a new issue