mirror of
https://github.com/simon987/Simple-Incremental-Search-Tool.git
synced 2025-04-19 02:06:45 +00:00
Some work on user management
This commit is contained in:
parent
f06cc9e4a4
commit
3b2d2bdd8d
@ -17,3 +17,4 @@ docx2txt
|
|||||||
xlrd
|
xlrd
|
||||||
six
|
six
|
||||||
cairosvg
|
cairosvg
|
||||||
|
ffmpeg-python
|
29
run.py
29
run.py
@ -37,6 +37,12 @@ def get_dir_size(path):
|
|||||||
@app.route("/user/<user>")
|
@app.route("/user/<user>")
|
||||||
def user_manage(user):
|
def user_manage(user):
|
||||||
|
|
||||||
|
if "admin" in session and session["admin"]:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
flash("You are not authorized to access this page", "warning")
|
||||||
|
return redirect("/")
|
||||||
|
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
@ -67,17 +73,31 @@ def login():
|
|||||||
@app.route("/user")
|
@app.route("/user")
|
||||||
def user_page():
|
def user_page():
|
||||||
|
|
||||||
if "admin" in session and session["admin"]:
|
admin_account_present = False
|
||||||
return render_template("user.html", users=storage.users())
|
|
||||||
|
for user in storage.users():
|
||||||
|
if storage.users()[user].admin:
|
||||||
|
admin_account_present = True
|
||||||
|
break
|
||||||
|
|
||||||
|
if not admin_account_present or ("admin" in session and session["admin"]):
|
||||||
|
return render_template("user.html", users=storage.users(), admin_account_present=admin_account_present)
|
||||||
else:
|
else:
|
||||||
flash("You are not authorized to access this page")
|
flash("You are not authorized to access this page", "warning")
|
||||||
return redirect("/")
|
return redirect("/")
|
||||||
|
|
||||||
|
|
||||||
@app.route("/user/add", methods=['POST'])
|
@app.route("/user/add", methods=['POST'])
|
||||||
def user_add():
|
def user_add():
|
||||||
|
|
||||||
if "admin" in session and session["admin"]:
|
admin_account_present = False
|
||||||
|
|
||||||
|
for user in storage.users():
|
||||||
|
if storage.users()[user].admin:
|
||||||
|
admin_account_present = True
|
||||||
|
break
|
||||||
|
|
||||||
|
if not admin_account_present or ("admin" in session and session["admin"]):
|
||||||
username = request.form["username"]
|
username = request.form["username"]
|
||||||
password = bcrypt.hashpw(request.form["password"].encode("utf-8"), bcrypt.gensalt(config.bcrypt_rounds))
|
password = bcrypt.hashpw(request.form["password"].encode("utf-8"), bcrypt.gensalt(config.bcrypt_rounds))
|
||||||
is_admin = True if "is_admin" in request.form else False
|
is_admin = True if "is_admin" in request.form else False
|
||||||
@ -99,7 +119,6 @@ def suggest():
|
|||||||
|
|
||||||
return json.dumps(search.suggest(request.args.get("prefix")))
|
return json.dumps(search.suggest(request.args.get("prefix")))
|
||||||
|
|
||||||
|
|
||||||
@app.route("/document/<doc_id>")
|
@app.route("/document/<doc_id>")
|
||||||
def document(doc_id):
|
def document(doc_id):
|
||||||
|
|
||||||
|
4
static/css/bootstrap.min.css
vendored
4
static/css/bootstrap.min.css
vendored
File diff suppressed because one or more lines are too long
@ -9,6 +9,10 @@
|
|||||||
<div class="card-header">Create user</div>
|
<div class="card-header">Create user</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
|
|
||||||
|
{% if not admin_account_present %}
|
||||||
|
<p>This page is unlocked because there are no admin accounts</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<form method="POST" action="/user/add">
|
<form method="POST" action="/user/add">
|
||||||
|
|
||||||
<div class="input-group form-group">
|
<div class="input-group form-group">
|
||||||
@ -44,7 +48,7 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
{% for user in users %}
|
{% for user in users %}
|
||||||
<tr>
|
<tr>
|
||||||
<td style="width: 80%;">{{ user }}</td>
|
<td style="width: 80%;">{% if session["username"] == user %}<b>{{ user }}{% else %}{{ user }}{% endif %}</b></td>
|
||||||
<td><i class="far {{ "fa-check-square" if users[user].admin else "fa-square" }}"></i></td>
|
<td><i class="far {{ "fa-check-square" if users[user].admin else "fa-square" }}"></i></td>
|
||||||
<td><a href="/user/{{ user }}" class="btn btn-primary">Manage</a></td>
|
<td><a href="/user/{{ user }}" class="btn btn-primary">Manage</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -1,29 +1,15 @@
|
|||||||
{% extends "layout.html" %}
|
{% extends "layout.html" %}
|
||||||
|
|
||||||
|
{% set active_page = "user" %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-header">Directory permissions</div>
|
<div class="card-header">Manage permission of <strong>{{ session["username"] }}</strong></div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
|
|
||||||
<table class="info-table table-hover table-striped">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Directory</th>
|
|
||||||
<th>Search access</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{% for user in users %}
|
|
||||||
<tr>
|
|
||||||
<td>{{ user }}</td>
|
|
||||||
<td><i class="far {{ "fa-check-square" if users[user].admin else "fa-square" }}"></i></td>
|
|
||||||
<td><a href="/user/{{ user }}" class="btn btn-primary">Manage</a></td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
</tbody>
|
|
||||||
|
|
||||||
</table>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user