Plugin Directory

Changeset 2808168


Ignore:
Timestamp:
10/31/2022 05:59:07 PM (3 years ago)
Author:
aixeiger
Message:

Add support for unlock users in the section

Location:
lock-login/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • lock-login/trunk/Readme.txt

    r2793732 r2808168  
    11=== Lock Login ===
    22Contributors: aixeiger
    3 Tags: security, login
     3Tags: security, login, lock, unlock, login failed
    44Tested up to: 6.0
    5 Stable tag: 0.1.2
     5Stable tag: 0.1.3
    66Requires PHP: 7.4
    77License: GPLv2 or later
     
    1818* Install the plugin
    1919* That's all
     20* For unlock users go to Settings -> Lock Login and lock on 'Unlock' for the selected user
     21
     22## Changelog
     23
     240.1.3       31-oct-22       Add an admin panel for unlock users gracefully
  • lock-login/trunk/includes/App.php

    r2793732 r2808168  
    2121        add_action('wp_authenticate_user', array($this, 'authenticate_user'), 100, 2); // set at last
    2222        add_filter('shake_error_codes', array($this, 'failure_shake'), 10);
     23
     24        add_action('admin_init', array($this, 'unlock_users'));
     25        add_action('admin_menu', array($this, 'register_admin_menu'));
    2326    }
    2427
     
    3033    {
    3134        $server_data = $this->get_server_data();
    32         $loaded_from = 'wp_login';
     35        $loaded_from = 'wp-login';
    3336        if(isset($GLOBALS['wp_xmlrpc_server']) && is_object($GLOBALS['wp_xmlrpc_server'])){
    3437            $loaded_from = 'wp_xmlrpc_server';
     
    5255        if(!$this->db->user_check($user->user_login, $server_data['REMOTE_ADDR'])){
    5356            $error = new \WP_Error();
    54             $error->add('too_many_retries', "Your user has surpased the limit retries please wait 20 minutes");
     57            $error->add('too_many_retries', "Your user has surpased the limit retries, please wait 20 minutes");
    5558            return $error;
    5659        } else {
     
    9497    }
    9598
     99    public function unlock_users()
     100    {
     101        if(current_user_can('manage_options') && isset($_POST['locklogin_id']) && is_numeric($_POST['locklogin_id'])){
     102            $this->db->disable_lock(filter_var($_POST['locklogin_id']), FILTER_VALIDATE_INT);
     103            wp_redirect(get_admin_url().'options-general.php?page=lock-login');
     104            exit;
     105        }
     106    }
     107
     108    public function register_admin_menu()
     109    {
     110        add_submenu_page(
     111            'options-general.php',
     112            'Lock Login',
     113            'Lock Login',
     114            'manage_options',
     115            'lock-login',
     116            array($this, 'admin_callback')
     117        );
     118    }
     119
     120    public function admin_callback()
     121    {
     122        $results = $this->db->get_locked_today();
     123        ?>
     124        <div class="wrap">
     125            <h2><?php echo esc_html(get_admin_page_title()); ?></h2>
     126            <h3>Lock tracking</h3>
     127            <table class="wp-list-table widefat fixed striped table-view-list posts">
     128                <thead>
     129                    <tr>
     130                        <td>Username</td>
     131                        <td>Ip Address</td>
     132                        <td>Browser</td>
     133                        <td>Platform</td>
     134                        <td>Attempts</td>
     135                        <td>Date</td>
     136                        <td>Action</td>
     137                    </tr>
     138                </thead>
     139                <tbody>
     140                    <?php
     141                    if($results):
     142                    foreach ($results as $obj):
     143                    ?>
     144                    <tr>
     145                        <td><?php echo esc_html($obj->username); ?></td>
     146                        <td><?php echo esc_html($obj->remote_addr); ?></td>
     147                        <td><?php echo esc_html($obj->browser); ?></td>
     148                        <td><?php echo esc_html($obj->platform); ?></td>
     149                        <td><?php echo esc_html($obj->attempts); ?></td>
     150                        <td><?php echo esc_html($obj->created_at.' '.$obj->created_time_at); ?></td>
     151                        <td>
     152                            <form method="post">
     153                                <input type="hidden" name="locklogin_id" value="<?php echo esc_html($obj->id); ?>">
     154                                <button type="submit">Unlock</button>
     155                            </form>
     156                        </td>
     157                    </tr>
     158                    <?php
     159                    endforeach;
     160                    endif;
     161                    ?>
     162                </tbody>
     163            </table>
     164        </div>
     165        <?php
     166    }
     167
    96168}
  • lock-login/trunk/includes/DB.php

    r2793732 r2808168  
    4242            return false;
    4343        }
     44    }
     45
     46    public function get_locked_today()
     47    {
     48        $register_name = $this->register_table_name;
     49        return $this->wpdb->get_results($this->wpdb->prepare("SELECT id, username, http_host, remote_addr, browser, browser_version, platform, attempts, created_at, created_time_at FROM $register_name WHERE created_at = %s AND attempts > 0", $this->get_current_date()));
     50    }
     51
     52    public function disable_lock($id)
     53    {
     54        $register_name = $this->register_table_name;
     55        $this->wpdb->update(
     56            $register_name,
     57            array(
     58                'attempts' => 0
     59            ),
     60            array('id' => $id),
     61            array('%d')
     62        );
    4463    }
    4564
  • lock-login/trunk/locklogin.php

    r2793732 r2808168  
    55 * Author: TocinoDev
    66 * Author URI: https://tocino.mx
    7  * Version: 0.1.2
     7 * Version: 0.1.3
    88 * Tested up to: 6.0
    99 * Requires PHP: 7.4
Note: See TracChangeset for help on using the changeset viewer.