Commit 385aadfd authored by Vladislav Rykov's avatar Vladislav Rykov
Browse files

new front end integrated finished (not purged)

parent f4558f94
...@@ -13,7 +13,7 @@ def get_user_data_count(cur, username): ...@@ -13,7 +13,7 @@ def get_user_data_count(cur, username):
for a in apps: for a in apps:
devs.append(dd.get_list(a[1])[1]) devs.append(dd.get_list(a[1])[1])
if apps != [] and devs != []: if apps != [] and devs != [[]]:
query = 'WITH t AS (' query = 'WITH t AS ('
i = 0 i = 0
for a in apps: for a in apps:
...@@ -38,7 +38,7 @@ def get_user_data_count_per_hour(cur, username, hour): ...@@ -38,7 +38,7 @@ def get_user_data_count_per_hour(cur, username, hour):
for a in apps: for a in apps:
devs.append(dd.get_list(a[1])[1]) devs.append(dd.get_list(a[1])[1])
if apps != [] and devs != []: if apps != [] and devs != [[]]:
utc_hour = utc_roundhour(hour) utc_hour = utc_roundhour(hour)
query = 'WITH t AS (' query = 'WITH t AS ('
...@@ -66,7 +66,7 @@ def get_user_data_count_per_hour_period(cur, username, period): ...@@ -66,7 +66,7 @@ def get_user_data_count_per_hour_period(cur, username, period):
for a in apps: for a in apps:
devs.append(dd.get_list(a[1])[1]) devs.append(dd.get_list(a[1])[1])
if apps != [] and devs != []: if apps != [] and devs != [[]]:
utc_hour = [utc_roundhour(x) for x in range(period,-1,-1)] utc_hour = [utc_roundhour(x) for x in range(period,-1,-1)]
query = 'WITH t AS (' query = 'WITH t AS ('
i = 0 i = 0
...@@ -97,7 +97,7 @@ def get_user_data_count_per_day(cur, username, day=0): ...@@ -97,7 +97,7 @@ def get_user_data_count_per_day(cur, username, day=0):
for a in apps: for a in apps:
devs.append(dd.get_list(a[1])[1]) devs.append(dd.get_list(a[1])[1])
if apps != [] and devs != []: if apps != [] and devs != [[]]:
utc_day = utc_roundday(day) utc_day = utc_roundday(day)
query = 'WITH t AS (' query = 'WITH t AS ('
...@@ -124,7 +124,7 @@ def get_user_data_count_per_day_period(cur, username, period): ...@@ -124,7 +124,7 @@ def get_user_data_count_per_day_period(cur, username, period):
for a in apps: for a in apps:
devs.append(dd.get_list(a[1])[1]) devs.append(dd.get_list(a[1])[1])
if apps != [] and devs != []: if apps != [] and devs != [[]]:
utc_hour = [utc_roundday(x) for x in range(period,-1,-1)] utc_hour = [utc_roundday(x) for x in range(period,-1,-1)]
query = 'WITH t AS (' query = 'WITH t AS ('
...@@ -155,7 +155,7 @@ def get_recent_activity(cur, username, n=5): ...@@ -155,7 +155,7 @@ def get_recent_activity(cur, username, n=5):
for a in apps: for a in apps:
devs.append(dd.get_list(a[1])[1]) devs.append(dd.get_list(a[1])[1])
if apps != [] and devs != []: if apps != [] and devs != [[]]:
query = '' query = ''
for a in apps: for a in apps:
devs = dd.get_list(a[1]) devs = dd.get_list(a[1])
......
...@@ -117,7 +117,7 @@ ...@@ -117,7 +117,7 @@
<!-- Navigation --> <!-- Navigation -->
<ul class="navbar-nav mb-md-3"> <ul class="navbar-nav mb-md-3">
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="/getting-started/overview.html"> <a class="nav-link" href="/getting-started">
<i class="ni ni-spaceship"></i> Getting started <i class="ni ni-spaceship"></i> Getting started
</a> </a>
</li> </li>
...@@ -147,10 +147,12 @@ ...@@ -147,10 +147,12 @@
<div class=" dropdown-header noti-title"> <div class=" dropdown-header noti-title">
<h6 class="text-overflow m-0">Welcome!</h6> <h6 class="text-overflow m-0">Welcome!</h6>
</div> </div>
<!--
<a href="/profile" class="dropdown-item"> <a href="/profile" class="dropdown-item">
<i class="ni ni-single-02"></i> <i class="ni ni-single-02"></i>
<span>My profile</span> <span>My profile</span>
</a> </a>
-->
<a href="/settings" class="dropdown-item"> <a href="/settings" class="dropdown-item">
<i class="ni ni-settings-gear-65"></i> <i class="ni ni-settings-gear-65"></i>
<span>Settings</span> <span>Settings</span>
......
{% extends 'logged_layout.html' %}
{% block title %} Administration - {{ user }} - Settings - HPC&amp;A IoT {% endblock %}
{% block location %}
<a class="h4 mb-0 text-white text-uppercase d-none d-lg-inline-block" href="/administration">Administration</a>
<p class="h4 mb-0 text-white text-uppercase d-none d-lg-inline-block"> &nbsp;-&nbsp; </p>
<a class="h4 mb-0 text-white text-uppercase d-none d-lg-inline-block" href="/administration/users">Users</a>
<p class="h4 mb-0 text-white text-uppercase d-none d-lg-inline-block"> &nbsp;-&nbsp; </p>
<a class="h4 mb-0 text-white text-uppercase d-none d-lg-inline-block" href="/administration/users/{{ user }}">{{ user }}</a>
<p class="h4 mb-0 text-white text-uppercase d-none d-lg-inline-block"> &nbsp;-&nbsp; </p>
<a class="h4 mb-0 text-white text-uppercase d-none d-lg-inline-block" href="/administration/users/{{ user }}/settings">Settings</a>
{% endblock %}
{% block body %}
<!-- Page content -->
<div class="container-fluid mt--7">
<!-- Table -->
<div class="row">
<div class="col">
<div class="card shadow">
<div class="card-header bg-transparent">
<h3 class="mb-0">User Settings</h3>
</div>
<div class="card-body">
<form action="/administration/users/{{ user }}/settings" method="post" id="settings">
<div class="form-group">
<label>Name:</label><br>
<input type="text" maxlength="30" class="form-control" id="name" name="name" value="{{ user }}" style="pointer-events: none;"><br>
</div>
<br>
<div class="form-group">
<div class="input-group input-group-alternative">
<div class="input-group-prepend">
<span class="input-group-text"><i class="ni ni-lock-circle-open"></i></span>
</div>
<input class="form-control" placeholder="Password" type="password" minlength="8" id="password" name="password" onkeyup="return validate_password();">
</div>
</div>
<div class="form-group">
<div class="input-group input-group-alternative">
<div class="input-group-prepend">
<span class="input-group-text"><i class="ni ni-lock-circle-open"></i></span>
</div>
<input class="form-control" placeholder="Repeat password" type="password" minlength="8" id="rpassword" name="rpassword" onkeyup="return validate_password();">
</div>
</div>
<div class="text-muted font-italic"><small>Required password strength: <span class="text-success font-weight-700">At least 8 characters.</span></small></div>
<div class="text-muted font-italic"><small id="passvalidation"></small></div>
<br>
</form>
<div class="row" style="margin-top: 30px;">
<div class="col-lg-3">
<button type="submit" form="settings" id="submit" class="btn btn-primary btn-block">Save</button>
</div>
<div class="col-lg-3">
</div>
<div class="col-lg-3">
</div>
<div class="col-lg-3">
<button type="button" class="btn btn-danger btn-block" data-toggle="modal" data-target="#exampleModal">Delete</button>
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Are you sure?</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
This action will remove permanently the account, applications and all its devices with their corresponding data.
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<a href="/administration/users/{{ user }}/delete-account"><button type="button" class="btn btn-danger">Delete Account</button></a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block script %}
<script type="text/javascript">
var password = document.getElementById("password");
var rpassword = document.getElementById("rpassword");
function validate_password() {
if (password.value != rpassword.value) {
$("#passvalidation").html("<span class='text-danger font-weight-700'>Passwords do not match.</span>");
$("#submit").prop("disabled", true);
} else {
$("#passvalidation").html("<span class='text-success font-weight-700'>Passwords match.</span>");
$("#submit").prop("disabled", false);
}
}
</script>
{% endblock %}
{% extends 'logged_layout.html' %}
{% block title %} Settings - HPC&amp;A IoT {% endblock %}
{% block location %}
<a class="h4 mb-0 text-white text-uppercase d-none d-lg-inline-block" href="/settings">Settings</a>
{% endblock %}
{% block body %}
<!-- Page content -->
<div class="container-fluid mt--7">
<!-- Table -->
<div class="row">
<div class="col">
<div class="card shadow">
<div class="card-header bg-transparent">
<h3 class="mb-0">User Settings</h3>
</div>
<div class="card-body">
<form action="/settings" method="post" id="settings">
<div class="form-group">
<label>Name:</label><br>
<input type="text" maxlength="30" class="form-control" id="name" name="name" value="{{ user }}" style="pointer-events: none;"><br>
</div>
<br>
<div class="form-group">
<div class="input-group input-group-alternative">
<div class="input-group-prepend">
<span class="input-group-text"><i class="ni ni-lock-circle-open"></i></span>
</div>
<input class="form-control" placeholder="Password" type="password" minlength="8" id="password" name="password" onkeyup="return validate_password();">
</div>
</div>
<div class="form-group">
<div class="input-group input-group-alternative">
<div class="input-group-prepend">
<span class="input-group-text"><i class="ni ni-lock-circle-open"></i></span>
</div>
<input class="form-control" placeholder="Repeat password" type="password" minlength="8" id="rpassword" name="rpassword" onkeyup="return validate_password();">
</div>
</div>
<div class="text-muted font-italic"><small>Required password strength: <span class="text-success font-weight-700">At least 8 characters.</span></small></div>
<div class="text-muted font-italic"><small id="passvalidation"></small></div>
<br>
</form>
<div class="row" style="margin-top: 30px;">
<div class="col-lg-3">
<button type="submit" form="settings" id="submit" class="btn btn-primary btn-block">Save</button>
</div>
<div class="col-lg-3">
</div>
<div class="col-lg-3">
</div>
<div class="col-lg-3">
<button type="button" class="btn btn-danger btn-block" data-toggle="modal" data-target="#exampleModal">Delete</button>
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Are you sure?</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
This action will remove permanently the account, applications and all its devices with their corresponding data.
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<a href="/delete-account?name={{ user }}"><button type="button" class="btn btn-danger">Delete Account</button></a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block script %}
<script type="text/javascript">
var password = document.getElementById("password");
var rpassword = document.getElementById("rpassword");
function validate_password() {
if (password.value != rpassword.value) {
$("#passvalidation").html("<span class='text-danger font-weight-700'>Passwords do not match.</span>");
$("#submit").prop("disabled", true);
} else {
$("#passvalidation").html("<span class='text-success font-weight-700'>Passwords match.</span>");
$("#submit").prop("disabled", false);
}
}
</script>
{% endblock %}
...@@ -647,10 +647,10 @@ def user(): ...@@ -647,10 +647,10 @@ def user():
return render_template('old/public/index.html') return render_template('old/public/index.html')
@app.route('/user-delete') @app.route('/delete-account')
def user_delete(): def delete_account():
user = ud.get(request.args.get('name')) user = ud.get(request.args.get('name'))
if user[0] and user[1][2] != 'admin' and session['role'] == 'admin': if user[0] and user[1][2] != 'admin':
app_list = ad.get_list(user[1][0]) app_list = ad.get_list(user[1][0])
res = (True,) res = (True,)
...@@ -678,19 +678,17 @@ def user_delete(): ...@@ -678,19 +678,17 @@ def user_delete():
flash('Error: {}'.format(res[1]), 'danger') flash('Error: {}'.format(res[1]), 'danger')
return render_template('old/admin/user.html', username=user[1][0]) return render_template('old/admin/user.html', username=user[1][0])
else: else:
return redirect(url_for('administraion')) flash('User {} was successfully deleted'.format(request.args.get('name')), 'success')
return redirect(url_for('login'))
else: else:
flash('Warning: the user is admin or does not exist.' ,'warning') flash('Warning: the user is admin or does not exist.' ,'danger')
return redirect(url_for('index')) return redirect(url_for('settings'))
@app.route('/settings', methods=['GET', 'POST']) @app.route('/settings', methods=['GET', 'POST'])
def settings(): def settings():
if request.method == 'GET': if request.method == 'GET':
if session['role'] == 'admin': return render_template('new/public/settings.html', user=session['name'])
return render_template('old/admin/settings.html', username=session['name'])
else:
return render_template('old/public/settings.html', username=session['name'])
else: else:
if request.form['name'] != session['name']: if request.form['name'] != session['name']:
res = ud.update_name(session['name'], request.form['name']) res = ud.update_name(session['name'], request.form['name'])
...@@ -704,13 +702,8 @@ def settings(): ...@@ -704,13 +702,8 @@ def settings():
if not res[0]: if not res[0]:
flash('Error: {}'.format(res[1]), 'danger') flash('Error: {}'.format(res[1]), 'danger')
return redirect(request.url) return redirect(request.url)
if session['role'] == 'admin':
if request.form.getlist('users_signup') and request.form.getlist('users_signup')[0] == 'us':
app.config['USERS_SIGNUP'] = True
else:
app.config['USERS_SIGNUP'] = False
flash('Settings successfully saved.', 'success')
return redirect(request.url) return redirect(request.url)
......
...@@ -516,3 +516,62 @@ def administration_users_new_user(): ...@@ -516,3 +516,62 @@ def administration_users_new_user():
else: else:
return redirect(url_for('administration/users', name=username)) return redirect(url_for('administration/users', name=username))
@app.route('/administration/users/<name>/settings', methods=['GET', 'POST'])
@restricted(access_level='admin')
def administration_users_user_settings(name):
if request.method == 'GET':
return render_template('new/admin/user-settings.html', user=name)
else:
if request.form['name'] != name:
res = ud.update_name(name, request.form['name'])
if not res[0]:
flash('Error: {}'.format(res[1]), 'danger')
return redirect(request.url);
if request.form['password'] != '':
res = ud.update_password(name, request.form['password'].encode('utf-8'))
if not res[0]:
flash('Error: {}'.format(res[1]), 'danger')
return redirect(request.url)
flash('Settings successfully saved.', 'success')
return redirect(request.url)
@app.route('/administration/users/<name>/delete-account')
@restricted(access_level='admin')
def administration_users_user_delete_account(name):
user = ud.get(name)
if user[0] and user[1][2] != 'admin':
app_list = ad.get_list(user[1][0])
res = (True,)
if app_list[0]:
for app in app_list[1]:
devs = dd.get_list(app[1])
for dev in devs[1]:
res = data.delete_table(app[1], dev[1])
if not res[0]:
break
if res[0]:
res = dd.delete_table(app[1])
if res[0]:
res = ad.delete(app[1])
if not res[0]:
break
if res[0]:
res = ud.delete(user[1][0])
if not res[0]:
flash('Error: {}'.format(res[1]), 'danger')
return render_template('new/admin/user-settings.html', user=name)
else:
flash('User {} was successfully deleted'.format(name), 'success')
return redirect(url_for('administration_users'))
else:
flash('Warning: the user is admin or does not exist.' ,'danger')
return redirect(url_for('administration_users_user_settings', name=name))
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