nowe funkcje (zrealizowane) i poprawki w detekcji ip
This commit is contained in:
44
app.py
44
app.py
@ -43,6 +43,7 @@ class Zbiorka(db.Model):
|
||||
ukryta = db.Column(db.Boolean, default=False)
|
||||
ukryj_kwote = db.Column(db.Boolean, default=False)
|
||||
wplaty = db.relationship('Wplata', backref='zbiorka', lazy=True, order_by='Wplata.data.desc()')
|
||||
zrealizowana = db.Column(db.Boolean, default=False)
|
||||
|
||||
class Wplata(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
@ -91,7 +92,12 @@ def markdown_filter(text):
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
zbiorki = Zbiorka.query.filter_by(ukryta=False).all()
|
||||
zbiorki = Zbiorka.query.filter_by(ukryta=False, zrealizowana=False).all()
|
||||
return render_template('index.html', zbiorki=zbiorki)
|
||||
|
||||
@app.route('/zbiorki_zrealizowane')
|
||||
def zbiorki_zrealizowane():
|
||||
zbiorki = Zbiorka.query.filter_by(zrealizowana=True).all()
|
||||
return render_template('index.html', zbiorki=zbiorki)
|
||||
|
||||
@app.errorhandler(404)
|
||||
@ -106,6 +112,21 @@ def zbiorka(zbiorka_id):
|
||||
abort(404)
|
||||
return render_template('zbiorka.html', zbiorka=zb)
|
||||
|
||||
def get_real_ip():
|
||||
# Sprawdź, czy żądanie pochodzi przez Cloudflare
|
||||
if "CF-Connecting-IP" in request.headers:
|
||||
return request.headers.get("CF-Connecting-IP")
|
||||
# Następnie sprawdź nagłówek X-Real-IP
|
||||
elif "X-Real-IP" in request.headers:
|
||||
return request.headers.get("X-Real-IP")
|
||||
# Jeśli jest nagłówek X-Forwarded-For, pobierz pierwszy adres na liście
|
||||
elif "X-Forwarded-For" in request.headers:
|
||||
forwarded_for = request.headers.get("X-Forwarded-For").split(",")
|
||||
return forwarded_for[0].strip()
|
||||
# W przeciwnym wypadku użyj standardowego remote_addr
|
||||
return request.remote_addr
|
||||
|
||||
|
||||
# TRASY LOGOWANIA I REJESTRACJI
|
||||
|
||||
@app.route('/login', methods=['GET', 'POST'])
|
||||
@ -117,7 +138,8 @@ def login():
|
||||
allowed_hosts_str = settings.allowed_login_hosts
|
||||
|
||||
# Sprawdzenie, czy adres IP klienta jest dozwolony
|
||||
if not is_allowed_ip(request.remote_addr, allowed_hosts_str):
|
||||
client_ip = get_real_ip()
|
||||
if not is_allowed_ip(client_ip, allowed_hosts_str):
|
||||
flash('Dostęp do endpointu /login jest zablokowany dla Twojego adresu IP', 'danger')
|
||||
return redirect(url_for('index'))
|
||||
|
||||
@ -166,12 +188,13 @@ def register():
|
||||
@app.route('/admin')
|
||||
@login_required
|
||||
def admin_dashboard():
|
||||
# Tylko użytkownik z flagą is_admin ma dostęp do pełnych funkcji panelu
|
||||
if not current_user.is_admin:
|
||||
flash('Brak uprawnień do panelu administracyjnego', 'danger')
|
||||
return redirect(url_for('index'))
|
||||
zbiorki = Zbiorka.query.all()
|
||||
return render_template('admin/dashboard.html', zbiorki=zbiorki)
|
||||
active_zbiorki = Zbiorka.query.filter_by(zrealizowana=False).all()
|
||||
completed_zbiorki = Zbiorka.query.filter_by(zrealizowana=True).all()
|
||||
return render_template('admin/dashboard.html', active_zbiorki=active_zbiorki,
|
||||
completed_zbiorki=completed_zbiorki)
|
||||
|
||||
@app.route('/admin/zbiorka/dodaj', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@ -346,6 +369,17 @@ def admin_settings():
|
||||
|
||||
return render_template('admin/settings.html', settings=settings)
|
||||
|
||||
@app.route('/admin/zbiorka/oznacz/<int:zbiorka_id>', methods=['POST'])
|
||||
@login_required
|
||||
def oznacz_zbiorka(zbiorka_id):
|
||||
if not current_user.is_admin:
|
||||
flash('Brak uprawnień do wykonania tej operacji', 'danger')
|
||||
return redirect(url_for('index'))
|
||||
zb = Zbiorka.query.get_or_404(zbiorka_id)
|
||||
zb.zrealizowana = True
|
||||
db.session.commit()
|
||||
flash('Zbiórka została oznaczona jako zrealizowana', 'success')
|
||||
return redirect(url_for('admin_dashboard'))
|
||||
|
||||
@app.route('/robots.txt')
|
||||
def robots():
|
||||
|
Reference in New Issue
Block a user