From b08b81fec937fd87d9ff042077fa8ca697e2c630 Mon Sep 17 00:00:00 2001 From: ComputerTech312 Date: Sat, 20 Sep 2025 20:44:30 +0100 Subject: [PATCH] Fix quote submission bug and update copyright notice MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fixed config access in submit route (config.min_quote_length -> config.get('quotes.min_length')) - Fixed Flask-Limiter initialization syntax - Reduced minimum quote length from 10 to 1 character - Updated copyright notice from '© ircquotes 2024, All Rights Reserved.' to '@ ircquotes 2024-2025' - Quote submission now works properly with correct status assignment (pending/approved) - Quotes are properly created with status=0 (pending) when auto_approve=false --- app.py | 31 ++++++++++++++++++++++++++----- config.json | 4 ++-- instance/quotes.db | Bin 6447104 -> 6447104 bytes templates/browse.html | 2 +- templates/index.html | 2 +- templates/login.html | 2 +- templates/quote.html | 2 +- templates/random.html | 2 +- templates/search.html | 2 +- templates/submit.html | 2 +- 10 files changed, 35 insertions(+), 14 deletions(-) diff --git a/app.py b/app.py index 4c2b06e..779c7ea 100644 --- a/app.py +++ b/app.py @@ -89,7 +89,10 @@ csrf.exempt('search_quotes') csrf.exempt('get_stats') # Initialize rate limiter with custom IP detection -limiter = Limiter(app, key_func=get_real_ip) +limiter = Limiter( + key_func=get_real_ip, + app=app +) db = SQLAlchemy(app) @@ -164,8 +167,8 @@ def submit(): # Input validation and length limits from config quote_text = quote_text.strip() - min_length = config.min_quote_length - max_length = config.max_quote_length + min_length = config.get('quotes.min_length', 10) + max_length = config.get('quotes.max_length', 5000) if len(quote_text) < min_length: flash(f"Your quote is too short. Please enter at least {min_length} characters.", 'error') @@ -184,14 +187,32 @@ def submit(): ip_address = get_real_ip() # Get the real user's IP address user_agent = request.headers.get('User-Agent') # Get the user's browser info - new_quote = Quote(text=quote_text, ip_address=ip_address, user_agent=user_agent) + # Determine initial status based on config + auto_approve = config.get('quotes.auto_approve', False) + initial_status = 1 if auto_approve else 0 # 1 = approved, 0 = pending + + new_quote = Quote( + text=quote_text, + ip_address=ip_address, + user_agent=user_agent, + status=initial_status + ) try: db.session.add(new_quote) db.session.commit() - flash("Thanks! Your quote has been submitted and is awaiting approval by our moderators.", 'success') + + # Log the quote creation for debugging + if config.get('logging.level') == 'DEBUG': + print(f"Quote created: ID={new_quote.id}, Status={new_quote.status}, Text='{quote_text[:50]}...'") + + if auto_approve: + flash("Thanks! Your quote has been submitted and automatically approved.", 'success') + else: + flash("Thanks! Your quote has been submitted and is awaiting approval by our moderators.", 'success') except Exception as e: db.session.rollback() + print(f"Error submitting quote: {e}") # Always log errors flash("Sorry, something went wrong while submitting your quote. Please try again in a moment.", 'error') return redirect(url_for('index')) diff --git a/config.json b/config.json index c240550..84a8ce9 100644 --- a/config.json +++ b/config.json @@ -59,7 +59,7 @@ "password_hash": "$argon2i$v=19$m=65536,t=4,p=1$cWZDc1pQaUJLTUJoaVI4cw$kn8XKz6AEZi8ebXfyyZuzommSypliVFrsGqzOyUEIHA" }, "quotes": { - "min_length": 10, + "min_length": 1, "max_length": 5000, "per_page": 25, "auto_approve": false, @@ -74,7 +74,7 @@ "bulk_moderation_enabled": true }, "logging": { - "level": "WARNING", + "level": "DEBUG", "format": "%(asctime)s [%(levelname)s] %(message)s" } } \ No newline at end of file diff --git a/instance/quotes.db b/instance/quotes.db index d97b86ca1eab3276803bdd5eb95d0a621c0ae4e4..971da4df43d4f2a57ff319e9ecd2e8fbc89353ee 100644 GIT binary patch delta 762 zcmXxhJxmjE7zXhFUFm)Fj`l!4q=0Qjtf+h{SU`nRgeum8mKG>tTM%Tygpe5H!ogpQ z(Lv*IhKYfVG?+@f!37h-U;q~xG!707vS`xpbp$$gZeEH%&! zYNQXqrH0Dm8X@bt+u!?ZG}SJmo8cvV}y8iv>1+o4ea26 z<4^)8pj6L}p8T~}%8okS6yW@VotxIH=W_qDdh=Xviq)zjOq-$(sq=Rw@<4QpC2GhmXpeeh l2bKQVuXHPmR;u&EGI=5ihXdgkmm75&ifuD`cVBG5_z&%#6D$A# delta 728 zcmXZZJ4{ny7{>AMoN`Xjr8f{Q6v0-&iWhFmrFg-LKt*Z+3q^|1Rx2SI1~E}L3a=J} zs~$t*#wLW=5WmF%6T(E@9MFZq(P-@=F2={e@LS&L`RAQke{P!jj|39QLiOu=*sN!7 zhmnkV7mR_&E~l{*_m-KOe7^Kn!VAZt22Q|9I0dJn7V4lL8lVx*z*%U5W@v#{@bRrg zTY3d8VaGW*4;SDfw8JIv!)54zE6@pD(9Oe+Kqgc%&Fqb~ht~I&O?^}Qp~jSXb5{N; zD^kCZ7y4ehOF}#u4@}C|sXuM#n%wV7#R99wyO|NEu{sebGqtv~q_YzNxC%XR4SFF6 z*C7Ob&<_J}1Hv!}LlA*sxCtXXI}!EGm)>FeqV_}`R5Ip({6P9HbrmE{Z^V1d@VKQ; z{^?irn{1y=rWT7eMv=W`d^#763hB&l6h`3|jKMg>cxE>qij?A^irL3(Q`Qa3YyFG% zTMMiA%|3aKd)9l~WurbO>^P`4wRBf!&veDFR;D6;-Y}e~5^c9rOG%AA+CLiOLy2u3 J9!V@q{{Y|p0}KEF diff --git a/templates/browse.html b/templates/browse.html index 705d12d..4898630 100644 --- a/templates/browse.html +++ b/templates/browse.html @@ -111,7 +111,7 @@ Hosted by YourHostingProvider
- © ircquotes 2024, All Rights Reserved. + @ ircquotes 2024-2025
diff --git a/templates/index.html b/templates/index.html index fdf229a..ba6ca31 100644 --- a/templates/index.html +++ b/templates/index.html @@ -85,7 +85,7 @@ -
© ircquotes 2024, All Rights Reserved.
+
@ ircquotes 2024-2025
diff --git a/templates/login.html b/templates/login.html index 75a0bd4..2924527 100644 --- a/templates/login.html +++ b/templates/login.html @@ -93,7 +93,7 @@ - © ircquotes 2024, All Rights Reserved. + @ ircquotes 2024-2025 diff --git a/templates/quote.html b/templates/quote.html index 6cae77f..2c9b089 100644 --- a/templates/quote.html +++ b/templates/quote.html @@ -95,7 +95,7 @@ - © ircquotes 2024, All Rights Reserved. + @ ircquotes 2024-2025 diff --git a/templates/random.html b/templates/random.html index 064ea3c..4607ad8 100644 --- a/templates/random.html +++ b/templates/random.html @@ -91,7 +91,7 @@ - © ircquotes 2024, All Rights Reserved. + @ ircquotes 2024-2025 diff --git a/templates/search.html b/templates/search.html index fe20c78..4860a21 100644 --- a/templates/search.html +++ b/templates/search.html @@ -129,7 +129,7 @@ Hosted by YourHostingProvider
- © ircquotes 2024, All Rights Reserved. + @ ircquotes 2024-2025
diff --git a/templates/submit.html b/templates/submit.html index d5dc669..9d6ed31 100644 --- a/templates/submit.html +++ b/templates/submit.html @@ -91,7 +91,7 @@ - © ircquotes 2024, All Rights Reserved. + @ ircquotes 2024-2025