Fix quote submission bug and update copyright notice
- 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
This commit is contained in:
31
app.py
31
app.py
@@ -89,7 +89,10 @@ csrf.exempt('search_quotes')
|
|||||||
csrf.exempt('get_stats')
|
csrf.exempt('get_stats')
|
||||||
|
|
||||||
# Initialize rate limiter with custom IP detection
|
# 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)
|
db = SQLAlchemy(app)
|
||||||
|
|
||||||
@@ -164,8 +167,8 @@ def submit():
|
|||||||
|
|
||||||
# Input validation and length limits from config
|
# Input validation and length limits from config
|
||||||
quote_text = quote_text.strip()
|
quote_text = quote_text.strip()
|
||||||
min_length = config.min_quote_length
|
min_length = config.get('quotes.min_length', 10)
|
||||||
max_length = config.max_quote_length
|
max_length = config.get('quotes.max_length', 5000)
|
||||||
|
|
||||||
if len(quote_text) < min_length:
|
if len(quote_text) < min_length:
|
||||||
flash(f"Your quote is too short. Please enter at least {min_length} characters.", 'error')
|
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
|
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
|
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:
|
try:
|
||||||
db.session.add(new_quote)
|
db.session.add(new_quote)
|
||||||
db.session.commit()
|
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:
|
except Exception as e:
|
||||||
db.session.rollback()
|
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')
|
flash("Sorry, something went wrong while submitting your quote. Please try again in a moment.", 'error')
|
||||||
|
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
|
|||||||
@@ -59,7 +59,7 @@
|
|||||||
"password_hash": "$argon2i$v=19$m=65536,t=4,p=1$cWZDc1pQaUJLTUJoaVI4cw$kn8XKz6AEZi8ebXfyyZuzommSypliVFrsGqzOyUEIHA"
|
"password_hash": "$argon2i$v=19$m=65536,t=4,p=1$cWZDc1pQaUJLTUJoaVI4cw$kn8XKz6AEZi8ebXfyyZuzommSypliVFrsGqzOyUEIHA"
|
||||||
},
|
},
|
||||||
"quotes": {
|
"quotes": {
|
||||||
"min_length": 10,
|
"min_length": 1,
|
||||||
"max_length": 5000,
|
"max_length": 5000,
|
||||||
"per_page": 25,
|
"per_page": 25,
|
||||||
"auto_approve": false,
|
"auto_approve": false,
|
||||||
@@ -74,7 +74,7 @@
|
|||||||
"bulk_moderation_enabled": true
|
"bulk_moderation_enabled": true
|
||||||
},
|
},
|
||||||
"logging": {
|
"logging": {
|
||||||
"level": "WARNING",
|
"level": "DEBUG",
|
||||||
"format": "%(asctime)s [%(levelname)s] %(message)s"
|
"format": "%(asctime)s [%(levelname)s] %(message)s"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Binary file not shown.
@@ -111,7 +111,7 @@
|
|||||||
|
|
||||||
<font size="-1">
|
<font size="-1">
|
||||||
<a href="#">Hosted by YourHostingProvider</a><br>
|
<a href="#">Hosted by YourHostingProvider</a><br>
|
||||||
© ircquotes 2024, All Rights Reserved.
|
@ ircquotes 2024-2025
|
||||||
</font>
|
</font>
|
||||||
</center>
|
</center>
|
||||||
|
|
||||||
|
|||||||
@@ -85,7 +85,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<font size="-1"><a href="#"></a><br>© ircquotes 2024, All Rights Reserved.</font>
|
<font size="-1"><a href="#"></a><br>@ ircquotes 2024-2025</font>
|
||||||
</center>
|
</center>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -93,7 +93,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<font size="-1">© ircquotes 2024, All Rights Reserved.</font>
|
<font size="-1">@ ircquotes 2024-2025</font>
|
||||||
</center>
|
</center>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -95,7 +95,7 @@
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
<font size="-1">
|
<font size="-1">
|
||||||
© ircquotes 2024, All Rights Reserved.
|
@ ircquotes 2024-2025
|
||||||
</font>
|
</font>
|
||||||
</center>
|
</center>
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,7 @@
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
<font size="-1">
|
<font size="-1">
|
||||||
© ircquotes 2024, All Rights Reserved.
|
@ ircquotes 2024-2025
|
||||||
</font>
|
</font>
|
||||||
</center>
|
</center>
|
||||||
|
|
||||||
|
|||||||
@@ -129,7 +129,7 @@
|
|||||||
|
|
||||||
<font size="-1">
|
<font size="-1">
|
||||||
<a href="#">Hosted by YourHostingProvider</a><br>
|
<a href="#">Hosted by YourHostingProvider</a><br>
|
||||||
© ircquotes 2024, All Rights Reserved.
|
@ ircquotes 2024-2025
|
||||||
</font>
|
</font>
|
||||||
</center>
|
</center>
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,7 @@
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
<font size="-1">
|
<font size="-1">
|
||||||
© ircquotes 2024, All Rights Reserved.
|
@ ircquotes 2024-2025
|
||||||
</font>
|
</font>
|
||||||
</center>
|
</center>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user