Plugin Directory

Changeset 3183506


Ignore:
Timestamp:
11/07/2024 04:41:43 AM (17 months ago)
Author:
alphanetbd
Message:

added otp session timeout checking, fixed submit btn style

Location:
alpha-sms
Files:
47 added
5 edited

Legend:

Unmodified
Added
Removed
  • alpha-sms/trunk/README.txt

    r3028026 r3183506  
    33Tags: order notification, order SMS, woocommerce sms integration, sms plugin, mobile verification, OTP, SMS notifications, two-step verification, OTP verification, SMS, signup security, user verification, user security, SMS gateway, order SMS, order notifications, WordPress OTP, 2FA, login OTP, WP SMS
    44Requires at least: 3.5
    5 Tested up to: 6.2
     5Tested up to: 6.6.2
    66Requires PHP: 5.6
    7 Stable tag: 1.0.9
     7Stable tag: 1.0.10
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
  • alpha-sms/trunk/alpha_sms.php

    r3028026 r3183506  
    1717 * Plugin URI:        https://sms.net.bd/plugins/wordpress
    1818 * Description:       WP 2FA Login. SMS OTP Verification for Registration and Login forms, WooCommerce SMS Notification for your shop orders.
    19  * Version:           1.0.9
     19 * Version:           1.0.10
    2020 * Author:            Alpha Net
    2121 * Author URI:        https://sms.net.bd/
     
    3636 * Rename this for your plugin and update it as you release new versions.
    3737 */
    38 define('ALPHA_SMS_VERSION', '1.0.9');
     38define('ALPHA_SMS_VERSION', '1.0.10');
    3939
    4040// plugin constants
  • alpha-sms/trunk/public/class-alpha_sms-public.php

    r3028026 r3183506  
    5858    }
    5959
    60     /**
     60        /**
    6161     * @return void
    6262     * @since 1.0.0
     
    7070    }
    7171
     72   
    7273    /**
    7374     * Register the stylesheets for the public-facing side of the site.
     
    195196    public function send_otp_for_reg()
    196197    {
    197         $user_phone = $user_email = '';
    198 
    199         if (isset($_POST['billing_phone'], $_POST['email'])) {
     198        $user_phone = '';
     199
     200        if (isset($_POST['billing_phone'])) {
    200201            $user_phone = $this->validateNumber(sanitize_text_field($_POST['billing_phone']));
    201             $user_email = sanitize_text_field($_POST['email']);
    202         }
    203 
    204         if (!$user_email && !empty($_POST['billing_email'])) {
    205             $user_email = sanitize_text_field($_POST['billing_email']);
    206         }
    207 
    208         if (!filter_var($user_email, FILTER_VALIDATE_EMAIL)) {
    209             $response = ['status' => 400, 'message' => __('The email address you entered is not valid!')];
    210             echo wp_kses_post(json_encode($response));
    211             wp_die();
    212             exit;
    213202        }
    214203
     
    226215            exit;
    227216        }
     217
     218        // check for already send otp by checking expiration
     219        $otp_expires = WC()->session->get('alpha_sms_expires');
     220
     221        if (!empty($otp_expires) && strtotime($otp_expires) > strtotime(ALPHA_SMS_TIMESTAMP)) {
     222            $response = [
     223                'status'  => 400,
     224                'message' => 'OTP already sent to a phone number. Please try again after ' . date('i:s', strtotime($otp_expires) - strtotime(ALPHA_SMS_TIMESTAMP) . ' min'),
     225            ];
     226            echo wp_kses_post(json_encode($response));
     227            wp_die();
     228            exit;
     229        }
     230
    228231
    229232        //we will send sms
     
    343346    ) {
    344347        $dateTime = new DateTime(ALPHA_SMS_TIMESTAMP);
    345         $dateTime->modify('+2 minutes');
    346 
    347         $_SESSION['alpha_sms_otp_code'] = $otp_code;
    348         $_SESSION['alpha_sms_expires']  = $dateTime->format('Y-m-d H:i:s');
    349 
    350         if (!empty($_SESSION['alpha_sms_otp_code'])) {
     348        $dateTime->modify('+3 minutes');
     349
     350        WC()->session->set('alpha_sms_otp_phone', $mobile_phone);
     351        WC()->session->set('alpha_sms_otp_code', $otp_code);
     352        WC()->session->set('alpha_sms_expires', $dateTime->format('Y-m-d H:i:s'));
     353
     354        if(WC()->session->get('alpha_sms_otp_code')) {
    351355            return true;
    352356        }
     
    512516    public function authenticate_otp($otp_code)
    513517    {
    514 
    515 
    516         if (!empty($_SESSION['alpha_sms_otp_code']) && !empty($_SESSION['alpha_sms_expires'])) {
    517 
    518             if (strtotime($_SESSION['alpha_sms_expires']) > strtotime(ALPHA_SMS_TIMESTAMP)) {
    519                 if ($otp_code === $_SESSION['alpha_sms_otp_code']) {
     518        $otp_code_session = WC()->session->get('alpha_sms_otp_code');
     519        $otp_expires_session = WC()->session->get('alpha_sms_expires');
     520
     521        if (!empty($otp_code_session) && !empty($otp_expires_session)) {
     522            if (strtotime($otp_expires_session) > strtotime(ALPHA_SMS_TIMESTAMP)) {
     523                if ($otp_code === $otp_code_session) {
    520524                    return true;
    521525                }
     
    532536    public function deletePastData()
    533537    {
    534         if (isset($_SESSION['alpha_sms_otp_code'], $_SESSION['alpha_sms_expires'])) {
    535             unset($_SESSION['alpha_sms_otp_code'], $_SESSION['alpha_sms_expires']);
     538        if (WC()->session->get('alpha_sms_otp_code') || WC()->session->get('alpha_sms_expires')) {
     539            WC()->session->__unset('alpha_sms_otp_code');
     540            WC()->session->__unset('alpha_sms_expires');
    536541        }
    537542    }
  • alpha-sms/trunk/public/js/alpha_sms-public.js

    r2812471 r3183506  
    2828      checkout_form = $('#alpha_sms_otp_checkout').parents('form.checkout.woocommerce-checkout').eq(0);
    2929      $(document).on('click', '#place_order2', WC_Checkout_SendOtp);
     30
     31
    3032   }
    3133});
     
    178180   alert_wrapper.html('');
    179181
    180    let firstName = checkout_form.find('#billing_first_name').val();
    181    let lastName = checkout_form.find('#billing_last_name').val();
    182    let country = checkout_form.find('#billing_country').val();
    183    let address = checkout_form.find('#billing_address_1').val();
    184    let city = checkout_form.find('#billing_city').val();
    185    let state = checkout_form.find('#billing_state').val();
    186182   let phone = checkout_form.find('#billing_phone').val();
    187    let email = checkout_form.find('#billing_email').val();
    188183
    189184   if (
    190       !firstName ||
    191       !lastName ||
    192       !country ||
    193       !address ||
    194       !city ||
    195       !state ||
    196       !phone ||
    197       !email
     185      !phone
    198186   ) {
    199187      checkout_form
     
    213201      action: 'wc_send_otp', //calls wp_ajax_nopriv_wc_send_otp
    214202      billing_phone: checkout_form.find('#billing_phone').val(),
    215       email: checkout_form.find('#billing_email').val(),
    216203      action_type: checkout_form.find('#action_type').val()
    217204   };
  • alpha-sms/trunk/public/partials/add-otp-checkout-form.php

    r2627862 r3183506  
    11<?php
    22// If this file is called directly, abort.
    3 if ( ! defined( 'WPINC' ) ) {
    4     die;
     3if (! defined('WPINC')) {
     4  die;
    55}
    66?>
     
    1010    <label for="otp_code" class="d-inline-block">OTP Code</label>
    1111    <div id="wc_checkout_resend_otp" class="float-right"></div>
    12     <input type="number" class="input" id="otp_code" name="otp_code" />
     12    <input type="number" class="input-text" id="otp_code" name="otp_code" />
    1313  </div>
    1414</div>
    15 <button type="button" class="button alt" name="woocommerce_checkout_place_order" id="place_order2">Place order</button>
     15<button type="button" class="alt button wp-element-button" name="woocommerce_checkout_place_order" id="place_order2">Place order</button>
    1616<style>
    17 button#place_order {
    18   display: none;
    19 }
     17  button#place_order {
     18    display: none;
     19  }
    2020</style>
     21<script>
     22  $(document).ready(function() {
     23    // Get computed styles of #place_order
     24    const placeOrderStyles = window.getComputedStyle(document.getElementById('place_order'));
     25
     26    $.each(placeOrderStyles, function(i, propertyName) {
     27      if (propertyName === 'display') return; // Skip display property if needed
     28      $('#place_order2').css(propertyName, placeOrderStyles.getPropertyValue(propertyName));
     29    });
     30  });
     31</script>
Note: See TracChangeset for help on using the changeset viewer.