Commit 9f40a9a2 authored by Vladislav Rykov's avatar Vladislav Rykov
Browse files

admin:new user added&tested, user dashboard view in progress

parent 49b95dae
...@@ -66,9 +66,8 @@ def get_user_data_count_per_hour_period(cur, username, period): ...@@ -66,9 +66,8 @@ 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])
utc_hour = [utc_roundhour(x) for x in range(period,-1,-1)]
if apps != [] and devs != []: if apps != [] and devs != []:
utc_hour = [utc_roundhour(x) for x in range(period,-1,-1)]
query = 'WITH t AS (' query = 'WITH t AS ('
i = 0 i = 0
for a in apps: for a in apps:
...@@ -86,7 +85,7 @@ def get_user_data_count_per_hour_period(cur, username, period): ...@@ -86,7 +85,7 @@ def get_user_data_count_per_hour_period(cur, username, period):
return (True,cur.fetchall()) return (True,cur.fetchall())
else: else:
return (True, (0,)) return (True, [(0,)])
...@@ -145,7 +144,7 @@ def get_user_data_count_per_day_period(cur, username, period): ...@@ -145,7 +144,7 @@ def get_user_data_count_per_day_period(cur, username, period):
return (True,cur.fetchall()) return (True,cur.fetchall())
else: else:
return (True, (0,)) return (True, [(0,)])
@with_psql @with_psql
...@@ -156,6 +155,7 @@ def get_recent_activity(cur, username, n=5): ...@@ -156,6 +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 != []:
query = '' query = ''
for a in apps: for a in apps:
devs = dd.get_list(a[1]) devs = dd.get_list(a[1])
...@@ -172,5 +172,7 @@ def get_recent_activity(cur, username, n=5): ...@@ -172,5 +172,7 @@ def get_recent_activity(cur, username, n=5):
cur.execute(query, ()) cur.execute(query, ())
return (True, cur.fetchall()) return (True, cur.fetchall())
else:
return (True, [])
...@@ -94,18 +94,18 @@ ...@@ -94,18 +94,18 @@
</li> </li>
{% if session['role'] == 'admin' %} {% if session['role'] == 'admin' %}
<li class="nav-item"> <li class="nav-item">
<a class="nav-link " href="./administration"> <a class="nav-link " href="/administration">
<i class="ni ni-briefcase-24 text-pink"></i> Administration <i class="ni ni-briefcase-24 text-pink"></i> Administration
</a> </a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link " href="./administration/users"> <a class="nav-link " href="/administration/users">
<i class="ni ni-single-02 text-info"></i> Users <i class="ni ni-single-02 text-info"></i> Users
</a> </a>
</li> </li>
{% endif %} {% endif %}
<li class="nav-item"> <li class="nav-item">
<a class="nav-link " href="./settings"> <a class="nav-link " href="/settings">
<i class="ni ni-settings-gear-65 text-grey"></i> Settings <i class="ni ni-settings-gear-65 text-grey"></i> Settings
</a> </a>
</li> </li>
......
{% extends 'logged_layout.html' %}
{% block title %} New User - HPC&amp;A IoT {% endblock %}
{% block location %}
<a class="h4 mb-0 text-white text-uppercase d-none d-lg-inline-block" href="/applications">Applications</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>
{% 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">New User</h3>
</div>
<div class="card-body">
<form action="/administration/users/new-user" method="post">
<div class="form-group">
<label>Name:</label><br>
<input type="text" maxlength="30" class="form-control" id="username" name="username" required><br>
</div>
<div class="form-group">
<label>Password:</label><br>
<input class="form-control" placeholder="Password" type="password" minlength="8" id="password" name="password" onkeyup="return validate_password();">
<br>
<input class="form-control" placeholder="Repeat password" type="password" minlength="8" id="rpassword" name="rpassword" onkeyup="return validate_password();">
</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>
<div class="form-group">
<label for="role"> Role: </label>
<select class="form-control" id="role" name="role">
<option> user </option>
<option> admin </option>
</select>
</div>
<br><br>
<div class="form-group">
<button type="submit" class="btn btn-primary">Create User</button>
</div>
</form>
</div>
</div>
</div>
</div>
{% endblock %}
{% block script %}
<script type="text/javascript">
var password = document.getElementById("password");
var rpassword = document.getElementById("rpassword");
$("#submit").prop("disabled", true);
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 %} User Dashboard - 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="#">Dashboard</a>
{% endblock %}
{% block stats %}
<div class="row">
<div class="col-xl-3 col-lg-6">
<div class="card card-stats mb-4 mb-xl-0">
<div class="card-body">
<div class="row">
<div class="col">
<h5 class="card-title text-uppercase text-muted mb-0">Created Apps</h5>
<span class="h2 font-weight-bold mb-0">{{ info[0] }}</span>
</div>
<div class="col-auto">
<div class="icon icon-shape bg-danger text-white rounded-circle shadow">
<i class="fas fa-chart-bar"></i>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-xl-3 col-lg-6">
<div class="card card-stats mb-4 mb-xl-0">
<div class="card-body">
<div class="row">
<div class="col">
<h5 class="card-title text-uppercase text-muted mb-0">Active Devices</h5>
<span class="h2 font-weight-bold mb-0">{{ info[1] }}</span>
</div>
<div class="col-auto">
<div class="icon icon-shape bg-warning text-white rounded-circle shadow">
<i class="fas fa-chart-pie"></i>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-xl-3 col-lg-6">
<div class="card card-stats mb-4 mb-xl-0">
<div class="card-body">
<div class="row">
<div class="col">
<h5 class="card-title text-uppercase text-muted mb-0">Total Activity</h5>
<span class="h2 font-weight-bold mb-0">{{ info[2] }}</span>
</div>
<div class="col-auto">
<div class="icon icon-shape bg-yellow text-white rounded-circle shadow">
<i class="fas fa-users"></i>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-xl-3 col-lg-6">
<div class="card card-stats mb-4 mb-xl-0">
<div class="card-body">
<div class="row">
<div class="col">
<h5 class="card-title text-uppercase text-muted mb-0">Last 24 Hours Activity</h5>
<span class="h2 font-weight-bold mb-0">{{ info[3] }}</span>
</div>
<div class="col-auto">
<div class="icon icon-shape bg-info text-white rounded-circle shadow">
<i class="fas fa-percent"></i>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block body %}
<div class="container-fluid mt--7">
<div class="row">
<div class="col-xl-8 mb-5 mb-xl-0">
<div class="card bg-gradient-default shadow">
<div class="card-header bg-transparent">
<div class="row align-items-center">
<div class="col">
<h6 class="text-uppercase text-light ls-1 mb-1">Day Overview</h6>
<h2 class="text-white mb-0">Devices Activity</h2>
</div>
<div class="col">
<ul class="nav nav-pills justify-content-end">
<li class="nav-item mr-2 mr-md-0" data-toggle="chart" data-target="#chart-sales" data-suffix="messages">
<a href="#" class="nav-link py-2 px-3 active" data-toggle="tab">
<span class="d-none d-md-block">Last 12 Hours</span>
<span class="d-md-none">M</span>
</a>
</li>
</ul>
</div>
</div>
</div>
<div class="card-body">
<!-- Chart -->
<div class="chart">
<!-- Chart wrapper -->
<canvas id="chart-sales" class="chart-canvas"></canvas>
</div>
</div>
</div>
</div>
<div class="col-xl-4">
<div class="card shadow">
<div class="card-header bg-transparent">
<div class="row align-items-center">
<div class="col">
<h6 class="text-uppercase text-muted ls-1 mb-1">Week Overview</h6>
<h2 class="mb-0">Per-day Activity</h2>
</div>
</div>
</div>
<div class="card-body">
<!-- Chart -->
<div class="chart">
<canvas id="chart-orders" class="chart-canvas"></canvas>
</div>
</div>
</div>
</div>
</div>
<div class="row mt-5">
<div class="col-xl-12 mb-5 mb-xl-0">
<div class="card shadow">
<div class="card-header border-0">
<div class="row align-items-center">
<div class="col">
<h3 class="mb-0">Recen Activity</h3>
</div>
</div>
</div>
<div class="table-responsive">
<!-- Projects table -->
<table class="table align-items-center table-flush">
<thead class="thead-light">
<tr>
<th scope="col">App name</th>
<th scope="col">Device name</th>
<th scope="col">Timestamp</th>
<th scope="col">Message</th>
</tr>
</thead>
<tbody id="recent_activity_body">
</tbody>
</table>
</div>
</div>
</div>
</div>
{% endblock %}
{% block script %}
<script type="text/javascript">
(function worker() {
var e = $("#chart-sales");
var e1 = $("#chart-orders");
$.get('/administration/users/{{ user }}/chart-update', function(cdata) {
cdata = eval(cdata);
var a = new Chart(e,
{
type: "line",
options:
{
scales:
{
yAxes: [
{
gridLines:
{
lineWidth: 1,
color: Charts.colors.gray[900],
zeroLineColor: Charts.colors.gray[900]
}
}]
},
tooltips:
{
callbacks:
{
label: function (e, a)
{
var t = a.datasets[e.datasetIndex].label || "",
o = e.yLabel,
n = "";
return 1 < a.datasets.length && (n += '<span class="popover-body-label mr-auto">' + t + "</span>"), n += '<span class="popover-body-value">' + o + "</span>"
}
}
}
},
data:
{
labels: cdata[0][0],
datasets: [
{
label: "Performance",
data: cdata[0][1]
}]
}
});
e.data("chart", a);
var a1 = new Chart(e1,
{
type: "bar",
options:
{
scales:
{
yAxes: [
{
gridLines:
{
lineWidth: 1,
color: "#dfe2e6",
zeroLineColor: "#dfe2e6"
},
ticks:
{
callback: function (e)
{
if (!(e % 10)) return e
}
}
}]
},
tooltips:
{
callbacks:
{
label: function (e, a)
{
var t = a.datasets[e.datasetIndex].label || "",
o = e.yLabel,
n = "";
return 1 < a.datasets.length && (n += '<span class="popover-body-label mr-auto">' + t + "</span>"), n += '<span class="popover-body-value">' + o + "</span>"
}
}
}
},
data:
{
labels: cdata[1][0],
datasets: [
{
label: "Sales",
data: cdata[1][1]
}]
}
});
e1.data("chart", a1);
setTimeout(worker, 600000);
});
})();
$.get("/administration/users/{{ user }}/recent-activity", function(cdata) {
$("#recent_activity_body").html(cdata);
});
</script>
{% endblock %}
...@@ -12,6 +12,48 @@ ...@@ -12,6 +12,48 @@
<a class="h4 mb-0 text-white text-uppercase d-none d-lg-inline-block" href="/administration/users">Users</a> <a class="h4 mb-0 text-white text-uppercase d-none d-lg-inline-block" href="/administration/users">Users</a>
{% endblock %} {% endblock %}
{% block stats %}
<!-- Header -->
<div class="row">
<div class="col-xl-4 col-lg-6">
<div class="card card-stats mb-4 mb-xl-0">
<div class="card-body">
<div class="row">
<div class="col">
<h5 class="card-title text-uppercase text-muted mb-0">Users</h5>
<span class="h2 font-weight-bold mb-0">{{ info[0] }}</span>
</div>
</div>
</div>
</div>
</div>
<div class="col-xl-4 col-lg-6">
<div class="card card-stats mb-4 mb-xl-0">
<div class="card-body">
<div class="row">
<div class="col">
<h5 class="card-title text-uppercase text-muted mb-0">Applications</h5>
<span class="h2 font-weight-bold mb-0">{{ info[1] }}</span>
</div>
</div>
</div>
</div>
</div>
<div class="col-xl-4 col-lg-6">
<div class="card card-stats mb-4 mb-xl-0">
<div class="card-body">
<div class="row">
<div class="col">
<h5 class="card-title text-uppercase text-muted mb-0">Devices</h5>
<span class="h2 font-weight-bold mb-0">{{ info[2] }}</span>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block body %} {% block body %}
<!-- Page content --> <!-- Page content -->
<div class="container-fluid mt--7"> <div class="container-fluid mt--7">
...@@ -50,36 +92,12 @@ ...@@ -50,36 +92,12 @@
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
<center><a href="javascript:void(0);" onclick="return table_load_more();">Load more</a></center>
{% endif %} {% endif %}
</div> </div>
<div class="card-footer py-4">
<nav aria-label="...">
<ul class="pagination justify-content-end mb-0">
<li class="page-item disabled">
<a class="page-link" href="#" tabindex="-1">
<i class="fas fa-angle-left"></i>
<span class="sr-only">Previous</span>
</a>
</li>
<li class="page-item active">
<a class="page-link" href="#">1</a>
</li>
<li class="page-item">
<a class="page-link" href="#">2 <span class="sr-only">(current)</span></a>
</li>
<li class="page-item"><a class="page-link" href="#">3</a></li>
<li class="page-item">
<a class="page-link" href="#">
<i class="fas fa-angle-right"></i>
<span class="sr-only">Next</span>
</a>
</li>
</ul>
</nav>
</div>
<div class="card-body"> <div class="card-body">
<div class="col-lg-4"> <div class="col-lg-4">
<a href="/administration/new-user"><button class="btn btn-primary" type="submit">New User</button></a> <a href="/administration/users/new-user"><button class="btn btn-primary" type="submit">New User</button></a>
</div> </div>
</div> </div>
...@@ -91,17 +109,32 @@ ...@@ -91,17 +109,32 @@
{% block script %} {% block script %}
<script type="text/javascript"> <script type="text/javascript">
var next_page = 2;
function users_update() { function users_update() {
$.ajax({ $.ajax({
url:"/administration/users/table-filter/1?name="+$("#filter_name").val(), url:"/administration/users/table/1?name="+$("#filter_name").val(),
type:"get", type:"get",
success: function(data) { success: function(data) {
data = eval(data); data = eval(data);
$("#users_body").empty(); $("#users_body").empty();
data.forEach(function (entry) { data.forEach(function (entry) {
str = "<tr onclick=window.location=\"/administration/users/"+entry[0]+"\"><td>"+entry[0]+"</td>"+"<td>"+entry[1]+"</td></tr>"; str = "<tr onclick=window.location=\"/administration/users/"+entry[0]+"\"><th>"+entry[0]+"</th>"+"<th>"+entry[1]+"</th></tr>";
$("#users_body").append(unescape(str));
});
}
});
}
function table_load_more() {
$.ajax({
url:"/administration/users/table/"+next_page+"?name="+$("#filter_name").val(),
type:"get",
success: function(data) {
data = eval(data);
data.forEach(function (entry) {
str = "<tr onclick=window.location=\"/administration/users/"+entry[0]+"\"><th>"+entry[0]+"</th>"+"<th>"+entry[1]+"</th></tr>";
$("#users_body").append(unescape(str)); $("#users_body").append(unescape(str));
}); });
next_page++;
} }
}); });
} }
......
...@@ -36,51 +36,36 @@ def index(): ...@@ -36,51 +36,36 @@ def index():
info = [created_apps, active_devices, total_activity, last_activity] info = [created_apps, active_devices, total_activity, last_activity]
return render_template('new/public/dashboard.html', info=info) return render_template('new/public/dashboard.html', info=info)
else: else:
return render_template('new/public/login.html', users_signup=app.config['USERS_SIGNUP']) return redirect(url_for('login'))
@app.route('/register', methods=['GET', 'POST']) @app.route('/register', methods=['GET', 'POST'])
def register(): def register():
if request.method == 'GET':
if 'role' in session and session['role'] == 'admin':
return render_template('old/admin/signup.html', users_signup=app.config['USERS_SIGNUP'])
else:
if app.config['USERS_SIGNUP']: if app.config['USERS_SIGNUP']:
return render_template('new/public/register.html', users_signup=app.config['USERS_SIGNUP']) if request.method == 'GET':
else: return render_template('new/public/register.html')
return redirect(url_for('index', users_signup=app.config['USERS_SIGNUP'])) elif request.method == 'POST':
else:
if app.config['USERS_SIGNUP'] or ('role' in session and session['role'] == 'admin'):
username = request.form['username'] username = request.form['username']
password = request.form['password'].encode('utf-8') password = request.form['password'].encode('utf-8')
if (username == '' or password == ''): if (username == '' or password == ''):
flash('Username or password fields cannot be empty', 'danger') flash('Username or password fields cannot be empty', 'danger')
return redirect(url_for('register', users_signup=app.config['USERS_SIGNUP'])) return redirect(request.url)
elif (len(password) < 8): elif (len(password) < 8):
flash('Password length must be at least 8 characters.', 'danger') flash('Password length must be at least 8 characters.', 'danger')
return redirect(url_for('register', users_signup=app.config['USERS_SIGNUP'])) return redirect(request.url)
else: else:
role = 'user' res = ud.create(username, password, 'user')
if 'role' in request.form and request.form['role'] == 'administrator':
role = 'admin'
res = ud.create(username, password, role)
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)
else: else:
session['name'] = username session['name'] = username
session['role'] = 'user'
flash('User successfully created.', 'success')
if 'role' in session and session['role'] == 'admin':
return redirect(url_for('administration'))
else:
return redirect(url_for('index')) return redirect(url_for('index'))
else: else:
return redirect(url_for('index')) return redirect(url_for('login'))
@app.route('/login', methods=['GET', 'POST']) @app.route('/login', methods=['GET', 'POST'])
...@@ -121,7 +106,7 @@ def applications(): ...@@ -121,7 +106,7 @@ def applications():
return render_template('new/public/applications.html', apps=apps[1]) return render_template('new/public/applications.html', apps=apps[1])
else: else:
return redirect(url_for('login', users_signup=app.config['USERS_SIGNUP'])) return redirect(url_for('login'))
@app.route('/application/<appkey>') @app.route('/application/<appkey>')
...@@ -133,7 +118,7 @@ def application(appkey): ...@@ -133,7 +118,7 @@ def application(appkey):
return render_template('new/public/application.html', app=ap, devs=devs) return render_template('new/public/application.html', app=ap, devs=devs)
else: else:
return redirect(url_for('login', users_signup=app.config['USERS_SIGNUP'])) return redirect(url_for('login'))
@app.route('/new-application', methods=['GET', 'POST']) @app.route('/new-application', methods=['GET', 'POST'])
...@@ -168,7 +153,7 @@ def application_create(): ...@@ -168,7 +153,7 @@ def application_create():
return redirect(url_for('applications')) return redirect(url_for('applications'))
else: else:
return redirect(url_for('login', users_signup=app.config['USERS_SIGNUP'])) return redirect(url_for('login'))
@app.route('/application/<appkey>/delete') @app.route('/application/<appkey>/delete')
...@@ -705,7 +690,7 @@ def user_delete(): ...@@ -705,7 +690,7 @@ def user_delete():
def settings(): def settings():
if request.method == 'GET': if request.method == 'GET':
if session['role'] == 'admin': if session['role'] == 'admin':
return render_template('old/admin/settings.html', username=session['name'], users_signup=app.config['USERS_SIGNUP']) return render_template('old/admin/settings.html', username=session['name'])
else: else:
return render_template('old/public/settings.html', username=session['name']) return render_template('old/public/settings.html', username=session['name'])
else: else:
......
...@@ -14,6 +14,7 @@ import app.dao.misc.misc as md ...@@ -14,6 +14,7 @@ import app.dao.misc.misc as md
#import app.helpers.misc as misc #import app.helpers.misc as misc
from app.helpers.misc import restricted from app.helpers.misc import restricted
import app.helpers.misc as misc
#import binascii #import binascii
...@@ -43,30 +44,90 @@ def administration(): ...@@ -43,30 +44,90 @@ def administration():
@app.route('/administration/users') @app.route('/administration/users')
@restricted(access_level='admin') @restricted(access_level='admin')
def administration_users(): def administration_users():
user_cnt = ud.get_count()[1][0]
apps_cnt = ad.get_count()[1][0]
devs_cnt = dd.get_count_all()[1][0]
info = [user_cnt, apps_cnt, devs_cnt]
cur_pg = 1 cur_pg = 1
users = ud.get_range([MAX_PG_ENTRIES_USERS, (cur_pg-1)*MAX_PG_ENTRIES_USERS])[1] users = ud.get_range([MAX_PG_ENTRIES_USERS, (cur_pg-1)*MAX_PG_ENTRIES_USERS])[1]
return render_template('new/admin/users.html', users=users) return render_template('new/admin/users.html', users=users, info=info)
@app.route('/administration/users/<name>') @app.route('/administration/users/<name>')
@restricted(access_level='admin') @restricted(access_level='admin')
def administration_users_user(name): def administration_users_user(name):
cur_pg = 1 created_apps = ad.get_count_by_user(name)[1][0]
users = ud.get_range([MAX_PG_ENTRIES_USERS, (cur_pg-1)*MAX_PG_ENTRIES_USERS])[1] active_devices = dd.get_count_by_user(name)
total_activity = md.get_user_data_count(name)[1][0]
last_activity = md.get_user_data_count_per_day(name)[1][0]
info = [created_apps, active_devices, total_activity, last_activity]
return render_template('new/admin/user.html', users=users) return render_template('new/admin/user-dashboard.html', info=info, user=name)
@app.route('/administration/users/table-<option>/<page>') @app.route('/administration/users/<name>/chart-update')
@restricted(access_level='admin') @restricted(access_level='admin')
def administration_users_table(option, page): def administration_users_user_chart_update(name):
if option == 'filter': day_chart_values = md.get_user_data_count_per_hour_period(name, 11)[1]
users = ud.get_range_name(request.args.get('name'), [MAX_PG_ENTRIES_USERS, (int(page)-1)*MAX_PG_ENTRIES_USERS])[1] day_chart_values = [x[0] for x in day_chart_values]
elif option == 'page': day_chart_labels = [misc.local_hour(x) for x in range(11,-1,-1)]
users = ud.get_range([MAX_PG_ENTRIES_USERS, (int(page)-1)*MAX_PG_ENTRIES_USERS])[1] day_chart = [day_chart_labels, day_chart_values]
week_chart_values = md.get_user_data_count_per_day_period(name, 6)[1]
week_chart_values = [x[0] for x in week_chart_values]
week_chart_labels = [misc.local_weekday(x) for x in range(6,-1,-1)]
week_chart = [week_chart_labels, week_chart_values]
return "[{}, {}]".format(day_chart, week_chart)
@app.route('/administration/users/<name>/recent-activity')
@restricted(access_level='admin')
def administration_users_user_recent_activity(name):
if 'name' in session:
recent_activity = md.get_recent_activity(name)[1]
ra = ''
for r in recent_activity:
ra += '<tr><th scope="row">'+r[1]+'</th><th>'+r[2]+'</th><th>'+r[0]+'</th><th>'+str(r[3])+'</th></tr>'
return ra, 200
else:
return '', 401
@app.route('/administration/users/table/<page>')
@restricted(access_level='admin')
def administration_users_table(page):
users = ud.get_range_name(request.args.get('name'), [MAX_PG_ENTRIES_USERS, (int(page)-1)*MAX_PG_ENTRIES_USERS])[1]
users = [[u[0],u[2]] for u in users] users = [[u[0],u[2]] for u in users]
return str(users), 200 return str(users), 200
@app.route('/administration/users/new-user', methods=['POST', 'GET'])
@restricted(access_level='admin')
def administration_users_new_user():
if request.method == 'GET':
return render_template('new/admin/new-user.html')
elif request.method == 'POST':
username = request.form['username']
password = request.form['password'].encode('utf-8')
role = request.form['role']
if (username == '' or password == ''):
flash('Username or password fields cannot be empty', 'danger')
return redirect(request.url)
elif (len(password) < 8):
flash('Password length must be at least 8 characters.', 'danger')
return redirect(request.url)
else:
res = ud.create(username, password, role)
if (not res[0]):
flash('Error: {}'.format(res[1]), 'danger')
return redirect(request.url)
else:
return redirect(url_for('administration/users', name=username))
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