jquery profile a.o. stuff

This commit is contained in:
deflax 2017-05-24 17:37:52 +03:00
parent 5a493635fe
commit 17179e8deb
12 changed files with 100 additions and 58 deletions

View file

@ -35,16 +35,17 @@ def login():
if form.validate_on_submit():
user = User.query.filter_by(email=form.email.data).first()
if user is not None and user.verify_password(form.password.data):
if user.active == False:
flash('User disabled.')
return redirect(url_for('main.index'))
if user is not None and user.verify_password(form.password.data):
if user.twofactor:
# redirect to the two-factor auth page, passing username in session
session['email'] = user.email
session['memberberry'] = form.remember_me.data
return redirect(url_for('auth.twofactor'))
#print('remember: ' + str(form.remember_me.data))
login_user(user, form.remember_me.data)
previp = user.last_ip
@ -56,7 +57,7 @@ def login():
db.session.add(user)
db.session.commit()
#send_email(current_app.config['MAIL_USERNAME'], user.email + ' logged in.', 'auth/email/adm_loginnotify', user=user, ipaddr=lastip )
flash('Last Login: {} from {}'.format(user.last_seen, previp))
flash('Last Login: {} from {}'.format(user.last_seen.strftime("%a %d %B %Y %H:%M"), previp))
return redirect(request.args.get('next') or url_for('vmanager.dashboard'))
else:
flash('Invalid username or password.')
@ -92,6 +93,8 @@ def twofactor():
db.session.commit()
#send_email(current_app.config['MAIL_USERNAME'], user.email + ' logged in.', 'auth/email/adm_loginnotify', user=user, ipaddr=lastip )
return redirect(request.args.get('next') or url_for('vmanager.dashboard'))
else:
flash('Invalid token.')
return render_template('auth/2fa.html', page=page, form=form)

View file

@ -78,7 +78,7 @@ class User(db.Model, UserMixin):
org_vat = db.Column(db.Boolean, default=False)
org_vatnum = db.Column(db.String(16))
group = db.Column(db.String(24), default='nogroup')
group = db.Column(db.String(24), default='User')
language = db.Column(db.String(2), default='BG')
wallet = db.Column(db.Float, default=0.0)
currency = db.Column(db.String(3), default='BGN')

View file

@ -21,8 +21,13 @@ class EditProfileForm(FlaskForm):
country = SelectField('Държава:', choices=clist, default='BG')
phone = StringField('Телефон:')
org_account = BooleanField('Юридическо лице')
org_companyname = StringField('Име на фирма:')
org_regaddress = StringField('Адресна регистрация:')
org_responsible = StringField('Отговорно Лице:')
org_bulstat = StringField('БУЛСТАТ:')
org_vat = BooleanField('Регистрация по ДДС')
org_vatnum = StringField('ДДС Номер:')
twofactor = BooleanField('2-factor authentication')
submit = SubmitField('Обнови')
@ -43,13 +48,14 @@ class EditProfileAdminForm(FlaskForm):
country = SelectField('Държава:', choices=clist)
phone = DecimalField('Телефон:', [validators.DataRequired()])
org_account = StringField('Юридическо лице')
org_account = BooleanField('Юридическо лице')
org_companyname = StringField('Име на фирма:')
org_regaddress = StringField('Адресна регистрация:')
org_responsible = StringField('Отговор)но Лице:')
org_responsible = StringField('Отговорно Лице:')
org_bulstat = StringField('БУЛСТАТ:')
org_vat = StringField('Регистрация по ДДС:')
org_vat = BooleanField('Регистрация по ДДС')
org_vatnum = StringField('ДДС Номер:')
twofactor = BooleanField('2-factor authentication')
submit = SubmitField('Обнови')
def __init__(self, user, *args, **kwargs):

View file

@ -15,14 +15,6 @@ import sys
@login_required
def profile():
page = { 'title': 'Edit Profile' }
currentmail = current_user.email
ouruser = User.query.filter_by(email=currentmail).first()
db.session.commit()
wallet = "%.2f" % round(ouruser.wallet, 3)
current_app.logger.info('wallet: ' + wallet)
form = EditProfileForm()
if form.validate_on_submit():
current_user.name = form.name.data
@ -54,9 +46,12 @@ def profile():
form.org_regaddress.data = current_user.org_regaddress
form.org_responsible.data = current_user.org_responsible
form.org_bulstat.data = current_user.org_bulstat
form.org_vat = current_user.org_vat
form.org_vatnum = current_user.org_vatnum
form.org_vat.data = current_user.org_vat
form.org_vatnum.data = current_user.org_vatnum
form.twofactor.data = current_user.twofactor
wallet = "%.2f" % round(current_user.wallet, 3)
current_app.logger.info('wallet: ' + wallet)
return render_template('settings/profile.html', page=page, form=form, wallet=wallet)

View file

@ -1,12 +0,0 @@
<div class="col-md-4">
<div class="panel panel-info">
<div class="panel-heading">{{ current_user.name }}</div>
<div class="panel-body">
<a href="https://en.gravatar.com/site/signup/"><img class="roundavatar" src="{{ current_user.gravatar(128) }}"></img></a><br />
Group: {{ current_user.group }}<br />
2Factor: {{ current_user.twofactor }}<br />
Wallet: {{ wallet }} {{ current_user.currency }}
</div>
</div>
</div>

View file

@ -2,6 +2,28 @@
{% block title %}Edit Profile{% endblock %}
{% block scripts %}
{{ super() }}
<script type="text/javascript">
$(document).ready(function() {
$("#firm").hide();
var chkbox = document.getElementById("{{ form.org_account.id }}");
if (chkbox.checked) {
$("#firm").show();
} else {
$("#firm)").hide();
}
});
$("#{{ form.org_account.id }}").click(function() {
if ($('#{{ form.org_account.id }}').is(':checked')) {
$("#firm").show(); }
else {
$("#firm").hide(); }
});
</script>
{% endblock %}
{% block page_content %}
<div class="page-header">
<h1>Edit Your Profile</h1>
@ -12,7 +34,7 @@
<div class="row">
{% block sidebar %}
{% include "settings/_sidebar.html" %}
{% include "/sidebar.html" %}
{% endblock %}
<div class="col-md-8">
@ -21,28 +43,28 @@
<div class="panel-body">
<form method="POST" action="{{ url_for('settings.profile') }}">
<p>
{{ form.name.label }}<br />{{ form.name(size=42) }}<br />
{{ form.name.label }}<br />{{ form.name }}<br />
{% for error in form.name.errors %}
{{ error }}<br />
{% endfor %}
</p>
<p>
{{ form.address.label }}<br /> {{ form.address(size=42) }}<br />
{{ form.address.label }}<br /> {{ form.address }}<br />
{% for error in form.address.errors %}
{{ error }}<br />
{% endfor %}
</p>
<p>
{{ form.city.label }}<br />{{ form.city(size=42) }}<br />
{{ form.city.label }}<br />{{ form.city }}<br />
{% for error in form.city.errors %}
{{ error }}<br />
{% endfor %}
</p>
<p>
{{ form.postcode.label }}<br />{{ form.postcode(size=24) }}<br />
{{ form.postcode.label }}<br />{{ form.postcode }}<br />
{% for error in form.postcode.errors %}
{{ error }}<br />
{% endfor %}
@ -56,37 +78,61 @@
</p>
<p>
{{ form.phone.label }}<br /> {{ form.phone(size=42) }}<br />
{{ form.phone.label }}<br /> {{ form.phone }}<br />
{% for error in form.phone.errors %}
{{ error }}<br />
{% endfor %}
</p>
<p>
{{ form.org_account }} {{ form.org_account.label }}<br />
</p>
</div>
</div>
<div id="firm">
<div class="panel panel-default">
<div class="panel-heading">Данни за юридическо лице</div>
<div class="panel-body">
<p>
{{ form.org_responsible.label }}<br />{{ form.org_responsible(size=42) }}<br />
{{ form.org_companyname.label }}<br />{{ form.org_companyname }}<br />
{% for error in form.org_companyname.errors %}
{{ error }}<br />
{% endfor %}
</p>
<p>
{{ form.org_regaddress.label }}<br />{{ form.org_regaddress }}<br />
{% for error in form.org_regaddress.errors %}
{{ error }}<br />
{% endfor %}
</p>
<p>
{{ form.org_responsible.label }}<br />{{ form.org_responsible }}<br />
{% for error in form.org_responsible.errors %}
{{ error }}<br />
{% endfor %}
</p>
<p>
{{ form.org_bulstat.label }}<br />{{ form.org_bulstat(size=42) }}<br />
{{ form.org_bulstat.label }}<br />{{ form.org_bulstat }}<br />
{% for error in form.org_bulstat.errors %}
{{ error }}<br />
{% endfor %}
</p>
<p>
{{ form.org_vat }} {{ form.org_vat.label }}
</p>
<p>
{{ form.org_vatnum.label }}<br />{{ form.org_vatnum }}<br />
{% for error in form.org_vatnum.errors %}
{{ error }}<br />
{% endfor %}
</p>
</div>
</div>
</div>
<div class="panel panel-default">

View file

@ -0,0 +1,14 @@
<div class="col-md-4">
<div class="panel panel-info">
<div class="panel-heading">{{ current_user.name }}</div>
<div class="panel-body">
<a href="https://en.gravatar.com/site/signup/"><img class="roundavatar" align="right" src="{{ current_user.gravatar(128) }}"></img></a>
<p><br />
<b>Wallet:</b> {{ current_user.wallet|round(2) }} {{ current_user.currency }}<br />
<b>Group:</b> {{ current_user.group }}<br />
<b>2-Factor:</b> {{ current_user.twofactor }}<br />
</p>
</div>
</div>
</div>

View file

@ -1,10 +0,0 @@
<div class="col-md-4">
<div class="panel panel-info">
<div class="panel-heading">{{ current_user.name }}</div>
<div class="panel-body">
<a href="https://en.gravatar.com/site/signup/"><img class="roundavatar" src="{{ current_user.gravatar(128) }}"></img></a><br />
2-Factor: {{ current_user.twofactor }}<br />
</div>
</div>
</div>

View file

@ -12,7 +12,7 @@
<div class="row">
{% block sidebar %}
{% include "uinvoice/_sidebar.html" %}
{% include "/sidebar.html" %}
{% endblock %}
<div class="col-md-8">

View file

@ -12,7 +12,7 @@
<div class="row">
{% block sidebar %}
{% include "uinvoice/_sidebar.html" %}
{% include "/sidebar.html" %}
{% endblock %}
<div class="col-md-8">

View file

@ -12,7 +12,7 @@
<div class="row">
{% block sidebar %}
{% include "uinvoice/_sidebar.html" %}
{% include "/sidebar.html" %}
{% endblock %}
<div class="col-md-8">

View file

@ -32,7 +32,7 @@ addEventListener("DOMContentLoaded", function() {
//alert(request.responseText);
};
// We point the request at the appropriate command
request.open("GET", "/" + command + "/" + vmid, true);
request.open("GET", "/vmanager/" + command + "/" + vmid, true);
// and then we send it off
request.send();
});
@ -55,7 +55,7 @@ addEventListener("DOMContentLoaded", function() {
<div class="row">
{% block sidebar %}
{% include "uinvoice/_sidebar.html" %}
{% include "/sidebar.html" %}
{% endblock %}
<div class="col-md-4">
@ -108,7 +108,7 @@ addEventListener("DOMContentLoaded", function() {
<div id="control{{ deploy.machine_id}}" class="tab-pane fade">
<br />
{% if status[deploy.machine_id] == 'running' %}
<button class="btn btn-default btn-info" onclick="window.open('/vmvnc/{{ deploy.machine_id }}', '_blank');"><span class="glyphicon glyphicon-console" aria-hidden="true"></span> Console</button>
<button class="btn btn-default btn-info" onclick="window.open('/vmanager/vmvnc/{{ deploy.machine_id }}', '_blank');"><span class="glyphicon glyphicon-console" aria-hidden="true"></span> Console</button>
<button class="command command-vmshutdown btn btn-default btn-warning" value="vmshutdown" vmid="{{ deploy.machine_id }}"><span class="glyphicon glyphicon-off" aria-hidden="true"></span> Shutdown</button>
<button class="command command-vmstop btn btn-default btn-danger" value="vmstop" vmid="{{ deploy.machine_id }}"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> Force Stop</button>
{% else %}