summaryrefslogtreecommitdiff
path: root/extensions/FunnyQuestion
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2010-09-18 17:43:34 +0200
committerPierre Schmitz <pierre@archlinux.de>2010-09-18 17:43:34 +0200
commit494e797fd6857f9a71bd5da7b53a1754500332fd (patch)
tree9c0cbef2e730ef776c9fe2db38b1375dc7a1454f /extensions/FunnyQuestion
parent1af011759fbfe2003273e859440e0d3bc211e528 (diff)
FunnyQuestion: Remeber if user has passed this test
Diffstat (limited to 'extensions/FunnyQuestion')
-rw-r--r--extensions/FunnyQuestion/FunnyQuestion.body.php33
-rw-r--r--extensions/FunnyQuestion/FunnyQuestion.php3
2 files changed, 30 insertions, 6 deletions
diff --git a/extensions/FunnyQuestion/FunnyQuestion.body.php b/extensions/FunnyQuestion/FunnyQuestion.body.php
index 04d25f8d..2bfb9343 100644
--- a/extensions/FunnyQuestion/FunnyQuestion.body.php
+++ b/extensions/FunnyQuestion/FunnyQuestion.body.php
@@ -24,9 +24,29 @@ class FunnyQuestion {
return array('question' => $question, 'time' => $time, 'hash' => $hash);
}
+ private static function setFunnyCookie() {
+ global $wgFunnyQuestionHash, $wgFunnyQuestionRemember, $wgRequest;
+
+ $time = time();
+ $wgRequest->response()->setcookie('FunnyQuestionHash', sha1($time.wfGetIP().$wgFunnyQuestionHash), $time+$wgFunnyQuestionRemember);
+ $wgRequest->response()->setcookie('FunnyQuestionTime', $time, $time+$wgFunnyQuestionRemember);
+ }
+
+ private static function hasFunnyCookie() {
+ global $wgFunnyQuestionHash, $wgFunnyQuestionRemember, $wgCookiePrefix;
+
+ return (!empty($_COOKIE[$wgCookiePrefix.'FunnyQuestionHash']) && !empty($_COOKIE[$wgCookiePrefix.'FunnyQuestionTime'])
+ && time() - $wgFunnyQuestionRemember <= $_COOKIE[$wgCookiePrefix.'FunnyQuestionTime']
+ && sha1($_COOKIE[$wgCookiePrefix.'FunnyQuestionTime']. wfGetIP().$wgFunnyQuestionHash) == $_COOKIE[$wgCookiePrefix.'FunnyQuestionHash']);
+ }
+
private static function checkFunnyQuestion() {
global $wgFunnyQuestionHash, $wgFunnyQuestions, $wgFunnyQuestionTimeout, $wgFunnyQuestionWait;
+ if (self::hasFunnyCookie()) {
+ return true;
+ }
+
if (!empty($_POST['FunnyQuestionTime'])
&& !empty($_POST['FunnyQuestionHash'])
&& !empty($_POST['FunnyAnswer'])) {
@@ -51,6 +71,7 @@ class FunnyQuestion {
foreach ($answers as $answer) {
if (self::normalizeAnswer($answer) == $userAnswer
&& $hash == sha1($time.$question.$wgFunnyQuestionHash)) {
+ self::setFunnyCookie();
return true;
}
}
@@ -62,7 +83,7 @@ class FunnyQuestion {
public static function addFunnyQuestionToEditPage($editpage, $output) {
global $wgUser;
- if (!$wgUser->isLoggedIn()) {
+ if (!$wgUser->isLoggedIn() && !self::hasFunnyCookie()) {
$funnyQuestion = self::getFunnyQuestion();
$editpage->editFormTextAfterWarn .=
'<div class="editOptions">
@@ -86,10 +107,12 @@ class FunnyQuestion {
}
public static function addFunnyQuestionToUserCreateForm($template) {
- $funnyQuestion = self::getFunnyQuestion();
- $template->addInputItem('FunnyAnswer', '', 'text', 'question-label', 'question-'.sha1($funnyQuestion['question']));
- $template->addInputItem('FunnyQuestionTime', $funnyQuestion['time'], 'hidden', '');
- $template->addInputItem('FunnyQuestionHash', $funnyQuestion['hash'], 'hidden', '');
+ if (!self::hasFunnyCookie()) {
+ $funnyQuestion = self::getFunnyQuestion();
+ $template->addInputItem('FunnyAnswer', '', 'text', 'question-label', 'question-'.sha1($funnyQuestion['question']));
+ $template->addInputItem('FunnyQuestionTime', $funnyQuestion['time'], 'hidden', '');
+ $template->addInputItem('FunnyQuestionHash', $funnyQuestion['hash'], 'hidden', '');
+ }
return true;
}
diff --git a/extensions/FunnyQuestion/FunnyQuestion.php b/extensions/FunnyQuestion/FunnyQuestion.php
index 5dcc367c..907d070a 100644
--- a/extensions/FunnyQuestion/FunnyQuestion.php
+++ b/extensions/FunnyQuestion/FunnyQuestion.php
@@ -2,7 +2,7 @@
$wgExtensionCredits['other'][] = array(
'name' => 'FunnyQuestion',
- 'version' => '2.0',
+ 'version' => '2.1',
'description' => 'Challenge-response authentication',
'author' => 'Pierre Schmitz',
'url' => 'https://www.archlinux.de'
@@ -15,6 +15,7 @@ $wgFunnyQuestions = array(
$wgFunnyQuestionHash = '';
$wgFunnyQuestionTimeout = 3600;
$wgFunnyQuestionWait = 2;
+$wgFunnyQuestionRemember = 3600*24;
$wgAutoloadClasses['FunnyQuestion'] = dirname(__FILE__) . '/FunnyQuestion.body.php';
$wgExtensionMessagesFiles['FunnyQuestion'] = dirname( __FILE__ ) . '/FunnyQuestion.i18n.php';