PageSourceSearch

https://fezana.org/wp-content/plugins/customer-email-verification-…/assets/js/signup-script.js?ver=1790941707

js fezana.org collected 2026-10-02 11:49:38 UTC 10,219 bytes, 264 lines download raw bytes

1jQuery(document).ready(function($) {
2    if (cev_ajax.enableEmailVerification) {
3        var otpVerified = false;
4
5        function displayError(message) {
6            var $form = $('#customer_login');
7            $form.prepend('<div class="woocommerce-error">' + message + '</div>');
8        }
9
10        function clearErrors() {
11            $('.woocommerce-error').remove();
12        }
13
14        // Set the value of email_verification hidden field to false
15        $('input[name="email_verification"]').val('false');
16        
17        // Add a class to the register button if email_verification is false
18        $('button[name="register"]').addClass('email_verification_popup');
19
20        // Track in-flight requests so a second click can never fire a second
21        // verification email while the first request is still running.
22        var cevRegisterInFlight = false;
23        var cevButtonLabel = '';
24
25        function getButtonLabel($button) {
26            return $button.is('input') ? $button.val() : $button.text();
27        }
28
29        function setButtonLabel($button, label) {
30            if ($button.is('input')) {
31                $button.val(label);
32            } else {
33                $button.text(label);
34            }
35        }
36
37        // Put the register button into its processing state and show the loader.
38        function startProcessing($button) {
39            cevRegisterInFlight = true;
40            cevButtonLabel = getButtonLabel($button);
41            setButtonLabel($button, cev_ajax.cev_processing);
42            $button.addClass('cev_processing').prop('disabled', true);
43            $('.cev_loading_overlay').css('display', 'block');
44        }
45
46        // Restore the register button so the customer can act again.
47        function stopProcessing($button) {
48            cevRegisterInFlight = false;
49            if (cevButtonLabel) {
50                setButtonLabel($button, cevButtonLabel);
51            }
52            $button.removeClass('cev_processing').prop('disabled', false);
53            $('.cev_loading_overlay').css('display', 'none');
54        }
55
56        // Handle the register button click event
57        $(document).on('click', '.email_verification_popup', function(e) {
58            if (!otpVerified && $(this).hasClass('email_verification_popup')) {
59                e.preventDefault();
60
61                // Ignore repeat clicks while the first request is still running.
62                if (cevRegisterInFlight) {
63                    return;
64                }
65
66                clearErrors();
67                var $button = $(this);
68
69                var $form = $(this).closest('form');
70                var email = $form.find('#reg_email').val();
71                var password = $form.find('#reg_password').val();
72
73                if (!email) {
74                    displayError(cev_ajax.cev_email_validation);
75                    return;
76                }
77                if (cev_ajax.password_setup_link_enabled == "no") {
78                    if (!password) {
79                        displayError(cev_ajax.cev_password_validation);
80                        return;
81                    }
82                }
83
84                startProcessing($button);
85
86                // AJAX request to check if the email is already registered
87                $.ajax({
88                    url: cev_ajax.ajax_url,
89                    type: 'POST',
90                    data: $('.woocommerce-form-register').serialize() + '&action=check_email_exists&nonce=' + cev_ajax.nonce,
91                    success: function(response) {
92                        var data = (response && response.data) ? response.data : {};
93
94                        if (data.exists) {
95                            displayError(cev_ajax.cev_email_exists_validation);
96                            stopProcessing($button);
97                        } else if (data.not_valid) {
98                            displayError(cev_ajax.cev_valid_email_validation);
99                            stopProcessing($button);
100                        } else if (data.already_verify) {
101                            // Re-enable the button first, otherwise the synthetic
102                            // click below cannot submit the form.
103                            stopProcessing($button);
104                            $form.find('button[name="register"]').removeClass('email_verification_popup');
105                            $form.find('input[name="email_verification"]').val('true');
106                            $form.find('button[name="register"]').trigger('click');
107                        } else if (data.email) {
108                            stopProcessing($button);
109                            $('#otp-popup').show();
110                        } else if (data.validation == false) {
111                            displayError(data.message);
112                            stopProcessing($button);
113                        } else {
114                            stopProcessing($button);
115                        }
116                    },
117                    error: function(xhr, status, error) {
118                        displayError(cev_ajax.cev_error_prefix + ' ' + error);
119                        stopProcessing($button);
120                    }
121                });
122            }
123        });
124
125        // OTP input handling
126        $('.otp-input').on('input', function() {
127            var $this = $(this);
128            var index = $this.index();
129          
130            if ($this.val().length === 1) {
131                if (index < $('.otp-input').length - 1) {
132                    $('.otp-input').eq(index + 1).focus();
133                } else {
134                    $('#verify-otp-button').trigger('click');
135                }
136            }
137        });
138
139        $('.otp-input').on('keydown', function(e) {
140            var $this = $(this);
141            var index = $this.index();
142
143            if (e.keyCode === 8 && $this.val().length === 0) {
144                if (index > 0) {
145                    $('.otp-input').eq(index - 1).focus();
146                }
147            }
148        });
149
150        $('.otp-input').on('keypress', function(e) {
151            var charCode = (e.which) ? e.which : e.keyCode;
152            if (charCode < 48 || charCode > 57) {
153                e.preventDefault();
154            }
155        });
156
157        var cevOtpInFlight = false;
158
159        $('#verify-otp-button').on('click', function(event) {
160            event.preventDefault(); // Prevents page reload
161
162            // Ignore repeat clicks while a verification request is running.
163            if (cevOtpInFlight) {
164                return;
165            }
166           
167            function getOtpValue() {
168                var otp = '';
169                $('.otp-input').each(function() {
170                    otp += $(this).val();
171                });
172                return otp;
173            }
174
175            var $form = $('.email_verification_popup').closest('form');
176            var email = $form.find('#reg_email').val();
177            var otp = getOtpValue();
178
179            cevOtpInFlight = true;
180
181            // Verify OTP using AJAX
182            $.ajax({
183                url: cev_ajax.ajax_url,
184                type: 'POST',
185                data: {
186                    action: 'verify_otp',
187                    otp: otp,
188                    email: email,
189                    nonce: cev_ajax.nonce 
190                },
191                success: function(response) {
192                   
193                    if (response.success) {
194                        
195                        if (response.data.verified) {
196                            $('#otp-popup').hide();
197
198                            $('<p class="success-message">' + cev_ajax.cev_verified_success + '</p>').insertBefore($form);
199
200                            // Make sure the button is enabled before the synthetic
201                            // click, otherwise the form cannot be submitted.
202                            $form.find('button[name="register"]').removeClass('email_verification_popup cev_processing').prop('disabled', false);
203                            $form.find('input[name="email_verification"]').val('true');
204                            $form.find('button[name="register"]').trigger('click');
205                        } else {
206                            displayError(response.data.message);
207                        }
208                    } else {
209                        $('.error_mesg').text(response.data.message).css('display', 'block');
210                    }
211                },
212                error: function(xhr, status, error) {
213                    displayError(cev_ajax.cev_error_prefix + ' ' + error);
214                },
215                complete: function() {
216                    cevOtpInFlight = false;
217                }
218            });
219        });
220
221        var cevResendInFlight = false;
222
223        $('.send_again_link').on('click', function() {
224            // Ignore repeat clicks while a resend request is running.
225            if (cevResendInFlight) {
226                return;
227            }
228
229            var $form = $('.woocommerce-form-register__submit').closest('form');
230            var email = $form.find('#reg_email').val();
231
232            cevResendInFlight = true;
233
234            $.ajax({
235                url: cev_ajax.ajax_url,
236                type: 'POST',
237                data: {
238                    action: 'resend_otp',
239                    email: email,
240                    nonce: cev_ajax.nonce 
241                },
242                success: function(response) {
243                    if (response.data.email) {
244                        $('.resend_sucsess').show();
245                        setTimeout(function() {
246                            $('.resend_sucsess').hide();
247                        }, 5000); // Hide after 5 seconds
248                    } else {
249                        console.log('No email found in response.data');
250                    }
251                },
252                error: function(xhr, status, error) {
253                    displayError(cev_ajax.cev_error_prefix + ' ' + error);
254                },
255                complete: function() {
256                    cevResendInFlight = false;
257                }
258            });
259        });
260    }
261    $(document).on('click', '.back_btn', function(e) {
262        $('#otp-popup').hide();
263    });
264});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.