diff options
author | 3dB <3db@3decibels.net> | 2009-08-04 01:03:29 -0400 |
---|---|---|
committer | 3dB <3db@3decibels.net> | 2009-08-04 01:03:29 -0400 |
commit | 8bfbcc91073690d4847ea6ca783c9d839c3ffcb6 (patch) | |
tree | 587e9595e0676f587acbd233948796bef6a37914 | |
parent | a130a4f79e04f8a6ccd4514b9a1d0285c63edfea (diff) |
Implemented double-post prevention
-- Created a subroutine to check for any recent posts made by a user
-- Added double-post checking and error messages to the form
handler & html generator
-rw-r--r-- | lib/VNDB/DB/Discussions.pm | 22 | ||||
-rw-r--r-- | lib/VNDB/Handler/Discussions.pm | 3 | ||||
-rw-r--r-- | lib/VNDB/Util/FormHTML.pm | 1 |
3 files changed, 25 insertions, 1 deletions
diff --git a/lib/VNDB/DB/Discussions.pm b/lib/VNDB/DB/Discussions.pm index 58cc5f61..eed1b2f9 100644 --- a/lib/VNDB/DB/Discussions.pm +++ b/lib/VNDB/DB/Discussions.pm @@ -5,7 +5,7 @@ use strict; use warnings; use Exporter 'import'; -our @EXPORT = qw|dbThreadGet dbThreadEdit dbThreadAdd dbPostGet dbPostEdit dbPostAdd dbThreadCount|; +our @EXPORT = qw|dbThreadGet dbThreadEdit dbThreadAdd dbPostGet dbPostEdit dbPostAdd dbThreadCount dbPostCheckDouble|; # Options: id, type, iid, results, page, what, notusers @@ -241,5 +241,25 @@ sub dbPostAdd { } +# Checks if a user has recently made a post in a particular thread +# If tid is omitted or equal to zero, check if user has made a recent post at all +# uid, tid (optional) +sub dbPostCheckDouble { + my($self, @o) = @_; + + my $time = time - 30; # 30 Seconds + my $r; + if (defined $o[1] && $o[1] ne 0) { + $r = $self->dbRow('SELECT COUNT(num) FROM threads_posts WHERE uid = ? AND tid = ? AND date > ? LIMIT 1', + @o, $time); + } else { + $r = $self->dbRow('SELECT COUNT(num) FROM threads_posts WHERE uid = ? AND date > ? LIMIT 1', + $o[0], $time); + } + + return $r->{count}||0; +} + + 1; diff --git a/lib/VNDB/Handler/Discussions.pm b/lib/VNDB/Handler/Discussions.pm index eff8212e..dce8dcde 100644 --- a/lib/VNDB/Handler/Discussions.pm +++ b/lib/VNDB/Handler/Discussions.pm @@ -166,6 +166,9 @@ sub edit { { name => 'msg', maxlenght => 5000 }, ); + # check for double-posting + push @{$frm->{_err}}, 'doublepost' if $self->dbPostCheckDouble($self->{_auth}{id}, $tid); + # parse and validate the boards my @boards; if(!$frm->{_err} && $frm->{boards}) { diff --git a/lib/VNDB/Util/FormHTML.pm b/lib/VNDB/Util/FormHTML.pm index dfb9a91f..f8047c4c 100644 --- a/lib/VNDB/Util/FormHTML.pm +++ b/lib/VNDB/Util/FormHTML.pm @@ -54,6 +54,7 @@ my %formerr_exeptions = ( toolarge => 'Image is too large, only 500kB allowed', oneaday => 'You can only register one account from the same IP within 24 hours', nochanges => 'No changes, please don\'t create an entry that is fully -identical- to another', + doublepost => 'Please wait 30 seconds before making another post', ); |