From 728a40408f5f11ec1f9916186e63bb7aa0c4f934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B8nstantine=20Kovalensky?= <45331093+kovalensky@users.noreply.github.com> Date: Tue, 21 Nov 2023 20:42:44 +0400 Subject: [PATCH] Event based invite system (#1149) Co-authored: @belomaxorka --- library/config.php | 12 +++++++++++ library/includes/ucp/register.php | 22 ++++++++++++++++++++ library/language/source/main.php | 5 +++++ styles/templates/default/usercp_register.tpl | 6 ++++++ 4 files changed, 45 insertions(+) diff --git a/library/config.php b/library/config.php index 3f17a7f62..ffd02ab2f 100644 --- a/library/config.php +++ b/library/config.php @@ -378,6 +378,18 @@ $bb_cfg['unique_ip'] = false; // Disallow registration from multiple IP addresse $bb_cfg['new_user_reg_restricted'] = false; // Disallow registration in below hours $bb_cfg['new_user_reg_interval'] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]; // Available hours $bb_cfg['reg_email_activation'] = true; // Demand to activate profile by email confirmation +// Invites +$bb_cfg['invite_only'] = true; +// Invite codes +// Syntax: 'invite_code' => 'validity_period' +// The 'validity_period' value is based on strtotime() function: https://www.php.net/manual/en/function.strtotime.php +// Invite link example: site_url/profile.php?mode=register&invite=new_year +$bb_cfg['invite_codes'] = [ + 'new_year' => '+1 month', + 'ein_volk' => '29 July 1936', + 'catch_up_overtake' => '1917-10-09' +]; + $bb_cfg['password_symbols'] = [ // Whay symbols should be required in the password 'nums' => true, // Numeric diff --git a/library/includes/ucp/register.php b/library/includes/ucp/register.php index e5692c5a8..4817e60aa 100644 --- a/library/includes/ucp/register.php +++ b/library/includes/ucp/register.php @@ -71,6 +71,7 @@ switch ($mode) { 'username' => true, 'user_password' => true, 'user_email' => true, + 'invite_code' => true, 'user_timezone' => true, 'user_lang' => true, 'user_opt' => true @@ -81,6 +82,7 @@ switch ($mode) { 'username' => '', 'user_password' => '', 'user_email' => '', + 'invite_code' => '', 'user_timezone' => $bb_cfg['board_timezone'], 'user_lang' => $bb_cfg['default_lang'], 'user_opt' => 0, @@ -197,6 +199,25 @@ foreach ($profile_fields as $field => $can_edit) { $tp_data['USERNAME'] = $pr_data['username']; break; + /** + * Invite code (reg) + */ + case 'invite_code': + if ($bb_cfg['invite_only']) { + $invite_code = $_POST['invite_code'] ?? ''; + if ($submit) { + if (isset($bb_cfg['invite_codes'][$invite_code])) { + if (TIMENOW > strtotime($bb_cfg['invite_codes'][$invite_code])) { + $errors[] = $lang['INVITE_EXPIRED']; + } + } + else { + $errors[] = $lang['INCORRECT_INVITE']; + } + } + } + break; + /** * Пароль (edit, reg) */ @@ -660,6 +681,7 @@ $template->assign_vars([ 'ADM_EDIT' => $adm_edit, 'SHOW_PASS' => ($adm_edit || ($mode == 'register' && IS_ADMIN)), 'PASSWORD_LONG' => sprintf($lang['PASSWORD_LONG'], PASSWORD_MAX_LENGTH, PASSWORD_MIN_LENGTH), + 'INVITE_CODE' => !empty($_GET['invite']) ? htmlCHR($_GET['invite']) : '', 'CAPTCHA_HTML' => ($need_captcha) ? bb_captcha('get') : '', 'LANGUAGE_SELECT' => \TorrentPier\Legacy\Select::language($pr_data['user_lang'], 'user_lang'), diff --git a/library/language/source/main.php b/library/language/source/main.php index 5fa9f81b7..30c122a55 100644 --- a/library/language/source/main.php +++ b/library/language/source/main.php @@ -688,6 +688,11 @@ $lang['LIKE_OWN_POST'] = 'You can\'t vote for your own topic'; $lang['NO_LIKES'] = 'Nobody gave a vote yet'; $lang['LIKE_ALREADY'] = 'You already voted this topic'; +// Invites +$lang['INVITE_CODE'] = 'Invite code'; +$lang['INCORRECT_INVITE'] = 'Invite not found'; +$lang['INVITE_EXPIRED'] = 'Invite expired'; + // Group control panel $lang['GROUP_CONTROL_PANEL'] = 'User Groups'; $lang['GROUP_CONFIGURATION'] = 'Group Configuration'; diff --git a/styles/templates/default/usercp_register.tpl b/styles/templates/default/usercp_register.tpl index aed51a36e..24269aa9a 100644 --- a/styles/templates/default/usercp_register.tpl +++ b/styles/templates/default/usercp_register.tpl @@ -95,6 +95,12 @@ + +