|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | + <head> |
| 4 | + <meta charset="UTF-8" /> |
| 5 | + <title>UID2 Hashing Tool</title> |
| 6 | + <link rel="stylesheet" type="text/css" href="./app.css" /> |
| 7 | + <link rel="shortcut icon" href="/img/favicon.ico" /> |
| 8 | + <script src="./uid2-sdk-3.3.0.js"></script> |
| 9 | + <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> |
| 10 | + </head> |
| 11 | + <script> |
| 12 | + console.log('Initializing example.'); |
| 13 | + |
| 14 | + async function updateGuiElements(normalizedInput, inputType) { |
| 15 | + console.log('Updating displayed values.'); |
| 16 | + |
| 17 | + if (normalizedInput) { |
| 18 | + const hashedValue = await window.__uid2Helper.hashIdentifier(normalizedInput); |
| 19 | + $('#hashed').text(hashedValue); |
| 20 | + const encodedValue = await window.__uid2Helper.hashAndEncodeIdentifier(normalizedInput); |
| 21 | + $('#base64_encoded').text(encodedValue); |
| 22 | + } |
| 23 | + else { |
| 24 | + $('#hashed').text(' '); |
| 25 | + $('#base64_encoded').text(' '); |
| 26 | + if (inputType === "email") { |
| 27 | + $("#normalization_value").text(' '); |
| 28 | + $('#alert_box_email').show(); |
| 29 | + } |
| 30 | + else if (inputType === "mobile") { |
| 31 | + $('#alert_box_mobile').show(); |
| 32 | + } |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + function clearElements() { |
| 37 | + document.querySelector('.input_value').value = ""; |
| 38 | + $('#normalization_value').text(' '); |
| 39 | + $('#hashed').text(' '); |
| 40 | + $('#base64_encoded').text(' '); |
| 41 | + $('.alert').hide(); |
| 42 | + } |
| 43 | + |
| 44 | + function onDocumentReady() { |
| 45 | + console.log('Setting up interface handlers.'); |
| 46 | + clearElements(); |
| 47 | + document.querySelector('.input_value').placeholder = "Enter an email address"; |
| 48 | + $('#enter').click(handleEnter); |
| 49 | + $('#clear_values_form').click(clearElements); |
| 50 | + $('#clear_values_form').show(); |
| 51 | + } |
| 52 | + |
| 53 | + function handleRadioClick(radioButton) { |
| 54 | + clearElements(); |
| 55 | + const inputType = radioButton.value; |
| 56 | + let placeholder = ""; |
| 57 | + if (inputType == "email") { |
| 58 | + placeholder = "Enter an email address"; |
| 59 | + $('#normalization').show(); |
| 60 | + $('#alert_email').show(); |
| 61 | + $('#alert_mobile').hide(); |
| 62 | + } |
| 63 | + else if (inputType == "mobile") { |
| 64 | + placeholder = "Enter a phone number"; |
| 65 | + $('#normalization').hide(); |
| 66 | + $('#alert_email').hide(); |
| 67 | + $('#alert_mobile').show(); |
| 68 | + } |
| 69 | + document.querySelector('.input_value').placeholder = placeholder; |
| 70 | + } |
| 71 | + |
| 72 | + async function handleEnter() { |
| 73 | + $('.alert').hide(); |
| 74 | + const inputValue = $('#input_value').val(); |
| 75 | + const inputType = document.querySelector('input[name="toggle_input_type"]:checked').value; |
| 76 | + let normalizedInput = undefined; |
| 77 | + if (inputType == "mobile") { |
| 78 | + const isNormalizedPhone = window.__uid2Helper.isNormalizedPhone(inputValue) |
| 79 | + if (isNormalizedPhone) { |
| 80 | + normalizedInput = inputValue; |
| 81 | + } |
| 82 | + } |
| 83 | + if (inputType === "email") { |
| 84 | + normalizedInput = window.__uid2Helper.normalizeEmail(inputValue); |
| 85 | + $('#normalization_value').text(normalizedInput); |
| 86 | + } |
| 87 | + updateGuiElements(normalizedInput, inputType); |
| 88 | + } |
| 89 | + |
| 90 | + $(document).ready(onDocumentReady); |
| 91 | + |
| 92 | + </script> |
| 93 | + <body> |
| 94 | + <h1>UID2 Hashing Tool</h1> |
| 95 | + <p class="intro"> |
| 96 | + Use this tool to verify that your own implementation is normalizing and |
| 97 | + encoding correctly. Choose Email or Phone Number, then type or paste the |
| 98 | + value and click Enter. <br><br> |
| 99 | + <b>NOTE:</b> Normalize phone numbers before using the tool. |
| 100 | + For details and examples, see <a href="https://unifiedid.com/docs/getting-started/gs-normalization-encoding">Normalization and Encoding</a>. |
| 101 | + </p> |
| 102 | + |
| 103 | + <input type="radio" id="toggle_email" name="toggle_input_type" value="email" onclick="handleRadioClick(this)" checked> |
| 104 | + <label for="html">Email</label> |
| 105 | + <input type="radio" id="toggle_mobile" name="toggle_input_type" value="mobile" onclick="handleRadioClick(this)"> |
| 106 | + <label for="css">Phone Number</label><br> |
| 107 | + |
| 108 | + <div id="input_value_form" class="form"> |
| 109 | + <div class="prompt"> |
| 110 | + <input |
| 111 | + type="text" |
| 112 | + id="input_value" |
| 113 | + class="input_value" |
| 114 | + name="input_value" |
| 115 | + placeholder="" |
| 116 | + /> |
| 117 | + </div> |
| 118 | + |
| 119 | + <div class="alert" id="alert_box_email"> |
| 120 | + <span class="closebtn" onclick="this.parentElement.style.display='none';">×</span> |
| 121 | + Email format is invalid. |
| 122 | + </div> |
| 123 | + <div class="alert" id="alert_box_mobile"> |
| 124 | + <span class="closebtn" onclick="this.parentElement.style.display='none';">×</span> |
| 125 | + Phone number format is invalid or is not normalized. |
| 126 | + </div> |
| 127 | + <br> |
| 128 | + </div> |
| 129 | + <div><button type="button" class="button" id="enter">Enter</button></div> |
| 130 | + <br><br><br> |
| 131 | + <div> |
| 132 | + <div id="normalization"> |
| 133 | + <h3 class="label" id="normalization_label">Normalized Value:</h3> |
| 134 | + <h4 class="value"><pre id="normalization_value"></pre></h4> |
| 135 | + </div> |
| 136 | + |
| 137 | + <h3 class="label">Hashed Value:</h3> |
| 138 | + <h4 class="value"><pre id="hashed"></pre></h4> |
| 139 | + |
| 140 | + <h3 class="label">Base64-encoded Value:</h3> |
| 141 | + <h4 class="value"><pre id="base64_encoded"></pre></h4> |
| 142 | + |
| 143 | + </div> |
| 144 | + </div> |
| 145 | + |
| 146 | + |
| 147 | + </div> |
| 148 | + <div id="clear_values_form" style="display: none" class="form"> |
| 149 | + <form> |
| 150 | + <button type="button" class="button" id="clear_values">Clear</button> |
| 151 | + </form> |
| 152 | + </div> |
| 153 | + </div> |
| 154 | + </body> |
| 155 | +</html> |
0 commit comments