Commit c306c20e authored by Tino Goratsch's avatar Tino Goratsch

- renamed the Model class to AbstractRepository and moved it into the ACP3\Core\Model namespace

- added  the new FloodBarrierAwareRepositoryInterface and used it for the Comments module
- reworked the FloodBarrierValidationRule
parent f0c1b820
<?php
namespace ACP3\Core\Model;
namespace ACP3\Core;
use ACP3\Core\DB;
/**
* Class Model
* @package ACP3\Core
* Class AbstractRepository
* @package ACP3\Core\Model
*/
class Model
abstract class AbstractRepository
{
/**
* The name of the default sql table
* The name of the sql table
*/
const TABLE_NAME = '';
/**
......
<?php
namespace ACP3\Core\Model;
/**
* Class FloodBarrierAwareRepositoryInterface
* @package ACP3\Core\Model
*/
interface FloodBarrierAwareRepositoryInterface
{
/**
* @param $ipAddress
*
* @return mixed
*/
public function getLastDateFromIp($ipAddress);
}
\ No newline at end of file
......@@ -7,7 +7,7 @@ use ACP3\Core\DB;
* Class NestedSetRepository
* @package ACP3\Core\NestedSet
*/
class NestedSetRepository extends \ACP3\Core\Model
class NestedSetRepository extends \ACP3\Core\Model\AbstractRepository
{
/**
* Die aktuelle Seite mit allen untergeordneten Seiten selektieren
......
<?php
namespace ACP3\Core\Validator\ValidationRules;
use ACP3\Core\Date;
use ACP3\Core\Model\FloodBarrierAwareRepositoryInterface;
/**
* Class FloodBarrierValidationRule
* @package ACP3\Core\Validator\ValidationRules
*/
class FloodBarrierValidationRule extends AbstractValidationRule
abstract class AbstractFloodBarrierValidationRule extends AbstractValidationRule
{
const NAME = 'flood_barrier';
/**
* @var \ACP3\Core\Date
*/
protected $date;
/**
* @var \ACP3\Core\Model\FloodBarrierAwareRepositoryInterface
*/
protected $repository;
/**
* FloodBarrierValidationRule constructor.
*
* @param \ACP3\Core\Date $date
* @param \ACP3\Core\Date $date
* @param \ACP3\Core\Model\FloodBarrierAwareRepositoryInterface $repository
*/
public function __construct(Date $date)
public function __construct(
Date $date,
FloodBarrierAwareRepositoryInterface $repository)
{
$this->date = $date;
$this->repository = $repository;
}
/**
......@@ -30,7 +37,8 @@ class FloodBarrierValidationRule extends AbstractValidationRule
*/
public function isValid($data, $field = '', array $extra = [])
{
$floodTime = !empty($extra['last_date']) ? $this->date->timestamp($extra['last_date'], true) + 30 : 0;
$date = $this->repository->getLastDateFromIp($extra['ip']);
$floodTime = !empty($date) ? $this->date->timestamp($date, true) + 30 : 0;
$time = $this->date->timestamp('now', true);
return $floodTime <= $time;
......
......@@ -7,12 +7,6 @@ services:
tags:
- { name: core.validator.validation_rule }
core.validator.validation_rules.flood_barrier_validation_rule:
class: ACP3\Core\Validator\ValidationRules\FloodBarrierValidationRule
arguments: [@core.date]
tags:
- { name: core.validator.validation_rule }
core.validator.validation_rules.form_token_validation_rule:
class: ACP3\Core\Validator\ValidationRules\FormTokenValidationRule
arguments: [@core.request, @core.session]
......
......@@ -7,7 +7,7 @@ use ACP3\Core;
* Class ArticleRepository
* @package ACP3\Modules\ACP3\Articles\Model
*/
class ArticleRepository extends Core\Model
class ArticleRepository extends Core\Model\AbstractRepository
{
const TABLE_NAME = 'articles';
......
......@@ -8,7 +8,7 @@ use ACP3\Core;
* Class CategoryRepository
* @package ACP3\Modules\ACP3\Categories\Model
*/
class CategoryRepository extends Core\Model
class CategoryRepository extends Core\Model\AbstractRepository
{
const TABLE_NAME = 'categories';
......
......@@ -8,7 +8,7 @@ use ACP3\Core;
* Class CommentRepository
* @package ACP3\Modules\ACP3\Comments\Model
*/
class CommentRepository extends Core\Model
class CommentRepository extends Core\Model\AbstractRepository implements Core\Model\FloodBarrierAwareRepositoryInterface
{
const TABLE_NAME = 'comments';
......
......@@ -5,6 +5,7 @@ parameters:
comments.helpers.fqdn: 'ACP3\Modules\ACP3\Comments\Helpers'
comments.model.commentrepository.fqdn: 'ACP3\Modules\ACP3\Comments\Model\CommentRepository'
comments.validator.fqdn: 'ACP3\Modules\ACP3\Comments\Validator'
comments.validator.validation_rules.flood_barrier_validation_rule.fqdn: 'ACP3\Modules\ACP3\Comments\Validator\ValidationRules\FloodBarrierValidationRule'
comments.validator.validation_rules.user_name_validation_rule.fqdn: 'ACP3\Modules\ACP3\Comments\Validator\ValidationRules\UserNameValidationRule'
comments.installer.schema.fqdn: 'ACP3\Modules\ACP3\Comments\Installer\Schema'
comments.installer.migration.fqdn: 'ACP3\Modules\ACP3\Comments\Installer\Migration'
......@@ -37,7 +38,13 @@ services:
comments.validator:
class: %comments.validator.fqdn%
arguments: ['@core.lang', @core.validator, '@core.validator.rules.misc', '@core.modules', '@comments.model.commentrepository']
arguments: ['@core.lang', @core.validator, '@core.validator.rules.misc', '@core.modules']
comments.validator.validation_rules.flood_barrier_validation_rule:
class: %comments.validator.validation_rules.flood_barrier_validation_rule.fqdn%
arguments: [@core.date, @comments.model.commentrepository]
tags:
- { name: core.validator.validation_rule }
comments.validator.validation_rules.user_name_validation_rule:
class: %comments.validator.validation_rules.user_name_validation_rule.fqdn%
......
......@@ -4,6 +4,7 @@ namespace ACP3\Modules\ACP3\Comments;
use ACP3\Core;
use ACP3\Modules\ACP3\Captcha\Validator\ValidationRules\CaptchaValidationRule;
use ACP3\Modules\ACP3\Comments\Model\CommentRepository;
use ACP3\Modules\ACP3\Comments\Validator\ValidationRules\FloodBarrierValidationRule;
/**
* Class Validator
......@@ -15,10 +16,6 @@ class Validator extends Core\Validator\AbstractValidator
* @var \ACP3\Core\Modules
*/
protected $modules;
/**
* @var \ACP3\Modules\ACP3\Comments\Model\CommentRepository
*/
protected $commentRepository;
/**
* @var \ACP3\Core\Validator\Validator
*/
......@@ -27,25 +24,22 @@ class Validator extends Core\Validator\AbstractValidator
/**
* Validator constructor.
*
* @param \ACP3\Core\Lang $lang
* @param \ACP3\Core\Validator\Validator $validator
* @param \ACP3\Core\Validator\Rules\Misc $validate
* @param \ACP3\Core\Modules $modules
* @param \ACP3\Modules\ACP3\Comments\Model\CommentRepository $commentRepository
* @param \ACP3\Core\Lang $lang
* @param \ACP3\Core\Validator\Validator $validator
* @param \ACP3\Core\Validator\Rules\Misc $validate
* @param \ACP3\Core\Modules $modules
*/
public function __construct(
Core\Lang $lang,
Core\Validator\Validator $validator,
Core\Validator\Rules\Misc $validate,
Core\Modules $modules,
CommentRepository $commentRepository
Core\Modules $modules
)
{
parent::__construct($lang, $validate);
$this->validator = $validator;
$this->modules = $modules;
$this->commentRepository = $commentRepository;
}
/**
......@@ -60,11 +54,11 @@ class Validator extends Core\Validator\AbstractValidator
$this->validator
->addConstraint(Core\Validator\ValidationRules\FormTokenValidationRule::NAME)
->addConstraint(
Core\Validator\ValidationRules\FloodBarrierValidationRule::NAME,
FloodBarrierValidationRule::NAME,
[
'message' => $this->lang->t('system', 'flood_no_entry_possible'),
'extra' => [
'last_date' => $this->commentRepository->getLastDateFromIp($ip)
'ip' => $ip
]
])
->addConstraint(
......
<?php
namespace ACP3\Modules\ACP3\Comments\Validator\ValidationRules;
use ACP3\Core\Validator\ValidationRules\AbstractFloodBarrierValidationRule;
/**
* Class FloodBarrierValidationRule
* @package ACP3\Modules\ACP3\Comments\Validator\ValidationRules
*/
class FloodBarrierValidationRule extends AbstractFloodBarrierValidationRule
{
const NAME = 'comments_flood_barrier';
}
\ No newline at end of file
......@@ -8,7 +8,7 @@ use ACP3\Core;
* Class EmoticonRepository
* @package ACP3\Modules\ACP3\Emoticons\Model
*/
class EmoticonRepository extends Core\Model
class EmoticonRepository extends Core\Model\AbstractRepository
{
const TABLE_NAME = 'emoticons';
......
......@@ -8,7 +8,7 @@ use ACP3\Core;
* Class FilesRepository
* @package ACP3\Modules\ACP3\Files\Model
*/
class FilesRepository extends Core\Model
class FilesRepository extends Core\Model\AbstractRepository
{
const TABLE_NAME = 'files';
......
......@@ -8,7 +8,7 @@ use ACP3\Core;
* Class Model
* @package ACP3\Modules\ACP3\Gallery
*/
class GalleryRepository extends Core\Model
class GalleryRepository extends Core\Model\AbstractRepository
{
const TABLE_NAME = 'gallery';
......
......@@ -7,7 +7,7 @@ use ACP3\Core;
* Class PictureRepository
* @package ACP3\Modules\ACP3\Gallery\Model
*/
class PictureRepository extends Core\Model
class PictureRepository extends Core\Model\AbstractRepository
{
const TABLE_NAME = 'gallery_pictures';
......
......@@ -8,7 +8,7 @@ use ACP3\Core;
* Class GuestbookRepository
* @package ACP3\Modules\ACP3\Guestbook\Model
*/
class GuestbookRepository extends Core\Model
class GuestbookRepository extends Core\Model\AbstractRepository
{
const TABLE_NAME = 'guestbook';
......
<?php
namespace ACP3\Modules\ACP3\Menus\Model;
use ACP3\Core\Model;
use ACP3\Core\Model\AbstractRepository;
/**
* Class MenuItemRepository
* @package ACP3\Modules\ACP3\Menus\Model
*/
class MenuItemRepository extends Model
class MenuItemRepository extends AbstractRepository
{
const TABLE_NAME = 'menu_items';
......
......@@ -7,7 +7,7 @@ use ACP3\Core;
* Class Model
* @package ACP3\Modules\ACP3\Menus
*/
class MenuRepository extends Core\Model
class MenuRepository extends Core\Model\AbstractRepository
{
const TABLE_NAME = 'menus';
......
......@@ -8,7 +8,7 @@ use ACP3\Core;
* Class NewsRepository
* @package ACP3\Modules\ACP3\News\Model
*/
class NewsRepository extends Core\Model
class NewsRepository extends Core\Model\AbstractRepository
{
const TABLE_NAME = 'news';
......
......@@ -7,7 +7,7 @@ use ACP3\Core;
* Class AccountHistoryRepository
* @package ACP3\Modules\ACP3\Newsletter\Model
*/
class AccountHistoryRepository extends Core\Model
class AccountHistoryRepository extends Core\Model\AbstractRepository
{
const TABLE_NAME = 'newsletter_account_history';
......
<?php
namespace ACP3\Modules\ACP3\Newsletter\Model;
use ACP3\Core\Model;
use ACP3\Core\Model\AbstractRepository;
use ACP3\Modules\ACP3\Newsletter\Helper\AccountStatus;
/**
* Class AccountRepository
* @package ACP3\Modules\ACP3\Newsletter\Model
*/
class AccountRepository extends Model
class AccountRepository extends AbstractRepository
{
const TABLE_NAME = 'newsletter_accounts';
......
......@@ -8,7 +8,7 @@ use ACP3\Core;
* Class NewsletterRepository
* @package ACP3\Modules\ACP3\Newsletter
*/
class NewsletterRepository extends Core\Model
class NewsletterRepository extends Core\Model\AbstractRepository
{
const TABLE_NAME = 'newsletters';
......
......@@ -7,7 +7,7 @@ use ACP3\Core;
* Class PrivilegeRepository
* @package ACP3\Modules\ACP3\Permissions\Model
*/
class PrivilegeRepository extends Core\Model
class PrivilegeRepository extends Core\Model\AbstractRepository
{
const TABLE_NAME = 'acl_privileges';
......
......@@ -7,7 +7,7 @@ use ACP3\Core;
* Class ResourceRepository
* @package ACP3\Modules\ACP3\Permissions\Model
*/
class ResourceRepository extends Core\Model
class ResourceRepository extends Core\Model\AbstractRepository
{
const TABLE_NAME = 'acl_resources';
......
......@@ -7,7 +7,7 @@ use ACP3\Core;
* Class Model
* @package ACP3\Modules\ACP3\Permissions
*/
class RoleRepository extends Core\Model
class RoleRepository extends Core\Model\AbstractRepository
{
const TABLE_NAME = 'acl_roles';
......
......@@ -7,7 +7,7 @@ use ACP3\Core;
* Class RuleRepository
* @package ACP3\Modules\ACP3\Permissions\Model
*/
class RuleRepository extends Core\Model
class RuleRepository extends Core\Model\AbstractRepository
{
const TABLE_NAME = 'acl_rules';
......
......@@ -7,7 +7,7 @@ use ACP3\Core;
* Class UserRolesRepository
* @package ACP3\Modules\ACP3\Permissions\Model
*/
class UserRoleRepository extends Core\Model
class UserRoleRepository extends Core\Model\AbstractRepository
{
const TABLE_NAME = 'acl_user_roles';
......
......@@ -7,7 +7,7 @@ use ACP3\Core;
* Class AnswerRepository
* @package ACP3\Modules\ACP3\Polls\Model
*/
class AnswerRepository extends Core\Model
class AnswerRepository extends Core\Model\AbstractRepository
{
const TABLE_NAME = 'poll_answers';
......
......@@ -8,7 +8,7 @@ use ACP3\Core;
* Class Model
* @package ACP3\Modules\ACP3\Polls
*/
class PollRepository extends Core\Model
class PollRepository extends Core\Model\AbstractRepository
{
const TABLE_NAME = 'polls';
......
......@@ -7,7 +7,7 @@ use ACP3\Core;
* Class VoteRepository
* @package ACP3\Modules\ACP3\Polls\Model
*/
class VoteRepository extends Core\Model
class VoteRepository extends Core\Model\AbstractRepository
{
const TABLE_NAME = 'poll_votes';
......
......@@ -7,7 +7,7 @@ use ACP3\Core;
* Class SeoRepository
* @package ACP3\Modules\ACP3\Seo\Model
*/
class SeoRepository extends Core\Model
class SeoRepository extends Core\Model\AbstractRepository
{
const TABLE_NAME = 'seo';
......
......@@ -7,7 +7,7 @@ use ACP3\Core;
* Class ModuleRepository
* @package ACP3\Modules\ACP3\System\Model
*/
class ModuleRepository extends Core\Model
class ModuleRepository extends Core\Model\AbstractRepository
{
const TABLE_NAME = 'modules';
......
......@@ -7,7 +7,7 @@ use ACP3\Core;
* Class SettingsRepository
* @package ACP3\Modules\ACP3\System\Model
*/
class SettingsRepository extends Core\Model
class SettingsRepository extends Core\Model\AbstractRepository
{
const TABLE_NAME = 'settings';
......
......@@ -8,7 +8,7 @@ use ACP3\Core;
* Class Model
* @package ACP3\Modules\ACP3\Users
*/
class UserRepository extends Core\Model
class UserRepository extends Core\Model\AbstractRepository
{
const TABLE_NAME = 'users';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment