Skip to content

Commit

Permalink
fix modal, refactor captcha
Browse files Browse the repository at this point in the history
  • Loading branch information
mzhelskiy committed Jan 25, 2014
1 parent ce32f1e commit dead633
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ class ModuleValidate_EntityValidatorCaptcha extends ModuleValidate_EntityValidat
* @var bool
*/
public $allowEmpty=false;
/**
* Название каптчи для возможности создавать несколько независимых каптч на странице
*
* @var string
*/
public $name='';

/**
* Запуск валидации
Expand All @@ -44,7 +50,8 @@ public function validate($sValue) {
return true;
}

if (!isset($_SESSION['captcha_keystring']) or $_SESSION['captcha_keystring']!=strtolower($sValue)) {
$sSessionName='captcha_keystring'.($this->name ? '_'.$this->name : '');
if (!isset($_SESSION[$sSessionName]) or $_SESSION[$sSessionName]!=strtolower($sValue)) {
return $this->getMessage($this->Lang_Get('validate_captcha_not_valid',null,false),'msg');
}
return true;
Expand Down
1 change: 1 addition & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@
"___path.framework.frontend.web___/js/ui/autocomplete.js",
"___path.framework.frontend.web___/js/ui/notification.js",
"___path.framework.frontend.web___/js/ui/alert.js",
"___path.framework.frontend.web___/js/ui/captcha.js",
);

$config['head']['default']['css'] = array(
Expand Down
67 changes: 67 additions & 0 deletions frontend/framework/js/ui/captcha.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* Captcha
*
* @module captcha
*
* @license GNU General Public License, version 2
* @copyright 2013 OOO "ЛС-СОФТ" {@link http://livestreetcms.com}
* @author Denis Shakhov <denis.shakhov@gmail.com>
*/

(function($) {
"use strict";

var _selectors = {
// Элемент с каптчей
captcha: '[data-type=captcha]'
};

$.widget( "livestreet.captcha", {
/**
* Дефолтные опции
*/
options: {
name: ''
},

/**
* Конструктор
*
* @constructor
* @private
*/
_create: function() {
this.options = $.extend({}, this.options, ls.utilities.getDataOptions(this.element, 'captcha'));

this._on({
click: function (e) {
this.update();
e.preventDefault();
}
});
},

/**
* Получает url каптчи
*/
getUrl: function () {
return PATH_FRAMEWORK_LIBS_VENDOR + '/kcaptcha/index.php?' + SESSION_NAME + '=' + SESSION_ID + '&n=' + Math.random()+'&name='+this.options.name;
},

/**
* Обновляет каптчу
*/
update: function () {
this.element.css('background-image', 'url(' + this.getUrl() + ')');
}
});

// Инициализация
$(document).on('ready', function (e) {
$(document).on('click', '[data-type=captcha]', function (e) {
$(this).captcha();
$(this).captcha('update');
e.preventDefault();
});
});
})(jQuery);
7 changes: 4 additions & 3 deletions frontend/framework/js/ui/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ var ls = ls || {};
if (result.bStateError) {
_loader.hide();
_overlay.hide();
//ls.msg.error('Error', result.sMsg);
ls.msg.error('Error', result.sMsg);
} else {
_loader.hide();
$( $.trim( result['sText'] ) ).modal( options ).modal('show');
Expand All @@ -305,7 +305,7 @@ var ls = ls || {};
error: function () {
_loader.hide();
_overlay.hide();
//ls.msg.error('Error', result.sMsg);
ls.msg.error('Error');
}
});
};
Expand Down Expand Up @@ -358,7 +358,8 @@ var ls = ls || {};
var options = ls.utilities.getDataOptions($(this), 'modal');
var params = ls.utilities.getDataOptions($(this), 'param') || {};

ls.modal.load(options.url, options.params, options);
ls.modal.load(options.url, params, options);
e.preventDefault();
});
});

Expand Down
1 change: 1 addition & 0 deletions frontend/framework/js/vendor/parsley/parsley.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
value: val
}
};
data.params=ls.utilities.getDataOptions(self.$element, 'remoteParam') || {};

data.security_ls_key = LIVESTREET_SECURITY_KEY;
/* @livestreet end */
Expand Down
11 changes: 6 additions & 5 deletions libs/vendor/kcaptcha/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@
}
}

$captcha = new KCAPTCHA();


$_SESSION['captcha_keystring'] = $captcha->getKeyString();
$name='';
if (isset($_GET['name']) and is_string($_GET['name']) and $_GET['name']) {
$name=$_GET['name'];
}

$captcha = new KCAPTCHA();

?>
$_SESSION['captcha_keystring'.($name ? '_'.$name : '')] = $captcha->getKeyString();

0 comments on commit dead633

Please sign in to comment.