JSFiddle - React, Tailwind, and code Playground

by kidino

HTML

<input type="text" id="email"><br />
    <button id="send_email">Send in Email</button>

JavaScript

var key = 'kpmbbt2014';
$('#send_email').on('click', function(){
    if (!validateEmail( $('#email').val() )) {
        alert("invalid email address");
    } else {
        $.ajax({
            method:'POST',
            url:'https://api.e-sentral.com/index.php/kpm/email_download',
            dataType: 'json',
            data: {
                email: $('#email').val(),
                hash: md5(key+$('#email').val()),
                doc: 'sejarah022014'
            }
        })
        .done(function(data){
            if (data.status == 'error') {
                alert('ERROR! '+data.error_message);
            } else {
                alert('Printable version will be arriving in your email soon.');
            }
            $('#send_email').removeAttr('disabled');
            
        })
        .fail(function(data){
            alert('There could be a problem with your Internet connection');
            $('#send_email').removeAttr('disabled');
        });
        
        $('#send_email').attr('disabled', 'disabled');
    }

});

/* ===== MD5 FUNCTIONS BELOW =============== */

function validateEmail(email) { 
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(email);
} 

function md5cycle(x, k) {
var a = x[0], b = x[1], c = x[2], d = x[3];

a = ff(a, b, c, d, k[0], 7, -680876936);
d = ff(d, a, b, c, k[1], 12, -389564586);
c = ff(c, d, a, b, k[2], 17,  606105819);
b = ff(b, c, d, a, k[3], 22, -1044525330);
a = ff(a, b, c, d, k[4], 7, -176418897);
d = ff(d, a, b, c, k[5], 12,  1200080426);
c = ff(c, d, a, b, k[6], 17, -1473231341);
b = ff(b, c, d, a, k[7], 22, -45705983);
a = ff(a, b, c, d, k[8], 7,  1770035416);
d = ff(d, a, b, c, k[9], 12, -1958414417);
c = ff(c, d, a, b, k[10], 17, -42063);
b = ff(b, c, d, a, k[11], 22, -1990404162);
a = ff(a, b, c, d, k[12], 7,  1804603682);
d = ff(d, a, b, c, k[13], 12, -40341101);
c...