Preparation fpr new mareike & solea module

This commit is contained in:
2024-07-30 23:06:59 +02:00
parent 19a10e5704
commit 5e107d36ca
10 changed files with 177 additions and 206 deletions

View File

@ -0,0 +1,39 @@
<?php
/**
* File: class-extendregistrationform.php
*
*
* @since 2024-07-30
* @license GPL-3.0-or-later
*
* @package mareike/
*/
namespace Bdp\Modules\Registration\Controllers;
class ExtendRegistrationForm {
public static function execute() {
?>
<p>
<label for="first_name">Vorname<br />
<input required style="width: 768px !important;" type="text" name="first_name" id="first_name" class="input" value="<?php echo esc_attr(wp_unslash($_POST['first_name'] ?? '')); ?>" size="25" /></label>
</p>
<p>
<label for="last_name">Nachname<br />
<input required style="width: 768px !important;" type="text" name="last_name" id="last_name" class="input" value="<?php echo esc_attr(wp_unslash($_POST['last_name'] ?? '')); ?>" size="25" /></label>
</p>
<?php
}
public static function error_messages($errors, $sanitized_user_login, $user_email) {
if (empty($_POST['first_name']) || !empty($_POST['first_name']) && trim($_POST['first_name']) == '') {
$errors->add('first_name_error', '<strong>FEHLER</strong>: Der Vorname ist erforderlich.');
}
if (empty($_POST['last_name']) || !empty($_POST['last_name']) && trim($_POST['last_name']) == '') {
$errors->add('last_name_error', '<strong>FEHLER</strong>: DEr Nachname ist erforderlich.');
}
return $errors;
}
}

View File

@ -0,0 +1,76 @@
<?php
/**
* File: class-saveregistration.php
*
*
* @since 2024-07-30
* @license GPL-3.0-or-later
*
* @package mareike/
*/
namespace Bdp\Modules\Registration\Controllers;
use WP_User;
class SaveRegistration {
public static function execute($user_id) {
if (!empty($_POST['first_name'])) {
update_user_meta($user_id, 'first_name', sanitize_text_field($_POST['first_name']));
}
if (!empty($_POST['last_name'])) {
update_user_meta($user_id, 'last_name', sanitize_text_field($_POST['last_name']));
}
// Assign the 'Standarduser' role to the new user
$user = new WP_User($user_id);
$user->set_role('standarduser');
// Send confirmation email
$user = get_userdata($user_id);
$code = sha1($user->user_registered);
update_user_meta($user_id, 'activation_code', $code);
$activation_link = add_query_arg(array('key' => $code, 'user' => $user_id), get_site_url() . '/wp-login.php');
wp_mail($user->user_email, 'Bitte bestätige deine Anmeldung', 'Hallo, bitte bestätige deine Anmeldung über den folgenden Link: ' . $activation_link);
// Notify admin
wp_mail(get_option('admin_email'), 'New User Registration', 'A new user has registered: ' . $user->user_login . PHP_EOL . 'First name:' . $user->first_name . PHP_EOL . 'Last name:' . $user->last_name );
}
public static function activate_user() {
if (isset($_GET['key']) && isset($_GET['user'])) {
$user_id = intval($_GET['user']);
$activation_code = get_user_meta($user_id, 'activation_code', true);
if ($activation_code === $_GET['key']) {
delete_user_meta($user_id, 'activation_code');
wp_redirect(home_url('/wp-login.php?checkemail=registered'));
exit;
}
}
}
public static function check_user_activation($user, $username, $password) {
if (!is_a($user, 'WP_User')) {
return null;
}
$user_id = $user->ID;
$activation_code = get_user_meta($user_id, 'activation_code', true);
if ($activation_code) {
return new WP_Error('not_activated', __('ERROR: You need to activate your account. Please check your email.', 'kompass'));
}
return $user;
}
public static function display_custom_message() {
if (isset($_GET['checkemail']) && $_GET['checkemail'] === 'registered') {
echo '<div class="custom-message" style="text-align:center; margin:20px auto; padding:10px; background-color:#e0f7fa; border:1px solid #00796b; border-radius:5px; max-width:600px;">
<p style="font-size:16px; color:#00796b;">Vielen Dank für deine Registrierung. Bitte überprüfen deine E-Mails, um deine Registrierung zu bestätigen.</p>
</div>';
}
}
}

View File

@ -1,6 +1,4 @@
<?php
add_filter('the_content', ['Calendar', 'printCalendar']);
wp_enqueue_style('bdp_calendar_css', BDP_LV_PLUGIN_URL . '/modules/calendar/assets/calendar.css');
wp_enqueue_script( 'loadCalendar', BDP_LV_PLUGIN_URL . '/modules/calendar/assets/ajaxscript.js');
require_once dirname(__FILE__) . '/classes/Calendar.class.php';

View File

@ -28,6 +28,9 @@ class Calendar
// Der zu ersetzende String
$original_string = '{{calendar}}';
if (str_contains($content,$original_string)) {
wp_enqueue_style('bdp_calendar_css', BDP_LV_PLUGIN_URL . '/modules/calendar/assets/calendar.css');
wp_enqueue_script( 'loadCalendar', BDP_LV_PLUGIN_URL . '/modules/calendar/assets/ajaxscript.js');
$calendar = new Calendar();
// Der Ersatzstring

View File

@ -40,11 +40,27 @@ class MainController
}
public function __construct()
{
global $dbHandler;
global $dbHandler, $wpdb;
add_menu_page(
__('Events', BDP_LV_PLUGIN_SLUG),
__('Events', BDP_LV_PLUGIN_SLUG),
$show_menu = false;
foreach ([self::KOMPASS_EVENTS_EVENTS] as $table) {
$sqlTable = $wpdb->prefix . $table;
$sql = "SHOW TABLES LIKE '$sqlTable'";
$result = $wpdb->get_var( $sql );
if ( $result == $sqlTable ) {
$show_menu = true;
}
}
if (!$show_menu) {
return;
}
add_menu_page(
__('Events (legacy)', BDP_LV_PLUGIN_SLUG),
__('Events (legacy)', BDP_LV_PLUGIN_SLUG),
'send_mails',
'kompass-events',
[$this, 'router'],

View File

@ -28,8 +28,7 @@ class Security
$loginUrl = get_option('whl_page', null) ?? 'bdp-login';
}
enable_option_rewrite_url($loginUrl);
enable_option_disable_xmlrpc();
enable_option_disable_xmlrpc();
enable_option_block_authorscan();
enable_option_block_execution_in_uploads();
enable_option_prohibit_special_files();
@ -83,12 +82,17 @@ class Security
public static function SetPageFilters() {
global $wp;
if (str_contains($_SERVER['REQUEST_URI'], 'wp-login.php?action=logout')) {
return;
add_action('template_redirect', [Security::class, 'protectAuthorScan']);
if (null !== is_login_rewritten()) {
if (str_contains($_SERVER['REQUEST_URI'], 'wp-login.php?action=logout')) {
return;
}
add_action('template_redirect', [Security::class, 'protectAuthorScan']);
Security::protectLoginSecurity();
Security::protectLoginSecurity();
}
}
public static function protectLoginSecurity() {

View File

@ -86,12 +86,6 @@ function disable_option_disable_wp_debug() {
WpConfigEditor::updateConfig('WP_DEBUG', 'true');
}
function enable_option_rewrite_url(?string $url = null) {
global $_POST;
$saveUrl = $url ?? $_POST['rewrite_login'];
update_option('kompass_sec_rewrite_login', $saveUrl);
}
function disable_option_rewrite_url() {
update_option('kompass_sec_rewrite_login', null);
}
@ -110,7 +104,6 @@ function kompass_sec_save_settings($settings) {
'option_prohibit_bot_access',
'option_block_directory_listing',
'option_disable_wp_debug',
'option_rewrite_url',
];
$enableSettings = array_intersect($allPossibleSettings, $settings);

View File

@ -98,20 +98,6 @@
</span>
</label>
</div>
<div class="bdp_setting_box">
<input <?php if (null !== is_login_rewritten()) {echo ' checked';} ?> type="checkbox" id="sec_mod_11" name="security_settings[]" value="option_rewrite_url" />
<label for="sec_mod_11">
<?= __('Change Login URL', BDP_LV_PLUGIN_SLUG); ?><br />
<span>
<?= __('Changing the default login URL of WordPress is advisable to enhance the security of your website. By default, WordPress login URLs is /wp-admin or /wp-login.php, which are easily guessed by hackers and facilitate attacks such as brute-force attacks. Changing the login URL to something unique and difficult to guess increases security since potential attackers will struggle to find the correct URL. This can help protect your website from unauthorized access and other malicious activities.', BDP_LV_PLUGIN_SLUG); ?><br />
<label style="font-weight: bold;">
<?= __('Login-URL', BDP_LV_PLUGIN_SLUG) ?>: <?= get_site_url(); ?>/<input style="width: 100px;" class="long_text" type="text" name="rewrite_login" id="rewrite_login" value="<?= is_login_rewritten(); ?>">
</label>
</span>
</label>
</div>
<br /><br />
<input type="submit" class="button" value="<?= __('Save changes', BDP_LV_PLUGIN_SLUG); ?>" />