mirror of
https://github.com/csd4ni3l/grass_touching_captcha.git
synced 2026-01-01 04:23:45 +01:00
Check if user is banned, log them out and then flash them with a funny message which is handled by error modals
This commit is contained in:
16
main.py
16
main.py
@@ -1,4 +1,4 @@
|
||||
from flask import Flask, redirect, url_for, render_template, request, Response, send_from_directory, g
|
||||
from flask import Flask, redirect, url_for, render_template, request, Response, send_from_directory, g, flash
|
||||
from dotenv import load_dotenv
|
||||
from constants import RICKROLL_LINK, UPLOAD_DIR, MINIMUM_COSINE_SIMILARITY, MINIMUM_OCR_SIMILARITY, DATABASE_FILE
|
||||
from PIL import Image
|
||||
@@ -82,6 +82,20 @@ def user_loader(user_id):
|
||||
def unauthorized_handler():
|
||||
return redirect(url_for("login"))
|
||||
|
||||
@app.before_request
|
||||
def check_banned():
|
||||
username = flask_login.current_user.id
|
||||
|
||||
cur = get_db().cursor()
|
||||
cur.execute("SELECT banned FROM Users WHERE username = ?", (username))
|
||||
row = cur.fetchone()
|
||||
cur.close()
|
||||
|
||||
if row is None or row[0]:
|
||||
flash("Imagine forgetting to touch grass so you get banned from my app. Such a discord moderator you are. You have no life. Just go outside.")
|
||||
flask_login.logout_user()
|
||||
return redirect("/")
|
||||
|
||||
def resize_image_file(path, max_side=256, fmt="JPEG"):
|
||||
img = Image.open(path)
|
||||
scale = max_side / max(img.size)
|
||||
|
||||
@@ -17,6 +17,38 @@
|
||||
DANGER! Touching grass involves going outside which might cause death for certain individuals!
|
||||
For more information, please visit <a href="/info" class="alert-link">the unofficial safety guide</a>!
|
||||
</div>
|
||||
{% block body %} {% endblock %}
|
||||
{% block body %}{% endblock %}
|
||||
<div class="modal fade" id="errorModal" tabindex="-1" aria-labelledby="errorModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header bg-danger text-white">
|
||||
<h5 class="modal-title" id="errorModalLabel">Error</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body" id="errorModalBody">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||
{% if messages %}
|
||||
{% for category, message in messages %}
|
||||
{% if category == 'error' %}
|
||||
const modalBody = document.getElementById("errorModalBody");
|
||||
modalBody.textContent = "{{ message|escapejs }}";
|
||||
|
||||
const errorModal = new bootstrap.Modal(document.getElementById('errorModal'));
|
||||
errorModal.show();
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user