Plugin Directory

Changeset 3472376


Ignore:
Timestamp:
03/02/2026 06:40:22 AM (4 weeks ago)
Author:
bitsstech
Message:

version 1.2.0

Location:
otpfy-your-website
Files:
52 added
6 edited

Legend:

Unmodified
Added
Removed
  • otpfy-your-website/trunk/includes/class-otpfy-for-wordpress.php

    r3340312 r3472376  
    230230        $this->loader->add_action( 'wp_ajax_otpfy_checkout_verify_otp', $plugin_public, 'wp_ajax_otpfy_checkout_verify_otp' );
    231231        $this->loader->add_action( 'wp_ajax_nopriv_otpfy_checkout_verify_otp', $plugin_public, 'wp_ajax_otpfy_checkout_verify_otp' );
    232     }
     232
     233        $this->loader->add_action( 'wp_ajax_api_call_register_and_login', $plugin_public, 'api_call_register_and_login' );
     234        $this->loader->add_action( 'wp_ajax_nopriv_api_call_register_and_login', $plugin_public, 'api_call_register_and_login' );
     235    }
     236
    233237
    234238    /**
  • otpfy-your-website/trunk/otpfy-for-wordpress.php

    r3384409 r3472376  
    1212 * Plugin URI:        https://otpfy.in
    1313 * Description:       OTPfy almost anything in your wordpress website!! OTP based Login, Signup, Order Confirmation, just anything you can imagine. Integrate OTP based 2 factor authentication using our developer hooks.
    14  * Version:           1.0.3.5
     14 * Version:           1.2.0
    1515 * Author:            Bitss Techniques
    1616 * Author URI:        https://bitss.tech
     
    3131 * Rename this for your plugin and update it as you release new versions.
    3232 */
    33 define( 'OTPFY_FOR_WORDPRESS_VERSION', '1.0.3.5' );
     33define( 'OTPFY_FOR_WORDPRESS_VERSION', '1.2.0' );
    3434
    3535/**
  • otpfy-your-website/trunk/public/class-otpfy-for-wordpress-public.php

    r3384409 r3472376  
    118118                "send_login_otp_nonce" => wp_create_nonce('api_call_send_verification_code'),
    119119                "vf_login_otp_nonce" => wp_create_nonce('api_call_verification_code'),
    120                 // "test_conn_nonce"    => wp_create_nonce('api_call_for_test_connection'),
    121                 // "test_conn_nonce"    => wp_create_nonce('api_call_for_test_connection'),
    122 
     120                "register_and_login_nonce" => wp_create_nonce('api_call_register_and_login'),
    123121            )
    124122        );
     
    264262               
    265263        }
    266        
     264
     265        // --- No account found: send OTP for registration flow ---
     266        if ($user == false || $user == null) {
     267            $otp = wp_rand(100000, 999999);
     268            $otp_reg_arr = array(
     269                "otp"               => $otp,
     270                "phone"             => $value,
     271                "otp_login_redirect" => $otp_login_redirect,
     272            );
     273            set_transient( 'otpfy_noreg_' . $value, $otp_reg_arr, 10 * MINUTE_IN_SECONDS );
     274            $this->core->send_otp_for_verify( $otp, $value, '' );
     275            $response = array(
     276                "status"       => true,
     277                "user_not_found" => true,
     278                "data"         => null,
     279                "message"      => "OTP sent! Please fill in your details to create an account.",
     280            );
     281            wp_send_json($response);
     282            die();
     283        }
     284
    267285    //check if woocommerce plugin is active
    268286
     
    297315            $this->core->send_otp_for_verify($otp,$phone,$email );
    298316
    299             //$response_code = wp_remote_retrieve_response_code( $response );
    300             //  $body = json_decode( wp_remote_retrieve_body( $resp ), true );
    301 
    302317            $response = array(
    303318                "status" => true,
     
    310325        die();
    311326
     327    }
     328
     329    /**
     330     * AJAX: Verify OTP and register a new user, then auto-login.
     331     * Action: api_call_register_and_login
     332     */
     333    function api_call_register_and_login() {
     334
     335        if ( ! wp_verify_nonce( sanitize_text_field( $_GET['nonce'] ?? '' ), 'api_call_register_and_login' ) ) {
     336            wp_send_json( array( 'status' => false, 'message' => 'Security check failed.' ) );
     337            die();
     338        }
     339
     340        $phone      = sanitize_text_field( trim( $_GET['phone'] ?? '' ) );
     341        $otp        = absint( trim( $_GET['otp'] ?? '' ) );
     342        $first_name = sanitize_text_field( trim( $_GET['first_name'] ?? '' ) );
     343        $email      = sanitize_email( trim( $_GET['email'] ?? '' ) );
     344
     345        // Validate required fields
     346        if ( empty( $phone ) || empty( $otp ) || empty( $first_name ) || empty( $email ) ) {
     347            wp_send_json( array( 'status' => false, 'message' => 'All fields are required.' ) );
     348            die();
     349        }
     350
     351        if ( ! is_email( $email ) ) {
     352            wp_send_json( array( 'status' => false, 'message' => 'Please enter a valid email address.' ) );
     353            die();
     354        }
     355
     356        if ( email_exists( $email ) ) {
     357            wp_send_json( array( 'status' => false, 'message' => 'An account with this email already exists. Please login instead.' ) );
     358            die();
     359        }
     360
     361        // Verify OTP
     362        $otp_reg_arr = get_transient( 'otpfy_noreg_' . $phone );
     363        if ( false === $otp_reg_arr ) {
     364            wp_send_json( array( 'status' => false, 'message' => 'OTP expired. Please go back and request a new one.' ) );
     365            die();
     366        }
     367        if ( intval( $otp_reg_arr['otp'] ) !== $otp ) {
     368            wp_send_json( array( 'status' => false, 'message' => 'Invalid OTP. Please try again.' ) );
     369            die();
     370        }
     371
     372        // Create user
     373        $username = sanitize_user( $email );
     374        // Ensure username is unique
     375        if ( username_exists( $username ) ) {
     376            $username = $username . '_' . wp_rand( 100, 999 );
     377        }
     378
     379        $user_id = wp_create_user( $username, wp_generate_password(), $email );
     380        if ( is_wp_error( $user_id ) ) {
     381            wp_send_json( array( 'status' => false, 'message' => $user_id->get_error_message() ) );
     382            die();
     383        }
     384        $user = new WP_User( $user_id );
     385
     386        if ( class_exists( 'WooCommerce' ) ) {
     387            $user->set_role( 'customer' );
     388        } else {
     389            $user->set_role( 'subscriber' );
     390        }
     391
     392        // Save user meta
     393        update_user_meta( $user_id, 'first_name', $first_name );
     394        update_user_meta( $user_id, 'bt_otpfy_user_mobile_number', $phone );
     395        wp_update_user( array( 'ID' => $user_id, 'display_name' => $first_name ) );
     396
     397        // WooCommerce billing meta
     398        if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
     399            update_user_meta( $user_id, 'billing_first_name', $first_name );
     400            update_user_meta( $user_id, 'billing_phone', $phone );
     401            update_user_meta( $user_id, 'billing_email', $email );
     402        }
     403
     404        // Clean up transient
     405        delete_transient( 'otpfy_noreg_' . $phone );
     406
     407        // Auto-login
     408        $u_data = get_userdata( $user_id );
     409        wp_clear_auth_cookie();
     410        wp_set_current_user( $user_id );
     411        wp_set_auth_cookie( $user_id, true );
     412        do_action( 'wp_login', $u_data->user_login, $u_data );
     413
     414        // Redirect
     415        $otp_login_redirect_reg = isset( $otp_reg_arr['otp_login_redirect'] ) && ! empty( $otp_reg_arr['otp_login_redirect'] )
     416            ? wp_validate_redirect( $otp_reg_arr['otp_login_redirect'], '' )
     417            : '';
     418        if ( ! $otp_login_redirect_reg ) {
     419            $otp_login_redirect_reg = get_permalink( $this->settings->get_redirect_url_after_login() );
     420        }
     421        if ( ! $otp_login_redirect_reg ) {
     422            $otp_login_redirect_reg = $this->get_next_page_url_based_on_user_role( $user_id );
     423        }
     424
     425        wp_send_json( array(
     426            'status'  => true,
     427            'data'    => $otp_login_redirect_reg,
     428            'message' => 'Registration successful! Logging you in...',
     429        ) );
     430        die();
    312431    }
    313432
  • otpfy-your-website/trunk/public/css/otpfy-for-wordpress-public.css

    r3228487 r3472376  
    4949}
    5050#bt_otpfy_email_phone_input::placeholder,
     51.registration_details::placeholder,
    5152#bt_otpfy_vf_code_input::placeholder {
    5253text-align: center;
     
    5758
    5859#bt_otpfy_email_phone_input,
     60.registration_details,
    5961#bt_otpfy_vf_code_input {
    60   margin: 10px 0px 5px 0px;
    61   border-radius: 15px;
    62   border: 1px solid black;
     62  margin: 10px 0px 5px 0px !important;
     63  border-radius: 15px !important;
     64  border: 1px solid black !important;
    6365  font-size: 15px !important;
    6466  line-height: 10px !important;
    65   padding: 10px;
     67  padding: 10px !important;
    6668  width: 100%;
    67   box-sizing: border-box;
    68   height: 40px;
    69   text-align: center;
     69  box-sizing: border-box !important;
     70  height: 40px !important;
     71  text-align: center !important;
    7072}
    7173
    7274/* Chrome, Safari, Edge, Opera */
    7375#bt_otpfy_vf_code_input::-webkit-outer-spin-button,
     76.registration_details::-webkit-outer-spin-button,
     77.registration_details::-webkit-inner-spin-button,
    7478#bt_otpfy_vf_code_input::-webkit-inner-spin-button {
    7579  -webkit-appearance: none;
     
    7781}
    7882/* Firefox */
     83.registration_details[type="number"] ,
    7984#bt_otpfy_vf_code_input[type="number"] {
    8085  -moz-appearance: textfield;
    8186}
    8287#bt_otpfy_email_phone_input:focus,
     88.registration_details:focus,
    8389#bt_otpfy_vf_code_input:focus {
    8490  border: 1px solid black;
  • otpfy-your-website/trunk/public/js/otpfy-for-wordpress-public.js

    r3228487 r3472376  
    1 (function( $ ) {
     1(function ($) {
    22    'use strict';
    33
    4     /**
    5      * All of the code for your public-facing JavaScript source
    6      * should reside in this file.
    7      *
    8      * Note: It has been assumed you will write jQuery code here, so the
    9      * $ function reference has been prepared for usage within the scope
    10      * of this function.
    11      *
    12      * This enables you to define handlers, for when the DOM is ready:
    13      *
    14      * $(function() {
    15      *
    16      * });
    17      *
    18      * When the window is loaded:
    19      *
    20      * $( window ).load(function() {
    21      *
    22      * });
    23      *
    24      * ...and/or other possibilities.
    25      *
    26      * Ideally, it is not considered best practise to attach more than a
    27      * single DOM-ready or window-load handler for a particular page.
    28      * Although scripts in the WordPress core, Plugins and Themes may be
    29      * practising this, we should strive to set a better example in our own work.
    30      */
    31     $(document).ready(function(){
    32         $('body').on('click', '#bt_otpfy_send_vf_code_btn', function(e) {
    33             e.preventDefault(); 
     4    var isNewUser = false; // tracks whether the current OTP step is for a new user
     5
     6    $(document).ready(function () {
     7
     8        // ── Step 1: Send OTP ─────────────────────────────────────────────────
     9        $('body').on('click', '#bt_otpfy_send_vf_code_btn', function (e) {
     10            e.preventDefault();
    3411            $('#bt_otpfy_send_vf_code_btn').prop("disabled", true);
    3512            $('#bt_otpfy_send_server_mess').html('');
    3613            $("#bt_otpfy_send_loader").addClass("btn-ring");
    37             var value = $("#bt_otpfy_email_phone_input").val();
     14            var value = $("#bt_otpfy_email_phone_input").val();
    3815            api_call_send_vf_otp(value);
    3916        });
    4017
    41         $('body').on('click', '#bt_otpfy_vf_code_btn', function(e) {
     18        // ── Step 2: Unified verify / register button ──────────────────────────
     19        $('body').on('click', '#bt_otpfy_vf_code_btn', function (e) {
    4220            e.preventDefault();
    4321            $('#bt_otpfy_vf_code_btn').prop("disabled", true);
    4422            $('#bt_otpfy_vf_server_mess').html('');
    4523            $("#bt_otpfy_vf_loader").addClass("btn-ring");
    46             $('#bt_otpfy_vf_code_btn').html("Verifying...");
    47             var value = $("#bt_otpfy_email_phone_input").val();
    48             var code = $("#bt_otpfy_vf_code_input").val();
    49             api_call_vf_otp(value, code);
    50         });
    51 
    52         $('body').on('click', '#bt_otpfy_resend_otp', function(e) {
    53             e.preventDefault();
    54             $('#bt_otpfy_resend_otp').addClass("bt_otpfy_disabled");
    55             $('#bt_otpfy_send_server_mess').html('');
    56             var value = $("#bt_otpfy_email_phone_input").val();
    57             api_call_send_vf_otp(value);
     24
     25            var phone = $("#bt_otpfy_email_phone_input").val();
     26            var otp = $("#bt_otpfy_vf_code_input").val();
     27
     28            if (isNewUser) {
     29                // Registration mode
     30                $('#bt_otpfy_vf_code_btn').html("Registering...");
     31                var first_name = $.trim($("#bt_otpfy_reg_first_name").val());
     32                var email = $.trim($("#bt_otpfy_reg_email").val());
     33                api_call_register_and_login(phone, first_name, email, otp);
     34            } else {
     35                // Login mode
     36                $('#bt_otpfy_vf_code_btn').html("Verifying...");
     37                api_call_vf_otp(phone, otp);
     38            }
     39        });
     40
     41        // ── Resend OTP ───────────────────────────────────────────────────────
     42        $('body').on('click', '#bt_otpfy_resend_otp', function (e) {
     43            e.preventDefault();
     44            if ($(this).hasClass("bt_otpfy_disabled")) return;
     45            $('#bt_otpfy_resend_otp').addClass("bt_otpfy_disabled");
     46            $('#bt_otpfy_vf_server_mess').html('');
     47            var value = $("#bt_otpfy_email_phone_input").val();
     48            api_call_send_vf_otp(value);
    5849            clearInterval(interval);
    5950        });
    60      
    61         $('body').on('click', '#bt_otpfy_back_to_send_login_otp', function(e) {
     51
     52        // ── Go back ──────────────────────────────────────────────────────────
     53        $('body').on('click', '#bt_otpfy_back_to_send_login_otp', function (e) {
    6254            e.preventDefault();
    6355            $('#bt_otpfy_send_server_mess').html('');
    6456            $('#bt_otpfy_vf_server_mess').html('');
    6557            $("#bt_otpfy_send_otp_div").removeClass("bt_otpfy_hide_div");
    66             $("#bt_otpfy_vf_otp_div").addClass("bt_otpfy_hide_div");
     58            $("#bt_otpfy_vf_otp_div").addClass("bt_otpfy_hide_div");
    6759            clearInterval(interval);
    68             if (!$("#bt_otpfy_resend_otp").hasClass("bt_otpfy_disabled")) {
     60            if (!$("#bt_otpfy_resend_otp").hasClass("bt_otpfy_disabled")) {
    6961                $("#bt_otpfy_resend_otp").addClass("bt_otpfy_disabled");
    70             }
    71 
    72         });
    73 
    74     });
     62            }
     63            // Reset state
     64            resetOtpStep();
     65        });
     66
     67    });
     68
     69    // ── Helpers ───────────────────────────────────────────────────────────────
     70
     71    function resetOtpStep() {
     72        isNewUser = false;
     73        $("#bt_otpfy_reg_fields").hide();
     74        var loginText = $('#bt_otpfy_vf_code_btn').data('text-login');
     75        $('#bt_otpfy_vf_code_btn')
     76            .removeAttr("disabled")
     77            .html(loginText + ' <span id="bt_otpfy_vf_loader"></span>')
     78            .data('text', loginText);
     79        $("#bt_otpfy_vf_code_input").val('');
     80        $("#bt_otpfy_reg_first_name").val('');
     81        $("#bt_otpfy_reg_email").val('');
     82    }
     83
     84    function showOtpStep(newUser) {
     85        isNewUser = newUser;
     86        $("#bt_otpfy_send_otp_div").addClass("bt_otpfy_hide_div");
     87        $("#bt_otpfy_vf_otp_div").removeClass("bt_otpfy_hide_div").css('display', 'block');
     88
     89        if (newUser) {
     90            // Show registration fields and update heading/button
     91            $("#bt_otpfy_reg_fields").show();
     92            $('#bt_otpfy_vf_heading_text').html("Create Your Account");
     93            $('#bt_otpfy_vf_sub_heading_text').html("Enter your details and the OTP you received.");
     94            var regText = $('#bt_otpfy_vf_code_btn').data('text-register');
     95            $('#bt_otpfy_vf_code_btn').html(regText + ' <span id="bt_otpfy_vf_loader"></span>').data('text', regText);
     96        } else {
     97            // Hide registration fields, keep default heading/button
     98            $("#bt_otpfy_reg_fields").hide();
     99            var loginText = $('#bt_otpfy_vf_code_btn').data('text-login');
     100            $('#bt_otpfy_vf_code_btn').html(loginText + ' <span id="bt_otpfy_vf_loader"></span>').data('text', loginText);
     101        }
     102
     103        startResentOtpTimer();
     104    }
     105
     106    // ── Timer ─────────────────────────────────────────────────────────────────
     107
    75108    var interval;
    76     function startResentOtpTimer(){
     109    function startResentOtpTimer() {
    77110        var timer = 30;
    78         $('#bt_otpfy_resend_timer').html("Resend in "+timer + " sec(s)");
    79         if(interval){
    80             clearInterval(interval);
    81         }
    82         interval = setInterval( function() {
    83             timer = timer - 1;
    84             $('#bt_otpfy_resend_timer').html("Resend in "+timer + " sec(s)");
    85        
    86             if(timer === 0){
     111        $('#bt_otpfy_resend_timer').html("Resend in " + timer + " sec(s)");
     112        if (interval) clearInterval(interval);
     113        interval = setInterval(function () {
     114            timer -= 1;
     115            $('#bt_otpfy_resend_timer').html("Resend in " + timer + " sec(s)");
     116            if (timer === 0) {
    87117                $('#bt_otpfy_resend_timer').html("");
    88118                clearInterval(interval);
     
    91121        }, 1000);
    92122    }
    93     function api_call_send_vf_otp(value) {
    94        
    95         var nonce = bitss_otpfy_vars.send_login_otp_nonce;     
     123
     124    // ── AJAX: Send OTP ────────────────────────────────────────────────────────
     125
     126    function api_call_send_vf_otp(value) {
     127        var nonce = bitss_otpfy_vars.send_login_otp_nonce;
    96128        $.get(
    97129            bitss_otpfy_vars.ajax_url,
    98             { action: 'api_call_send_verification_code', input: value, nonce: nonce, otp_login_redirect : $('#otp_login_redirect').val()},
     130            { action: 'api_call_send_verification_code', input: value, nonce: nonce, otp_login_redirect: $('#otp_login_redirect').val() },
    99131            function (res) {
    100                
     132                $('#bt_otpfy_send_vf_code_btn').removeAttr("disabled");
     133                $("#bt_otpfy_send_loader").removeClass("btn-ring");
     134
    101135                if (!res) {
    102                     $('#bt_otpfy_send_vf_code_btn').removeAttr("disabled");
    103                     $("#bt_otpfy_send_loader").removeClass("btn-ring");
    104                     $('#bt_otpfy_send_server_mess').html("Please refresh the page, and try again.");
    105 
    106                 }
    107                 if (res.status) {
    108                     $('#bt_otpfy_send_vf_code_btn').removeAttr("disabled");
    109                     $("#bt_otpfy_send_loader").removeClass("btn-ring");
    110                     $("#bt_otpfy_send_otp_div").addClass("bt_otpfy_hide_div");
    111                     $("#bt_otpfy_vf_otp_div").removeClass("bt_otpfy_hide_div");
    112                     $("#bt_otpfy_vf_otp_div").css('display','block');
    113                     startResentOtpTimer();
    114                 }
    115                 else {
    116                     $('#bt_otpfy_send_vf_code_btn').removeAttr("disabled");
    117                     $("#bt_otpfy_send_loader").removeClass("btn-ring");
     136                    $('#bt_otpfy_send_server_mess').html("Please refresh the page and try again.");
     137                    return;
     138                }
     139                if (res.status) {
     140                    // Show unified OTP step — new user vs existing user
     141                    showOtpStep(res.user_not_found === true);
     142                } else {
    118143                    $('#bt_otpfy_send_server_mess').html(res.message);
    119                 }
    120             }
    121         ).fail( function(err) {
     144                }
     145            }
     146        ).fail(function () {
    122147            $('#bt_otpfy_send_vf_code_btn').removeAttr("disabled");
    123             $("#bt_otpfy_send_loader").removeClass("btn-ring");
    124             $('#bt_otpfy_send_server_mess').html( 'An error occured, please refresh try again.' );
    125         });
    126     }
    127 
    128     function api_call_vf_otp(value, code) {
    129         var nonce = bitss_otpfy_vars.vf_login_otp_nonce;       
     148            $("#bt_otpfy_send_loader").removeClass("btn-ring");
     149            $('#bt_otpfy_send_server_mess').html('An error occurred, please refresh and try again.');
     150        });
     151    }
     152
     153    // ── AJAX: Verify OTP (existing user) ─────────────────────────────────────
     154
     155    function api_call_vf_otp(value, code) {
     156        var nonce = bitss_otpfy_vars.vf_login_otp_nonce;
    130157        $.get(
    131158            bitss_otpfy_vars.ajax_url,
    132             { action: 'api_call_verification_code', input: value, code: code, nonce: nonce},
    133             (res)=> {
    134                 if (!res) {
    135                     $('#bt_otpfy_vf_code_btn').removeAttr("disabled");
    136                     $("#bt_otpfy_vf_loader").removeClass("btn-ring");
    137                     $('#bt_otpfy_vf_server_mess').html("Please refresh the page, and try again.");
    138                     $('#bt_otpfy_vf_code_btn').html($('#bt_otpfy_vf_code_btn').data('text'));
    139                 }
    140                 if (!res.status) {
    141                     $('#bt_otpfy_vf_code_btn').removeAttr("disabled");
    142                     $("#bt_otpfy_vf_loader").removeClass("btn-ring");
    143                     $('#bt_otpfy_vf_server_mess').html(res.message);
    144                     $('#bt_otpfy_vf_code_btn').html($('#bt_otpfy_vf_code_btn').data('text'));
    145                 }
    146                 else {
    147                     $('#bt_otpfy_vf_code_btn').removeAttr("disabled");
    148                     $("#bt_otpfy_vf_loader").removeClass("btn-ring");
     159            { action: 'api_call_verification_code', input: value, code: code, nonce: nonce },
     160            function (res) {
     161                $('#bt_otpfy_vf_code_btn').removeAttr("disabled");
     162                $("#bt_otpfy_vf_loader").removeClass("btn-ring");
     163
     164                if (!res || !res.status) {
     165                    $('#bt_otpfy_vf_server_mess').html(res ? res.message : "Please refresh and try again.");
     166                    $('#bt_otpfy_vf_code_btn').html($('#bt_otpfy_vf_code_btn').data('text') + ' <span id="bt_otpfy_vf_loader"></span>');
     167                } else {
    149168                    $('#bt_otpfy_vf_code_btn').html("Verified, redirecting...");
    150169                    window.location = res.data;
    151                 }
    152             }
    153         ).fail( function(err) {
    154             $('#bt_otpfy_vf_code_btn').html($('#bt_otpfy_vf_code_btn').data('text'));
     170                }
     171            }
     172        ).fail(function () {
    155173            $('#bt_otpfy_vf_code_btn').removeAttr("disabled");
    156174            $("#bt_otpfy_vf_loader").removeClass("btn-ring");
    157             $('#bt_otpfy_vf_server_mess').html( 'An error occured, please refresh try again.' );
    158         });
    159     }
    160 
    161 
    162 })( jQuery );
     175            $('#bt_otpfy_vf_code_btn').html($('#bt_otpfy_vf_code_btn').data('text') + ' <span id="bt_otpfy_vf_loader"></span>');
     176            $('#bt_otpfy_vf_server_mess').html('An error occurred, please refresh and try again.');
     177        });
     178    }
     179
     180    // ── AJAX: Register & Login (new user) ─────────────────────────────────────
     181
     182    function api_call_register_and_login(phone, first_name, email, otp) {
     183        var nonce = bitss_otpfy_vars.register_and_login_nonce;
     184        $.get(
     185            bitss_otpfy_vars.ajax_url,
     186            {
     187                action: 'api_call_register_and_login',
     188                phone: phone,
     189                first_name: first_name,
     190                email: email,
     191                otp: otp,
     192                nonce: nonce
     193            },
     194            function (res) {
     195                $('#bt_otpfy_vf_code_btn').removeAttr("disabled");
     196                $("#bt_otpfy_vf_loader").removeClass("btn-ring");
     197
     198                if (!res || !res.status) {
     199                    $('#bt_otpfy_vf_server_mess').html(res ? res.message : 'An error occurred. Please try again.');
     200                    $('#bt_otpfy_vf_code_btn').html($('#bt_otpfy_vf_code_btn').data('text') + ' <span id="bt_otpfy_vf_loader"></span>');
     201                } else {
     202                    $('#bt_otpfy_vf_code_btn').html("Registered! Redirecting...");
     203                    window.location = res.data;
     204                }
     205            }
     206        ).fail(function () {
     207            $('#bt_otpfy_vf_code_btn').removeAttr("disabled");
     208            $("#bt_otpfy_vf_loader").removeClass("btn-ring");
     209            $('#bt_otpfy_vf_code_btn').html($('#bt_otpfy_vf_code_btn').data('text') + ' <span id="bt_otpfy_vf_loader"></span>');
     210            $('#bt_otpfy_vf_server_mess').html('An error occurred, please refresh and try again.');
     211        });
     212    }
     213
     214})(jQuery);
  • otpfy-your-website/trunk/public/partials/otpfy-for-wordpress-public-display.php

    r3228487 r3472376  
    7878                <div class="bt_otpfy_heading">
    7979                    <h3>
    80                         <b>
     80                        <b id="bt_otpfy_vf_heading_text">
    8181                            <?php echo esc_html($settings->get_vf_heading_text()) ?>
    8282                        </b>
    8383                    </h3>
    84                     <p>
     84                    <p id="bt_otpfy_vf_sub_heading_text">
    8585                        <?php echo esc_html($settings->get_vf_sub_heading_text()) ?>
    8686                    </p>
    8787                </div>
     88
     89                <!-- Registration fields: hidden by default, shown only for new users -->
     90                <div id="bt_otpfy_reg_fields" style="display:none">
     91                    <div class="bt_otpfy_lg_input">
     92                        <input class="registration_details" id="bt_otpfy_reg_first_name" style="width:100%;margin-bottom:8px" type="text" placeholder="Full Name" />
     93                    </div>
     94                    <div class="bt_otpfy_lg_input">
     95                        <input class="registration_details" id="bt_otpfy_reg_email" style="width:100%;margin-bottom:8px" type="email" placeholder="Email Address" />
     96                    </div>
     97                </div>
     98
    8899                <div class="bt_otpfy_lg_input">
    89100                    <input id="bt_otpfy_vf_code_input" style="width:100%;max-width:100%" type="number" pattern="[0-9]*" inputmode="numeric" placeholder="<?php echo esc_html($settings->get_vf_input_ph()) ?>" />
    90101                </div>
    91102                <div class="bt_otpfy_lg_button">
    92                     <button id="bt_otpfy_vf_code_btn" data-text="<?php echo esc_html($settings->get_vf_button_text()) ?>" class="btn button">
     103                    <button id="bt_otpfy_vf_code_btn"
     104                        data-text-login="<?php echo esc_attr($settings->get_vf_button_text()) ?>"
     105                        data-text-register="Register &amp; Login"
     106                        data-text="<?php echo esc_attr($settings->get_vf_button_text()) ?>"
     107                        class="btn button">
    93108                        <?php echo esc_html($settings->get_vf_button_text()) ?> <span id="bt_otpfy_vf_loader"></span>
    94109                    </button>
     
    110125    </div>
    111126
     127
     128
    112129    <p class="otpfy-form-footer"><?php do_action('otpfy-form-footer'); ?></p>
    113130<?php else :
Note: See TracChangeset for help on using the changeset viewer.