Author | zPlus <zplus@peers.community> 2018-07-28 05:53:07 |
Committer | zPlus <zplus@peers.community> 2018-07-28 05:53:07 |
Commit | f671cdf (patch) |
Tree | 8a2e5b8 |
Parent(s) |
-rwxr-xr-x | freepost/__init__.py | 19 | ||
-rw-r--r-- | freepost/database.py | 6 |
index d30ca8e..23d9b2a | |||
old size: 25K - new size: 25K | |||
@@ -506,16 +506,23 @@ def post_thread (hash_id): | |||
506 | 506 | @requires_login | |
507 | 507 | @post ('/post/<hash_id>') | |
508 | 508 | def new_comment (hash_id): | |
509 | - | user = session.user () | |
510 | - | ||
511 | 509 | # The comment text | |
512 | 510 | comment = request.forms.getunicode ('new_comment').strip () | |
513 | 511 | ||
514 | - | # Empty comment | |
512 | + | # Empty comment? | |
515 | 513 | if len (comment) == 0: | |
516 | 514 | redirect (application.get_url ('post', hash_id=hash_id)) | |
517 | 515 | ||
518 | - | comment_hash_id = database.new_comment (comment, hash_id, user['id']) | |
516 | + | # Retrieve the post | |
517 | + | post = database.get_post (hash_id) | |
518 | + | ||
519 | + | # Does post exist? | |
520 | + | if not post: | |
521 | + | redirect (application.get_url ('homepage')) | |
522 | + | ||
523 | + | user = session.user () | |
524 | + | ||
525 | + | comment_hash_id = database.new_comment (comment, hash_id, user['id'], post['userId']) | |
519 | 526 | ||
520 | 527 | # Retrieve new comment | |
521 | 528 | comment = database.get_comment (comment_hash_id) | |
@@ -679,7 +686,9 @@ def reply_check (hash_id): | |||
679 | 686 | redirect (application.get_url ('post', hash_id=comment['postHashId'])) | |
680 | 687 | ||
681 | 688 | # We have a text, add the reply and redirect to the new reply | |
682 | - | reply_hash_id = database.new_comment (text, comment['postHashId'], user['id'], comment['id']) | |
689 | + | reply_hash_id = database.new_comment ( | |
690 | + | text, comment['postHashId'], user['id'], | |
691 | + | comment['userId'], comment['id']) | |
683 | 692 | ||
684 | 693 | # Retrieve new comment | |
685 | 694 | comment = database.get_comment (reply_hash_id) |
index 64aeb1a..b5ecd1a | |||
old size: 18K - new size: 18K | |||
@@ -440,7 +440,7 @@ def get_post_comments (post_id, session_user_id = None): | |||
440 | 440 | return cursor.fetchall () | |
441 | 441 | ||
442 | 442 | # Submit a new comment to a post | |
443 | - | def new_comment (comment_text, post_hash_id, user_id, parent_comment_id = None): | |
443 | + | def new_comment (comment_text, post_hash_id, user_id, parent_user_id = None, parent_comment_id = None): | |
444 | 444 | # Create a hash_id for the new comment | |
445 | 445 | hash_id = random.alphanumeric_string (10) | |
446 | 446 | ||
@@ -451,7 +451,7 @@ def new_comment (comment_text, post_hash_id, user_id, parent_comment_id = None): | |||
451 | 451 | ||
452 | 452 | cursor.execute ( | |
453 | 453 | """ | |
454 | - | INSERT INTO comment (hashId, created, dateCreated, `read`, `text`, `vote`, | |
454 | + | INSERT INTO comment (hashId, created, dateCreated, `read`, text, vote, | |
455 | 455 | parentId, parentUserId, postId, userId) | |
456 | 456 | VALUES (%(hash_id)s, NOW(), CURDATE(), 0, %(text)s, 0, %(parent_id)s, | |
457 | 457 | %(parent_user_id)s, %(post_id)s, %(user)s) | |
@@ -460,7 +460,7 @@ def new_comment (comment_text, post_hash_id, user_id, parent_comment_id = None): | |||
460 | 460 | 'hash_id': hash_id, | |
461 | 461 | 'text': comment_text, | |
462 | 462 | 'parent_id': parent_comment_id, | |
463 | - | 'parent_user_id': post['userId'], | |
463 | + | 'parent_user_id': parent_user_id, | |
464 | 464 | 'post_id': post['id'], | |
465 | 465 | 'user': user_id | |
466 | 466 | } |