mirror of
https://github.com/simple-login/app.git
synced 2024-09-29 21:21:29 +02:00
Add rate limit to ticket createion
This commit is contained in:
parent
e844c9a392
commit
3fedc84c95
@ -3,11 +3,12 @@ import urllib.parse
|
|||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from flask import render_template, request, flash, url_for, redirect
|
from flask import render_template, request, flash, url_for, redirect, g
|
||||||
from flask_login import login_required, current_user
|
from flask_login import login_required, current_user
|
||||||
from werkzeug.datastructures import FileStorage
|
from werkzeug.datastructures import FileStorage
|
||||||
|
|
||||||
from app.dashboard.base import dashboard_bp
|
from app.dashboard.base import dashboard_bp
|
||||||
|
from app.extensions import limiter
|
||||||
from app.log import LOG
|
from app.log import LOG
|
||||||
from app.models import Mailbox
|
from app.models import Mailbox
|
||||||
from app.config import ZENDESK_HOST
|
from app.config import ZENDESK_HOST
|
||||||
@ -81,6 +82,9 @@ def create_zendesk_request(email: str, content: str, files: [FileStorage]) -> bo
|
|||||||
|
|
||||||
@dashboard_bp.route("/support", methods=["POST"])
|
@dashboard_bp.route("/support", methods=["POST"])
|
||||||
@login_required
|
@login_required
|
||||||
|
@limiter.limit(
|
||||||
|
"2/hour", deduct_when=lambda r: hasattr(g, "deduct_limit") and g.deduct_limit
|
||||||
|
)
|
||||||
def process_support_dialog():
|
def process_support_dialog():
|
||||||
if not ZENDESK_HOST:
|
if not ZENDESK_HOST:
|
||||||
return render_template("dashboard/support_disabled.html")
|
return render_template("dashboard/support_disabled.html")
|
||||||
@ -92,10 +96,11 @@ def process_support_dialog():
|
|||||||
if not email:
|
if not email:
|
||||||
flash("Please add an email", "warning")
|
flash("Please add an email", "warning")
|
||||||
return render_template("dashboard/support.html", ticket_content=content)
|
return render_template("dashboard/support.html", ticket_content=content)
|
||||||
if create_zendesk_request(email, content, request.files.getlist("ticket_files")):
|
if not create_zendesk_request(
|
||||||
return render_template(
|
email, content, request.files.getlist("ticket_files")
|
||||||
"dashboard/support_ticket_created.html", ticket_email=email
|
):
|
||||||
)
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"dashboard/support.html", ticket_email=email, ticket_content=content
|
"dashboard/support.html", ticket_email=email, ticket_content=content
|
||||||
)
|
)
|
||||||
|
g.deduct_limit = True
|
||||||
|
return render_template("dashboard/support_ticket_created.html", ticket_email=email)
|
||||||
|
Loading…
Reference in New Issue
Block a user