Skip to content
This repository has been archived by the owner on Mar 30, 2024. It is now read-only.

Commit

Permalink
fixed #8
Browse files Browse the repository at this point in the history
  • Loading branch information
kimbtech committed Nov 17, 2018
1 parent 0f7c463 commit f7166be
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
5 changes: 1 addition & 4 deletions core/Poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,7 @@ public function saveSendData( $template ){
return true;
}
else{
$alert = new Template( 'alert' );
$template->includeTemplate($alert);
$alert->setContent( 'ALERTMESSAGE', $capok ? LanguageManager::getTranslation('EinwillErr') : Captcha::getError() );

$this->error = $capok ? LanguageManager::getTranslation('EinwillErr') : Captcha::getError();
return false;
}
}
Expand Down
27 changes: 27 additions & 0 deletions core/api/Captcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ class Captcha{
*/
const SESSION_POST_NAME = 'CAPTCHA_STRING';

/**
* The name of the session for already checked users
*/
const SESSION_OK_NAME = 'CAPTCHA_LAST_OK';

/**
* How long does a solved captcha live?
* (seconds)
*/
const LAST_SOLVED_TIMEOUT = 600;

/**
* When show a new one?
* (should be smaller than LAST_SOLVED_TIMEOUT, seconds)
*/
const LAST_SOLVED_NEW = 90;

/**
* The string, displayed in the captcha
*/
Expand Down Expand Up @@ -89,6 +106,10 @@ public static function showImage(){
* Getting the HTML for the captcha
*/
public static function getCaptchaHTML(){
if( !empty( $_SESSION[self::SESSION_OK_NAME] ) && $_SESSION[self::SESSION_OK_NAME] - self::LAST_SOLVED_NEW >= time() ){
//user has already solved a captcha, no new one
return '';
}
return Utilities::getRowHtml(
'<img title="'.LanguageManager::getTranslation('CaptTitle').'" src="'. URL::generateAPILink('captcha', ['time' => time()]) .'" onclick="this.src=\''.URL::generateAPILink('captcha').'&r=\'+Math.random();">',
'<input type="text" name="'. self::SESSION_POST_NAME .'" placeholder="Captcha" class="form-control nolocalsave">'
Expand All @@ -101,11 +122,17 @@ public static function getCaptchaHTML(){
* default self::USE_POST, the post param by getCaptchaHTML()
*/
public static function checkImageData( $string = self::USE_POST ){
if( !empty( $_SESSION[self::SESSION_OK_NAME] ) && $_SESSION[self::SESSION_OK_NAME] >= time() ){
//user has already solved a captcha, no new one
return true;
}
if( $string === self::USE_POST ){
$string = $_POST[self::SESSION_POST_NAME];
}
if( !empty( $_SESSION[self::SESSION_POST_NAME] ) && !empty( $string ) ){
if( $_SESSION[self::SESSION_POST_NAME] == $string ){
//now user has solved one, set valid until:
$_SESSION[self::SESSION_OK_NAME] = time() + self::LAST_SOLVED_TIMEOUT;
return true;
}
else{
Expand Down
2 changes: 1 addition & 1 deletion data/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
"textPoll": "Ich bin mit den Datenschutzrichlinien ... einverstanden!",
"textNew": "Ich bin mit den AGB des Anbieters einverstanden!"
},
"version": "1.0.3alpha"
"version": "1.0.4alpha"
}
6 changes: 3 additions & 3 deletions load/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ function template_new(){
$("input[name=formtype][value="+ data.formtype +"]").prop('checked', true)
personMeetingUpdate();

$("input[type=text]").each((k,v) => {
$("input[type=text]:not(.nolocalsave)").each((k,v) => {
$( v ).val( data["inputsText"][k] );
});
$("input[type=number]").each((k,v) => {
$("input[type=number]:not(.nolocalsave)").each((k,v) => {
$( v ).val( data["inputsNum"][k] );
});
$("textarea").each((k,v) => {
$("textarea:not(.nolocalsave)").each((k,v) => {
$( v ).val( data["textAr"][k] );
});
}
Expand Down

0 comments on commit f7166be

Please sign in to comment.