Merge branch 'development' into alternate-dashboard-2

This commit is contained in:
DaanoGames
2025-04-17 15:47:34 +02:00
4 changed files with 56 additions and 18 deletions

View File

@@ -1,16 +1,15 @@
from flask import Blueprint, render_template, redirect, url_for
from flask import Blueprint, render_template, redirect, url_for, flash
from application import db
from application.auth.models import User
from application.auth.forms import LoginForm
from flask_login import ( # type: ignore
login_required, # type: ignore
login_user, # type: ignore
logout_user,
current_user,
)
from werkzeug.security import check_password_hash, generate_password_hash
from application.decorators import admin_required
from application.decorators import admin_required, login_required
from application.auth.forms import RegisterForm, UpdateForm
auth_blueprint = Blueprint("auth", __name__, template_folder="templates")
@@ -86,6 +85,7 @@ def update():
)
db.session.commit()
logout_user()
flash("Password changed succesfully, please log back in")
return redirect(url_for("auth.login"))
return render_template("update_user.html", form=form, active_page="update")
@@ -105,6 +105,7 @@ def login():
user.password, password # type: ignore
):
login_user(user) # type: ignore
flash("Logged in succesfully")
return redirect("/")
else:
feedback = "Username or password is incorrect"
@@ -117,4 +118,5 @@ def login():
@login_required
def logout():
logout_user()
flash("Logged out succesfully")
return redirect(url_for("index"))

View File

@@ -1,9 +1,10 @@
from application import db
from flask import Blueprint, render_template, redirect, url_for
from flask import Blueprint, render_template, redirect, url_for, flash
from application.dash.forms import ServiceForm
from flask_login import login_required, current_user # type: ignore
from flask_login import current_user # type: ignore
from application.dash.models import Service
from application.utils import saveImage
from application.decorators import login_required
# Dashboard blueprint
dash_blueprint = Blueprint("dash", __name__, template_folder="templates")
@@ -27,10 +28,12 @@ def delete_service(service_id: int):
# Check ownership
if service.user_id != current_user.id:
flash("This is not your service!")
return redirect(url_for("dash.index"))
db.session.delete(service)
db.session.commit()
flash("Service deleted")
return redirect(url_for("dash.index"))
@@ -56,12 +59,8 @@ def add_service():
) # type: ignore
db.session.add(new_service)
db.session.commit()
return render_template(
"add_service.html",
form=ServiceForm(formdata=None),
feedback="Service succesfully added",
active_page="service",
)
flash("Service added")
return redirect(url_for("dash.index"))
return render_template(
"add_service.html", form=service_form, active_page="service"
)
@@ -93,7 +92,8 @@ def edit_service(service_id: int):
commit = True
if commit:
db.session.commit()
return redirect(url_for("dash.index"))
flash("Service edited")
return redirect(url_for("dash.index"))
# Fill in correct data
form = ServiceForm(name=service.name, url=service.url)
return render_template("edit_service.html", form=form)

View File

@@ -11,9 +11,19 @@ def admin_required(f: Callable[..., Any]) -> Callable[..., Any]:
@wraps(f)
def decorated_function(*args: ..., **kwargs: ...):
if not current_user.is_authenticated:
return redirect(url_for("login"))
return redirect(url_for("auth.login"))
if not current_user.is_admin:
return redirect(url_for("index"))
return f(*args, **kwargs)
return decorated_function
def login_required(f: Callable[..., Any]) -> Callable[..., Any]:
@wraps(f)
def decorated_function(*args: ..., **kwargs: ...):
if not current_user.is_authenticated:
return redirect(url_for("auth.login"))
return f(*args, **kwargs)
return decorated_function

View File

@@ -38,20 +38,46 @@
</ul>
{% if current_user.is_authenticated %}
<div class="dropstart">
<button class="btn btn-outline-info" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">
<button class="btn btn-outline-info" type="button" id="dropdownMenuButton1"
data-bs-toggle="dropdown" aria-expanded="false">
Profile
</button>
<ul class="dropdown-menu dropdown-menu-end dropdown-menu-lg-start" aria-labelledby="dropdownMenuButton1">
<ul class="dropdown-menu dropdown-menu-end dropdown-menu-lg-start"
aria-labelledby="dropdownMenuButton1">
<li><a class="dropdown-item">Username: {{current_user.username}}</a></li>
<li><a class="dropdown-item {% if active_page == 'update' %}active{% endif %}" href="{{url_for('auth.update')}}">Change password</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" style="color: tomato;" data-bs-theme="dark" href="{{url_for('auth.logout')}}">Logout</a></li>
<li><a class="dropdown-item {% if active_page == 'update' %}active{% endif %}"
href="{{url_for('auth.update')}}">Change password</a></li>
<li>
<hr class="dropdown-divider">
</li>
<li><a class="dropdown-item" style="color: tomato;" data-bs-theme="dark"
href="{{url_for('auth.logout')}}">Logout</a></li>
</ul>
</div>
{% endif %}
</div>
</div>
</nav>
<svg xmlns="http://www.w3.org/2000/svg" class="d-none">
<symbol id="check-circle-fill" viewBox="0 0 16 16">
<path
d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zm-3.97-3.03a.75.75 0 0 0-1.08.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-.01-1.05z" />
</symbol>
</svg>
<div class="position-fixed bottom-0 end-0 p-3" style="z-index: 1050;">
{% for message in get_flashed_messages() %}
<div class="alert alert-success alert-dismissible fade show" role="alert">
<svg class="bi flex-shrink-0 me-2" width="15" height="15" role="img" aria-label="Success:">
<use xlink:href="#check-circle-fill" />
</svg>
{{message}}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
{% endfor %}
</div>
{% block content %}
{% endblock %}
</body>