Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
fix(Register): Add captcha checker
Browse files Browse the repository at this point in the history
1. Rename some site_config key name
2. Add Captcha Check in UserRegisterForm
  • Loading branch information
Rhilip committed Jun 4, 2019
1 parent 21dca47 commit bacee6d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
18 changes: 13 additions & 5 deletions apps/models/form/UserRegisterForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@

use Rid\Helpers\StringHelper;
use Rid\Validators\Validator;
use Rid\Validators\CaptchaTrait;

class UserRegisterForm extends Validator
{
use CaptchaTrait;

public $id;

public $username;
Expand Down Expand Up @@ -91,7 +94,12 @@ public static function inputRules()

public static function callbackRules()
{
return ['isRegisterSystemOpen', 'isMaxUserReached', 'isMaxRegisterIpReached', 'isValidUsername', 'isValidEmail', 'checkRegisterType'];
return [
'validateCaptcha',
'isRegisterSystemOpen', 'isMaxUserReached', 'isMaxRegisterIpReached',
'isValidUsername', 'isValidEmail',
'checkRegisterType'
];
}

protected function isRegisterSystemOpen()
Expand All @@ -109,14 +117,14 @@ protected function isRegisterSystemOpen()

protected function isMaxUserReached()
{
if (app()->config->get('register.max_user_check') &&
if (app()->config->get('register.check_max_user') &&
Site::fetchUserCount() >= app()->config->get('base.max_user'))
$this->buildCallbackFailMsg('MaxUserReached','Max user limit Reached');
}

public function isMaxRegisterIpReached()
{
if (app()->config->get("register.max_ip_check")) {
if (app()->config->get("register.check_max_ip")) {
$client_ip = app()->request->getClientIp();

$max_user_per_ip = app()->config->get("register.per_ip_user") ?: 5;
Expand Down Expand Up @@ -152,15 +160,15 @@ public function isValidEmail()
{
$email = $this->email;
$email_suffix = substr($email, strpos($email, '@')); // Will get `@test.com` as example
if (app()->config->get("register.enabled_email_black_list") &&
if (app()->config->get("register.check_email_blacklist") &&
app()->config->get("register.email_black_list")) {
$email_black_list = explode(",", app()->config->get("register.email_black_list"));
if (in_array($email_suffix, $email_black_list)) {
$this->buildCallbackFailMsg('ValidEmail', "The email suffix `$email_suffix` is not allowed.");
return;
}
}
if (app()->config->get("register.enabled_email_white_list") &&
if (app()->config->get("register.check_email_whitelist") &&
app()->config->get("register.email_white_list")) {
$email_white_list = explode(",", app()->config->get("register.email_white_list"));
if (!in_array($email_suffix, $email_white_list)) {
Expand Down
25 changes: 7 additions & 18 deletions migration/ridpt.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: May 31, 2019 at 09:48 PM
-- Generation Time: Jun 04, 2019 at 03:00 PM
-- Server version: 8.0.16
-- PHP Version: 7.3.5
-- PHP Version: 7.3.6

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
Expand Down Expand Up @@ -384,6 +384,7 @@ INSERT INTO `site_config` (`name`, `value`) VALUES
('base.enable_extend_debug', '1'),
('base.enable_register_system', '1'),
('base.enable_tracker_system', '1'),
('base.max_news_sum', '5'),
('base.max_per_user_session', '10'),
('base.max_user', '5000'),
('base.site_author', 'Rhilip'),
Expand Down Expand Up @@ -412,12 +413,12 @@ INSERT INTO `site_config` (`name`, `value`) VALUES
('register.by_green', '0'),
('register.by_invite', '1'),
('register.by_open', '1'),
('register.check_email_blacklist', '1'),
('register.check_email_whitelist', '1'),
('register.check_max_ip', '1'),
('register.check_max_user', '1'),
('register.email_black_list', '@test.com'),
('register.email_white_list', '@gmail.com'),
('register.enabled_email_black_list', '1'),
('register.enabled_email_white_list', '1'),
('register.max_ip_check', '1'),
('register.max_user_check', '1'),
('register.per_ip_user', '5'),
('register.user_confirm_way', 'auto'),
('register.user_default_bonus', '0'),
Expand Down Expand Up @@ -618,18 +619,6 @@ CREATE TABLE IF NOT EXISTS `torrents_categories` (
-- RELATIONSHIPS FOR TABLE `torrents_categories`:
--

--
-- Truncate table before insert `torrents_categories`
--

TRUNCATE TABLE `torrents_categories`;
--
-- Dumping data for table `torrents_categories`
--

INSERT INTO `torrents_categories` (`id`, `name`) VALUES
(1, 'Movie');

-- --------------------------------------------------------

--
Expand Down

0 comments on commit bacee6d

Please sign in to comment.