|
| 1 | +var qs = (function (a) { |
| 2 | + if (a == "") return {}; |
| 3 | + var b = {}; |
| 4 | + for (var i = 0; i < a.length; ++i) { |
| 5 | + var p = a[i].split("=", 2); |
| 6 | + if (p.length == 1) b[p[0]] = ""; |
| 7 | + else b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " ")); |
| 8 | + } |
| 9 | + return b; |
| 10 | +})(window.location.search.substr(1).split("&")); |
| 11 | +$(document).ready(function () { |
| 12 | + window.history.forward(); |
| 13 | + const resendToken = qs["resendToken"]; |
| 14 | + const canResend = qs["canResend"]; |
| 15 | + const userId = qs["userId"]; |
| 16 | + let formAction = qs["formAction"] || "#"; |
| 17 | + const opt1 = 'https://auth.{{DOMAIN}}/continue'; |
| 18 | + const opt2 = 'https://{{AUTH0DOMAIN}}/continue'; |
| 19 | + if (!formAction.startsWith(opt1) && !formAction.startsWith(opt2)) { |
| 20 | + // looks like XSS attack |
| 21 | + formAction = "#"; |
| 22 | + return false; |
| 23 | + } |
| 24 | + const apiServerUrl = "https://api.{{DOMAIN}}.com/v3/users"; |
| 25 | + $("#continueBtn").click(function () { |
| 26 | + var otp = $("#otp").val(); |
| 27 | + if (!otp) { |
| 28 | + $("#error").html("Need Password"); |
| 29 | + $("#error").closest(".message").fadeIn(); |
| 30 | + return false; |
| 31 | + } |
| 32 | + $("#error").closest(".message").fadeOut(); |
| 33 | + $("#error").html(""); |
| 34 | + $.ajax({ |
| 35 | + type: "PUT", |
| 36 | + url: apiServerUrl + "/activate", |
| 37 | + contentType: "application/json", |
| 38 | + mimeType: "application/json", |
| 39 | + data: JSON.stringify({ |
| 40 | + "param": { |
| 41 | + userId, resendToken, otp |
| 42 | + } |
| 43 | + }), |
| 44 | + dataType: "json", |
| 45 | + success: function (result) { |
| 46 | + $("#notify").html("Your account is activated"); |
| 47 | + $("#notify").closest(".message").fadeIn(); |
| 48 | + $("#resend-text").hide(); |
| 49 | + $('#verifyOtp').attr('action', formAction); |
| 50 | + $("#state").val(qs["state"]); |
| 51 | + $("#returnUrl").val(qs["returnUrl"]); |
| 52 | + $("#otp").attr('disabled', 'disabled'); |
| 53 | + $("#verifyOtp").submit(); |
| 54 | + }, |
| 55 | + error: function (error) { |
| 56 | + if (error.responseJSON && error.responseJSON.result) { |
| 57 | + $("#error").html(error.responseJSON.result.content); |
| 58 | + $("#error").closest(".message").fadeIn(); |
| 59 | + } else { |
| 60 | + $("#error").html("Unknown Error"); |
| 61 | + $("#error").closest(".message").fadeIn(); |
| 62 | + } |
| 63 | + } |
| 64 | + }); |
| 65 | + return false; |
| 66 | + }); |
| 67 | + if (canResend) { |
| 68 | + $("#resend").click(function () { |
| 69 | + $.ajax({ |
| 70 | + type: "POST", |
| 71 | + url: apiServerUrl + "/resendActivationEmail", |
| 72 | + contentType: "application/json", |
| 73 | + mimeType: "application/json", |
| 74 | + data: JSON.stringify({ |
| 75 | + "param": { |
| 76 | + userId, resendToken |
| 77 | + } |
| 78 | + }), |
| 79 | + dataType: "json", |
| 80 | + success: function (result) { |
| 81 | + $("#notify").html("Email sent"); |
| 82 | + $("#notify").closest(".message").fadeIn(); |
| 83 | + $("#resend-text").hide(); |
| 84 | + }, |
| 85 | + error: function (error) { |
| 86 | + if (error.responseJSON && error.responseJSON.result) { |
| 87 | + $("#error").html(error.responseJSON.result.content); |
| 88 | + $("#error").closest(".message").fadeIn(); |
| 89 | + $("#resend-text").hide(); |
| 90 | + } else { |
| 91 | + $("#error").html("Unknown Error"); |
| 92 | + $("#error").closest(".message").fadeIn(); |
| 93 | + } |
| 94 | + } |
| 95 | + }); |
| 96 | + return false; |
| 97 | + }); |
| 98 | + } else { |
| 99 | + $("#resend-text").hide(); |
| 100 | + } |
| 101 | + |
| 102 | + /** |
| 103 | + * Script for field placeholder |
| 104 | + **/ |
| 105 | + $(".messages .close-error").on("click", function () { |
| 106 | + $(this).closest(".message").fadeOut(); |
| 107 | + }); |
| 108 | + var inputObj = $(".input-field .input-text"), |
| 109 | + continueBtnDisable = false; |
| 110 | + inputObj |
| 111 | + .on("focus", function () { |
| 112 | + $(this).parent().addClass("active focussed"); |
| 113 | + }) |
| 114 | + .on("blur", function () { |
| 115 | + var parentObj = $(this).parent(); |
| 116 | + if ($(this).val() === "") { |
| 117 | + parentObj.removeClass("active"); |
| 118 | + } |
| 119 | + parentObj.removeClass("focussed"); |
| 120 | + }) |
| 121 | + .on("change keydown paste input", function () { |
| 122 | + var disableStatus = false; |
| 123 | + inputObj.each(function (index, element) { |
| 124 | + if ($(element).val() === "") { |
| 125 | + disableStatus = true; |
| 126 | + return; |
| 127 | + } else { |
| 128 | + disableStatus = false; |
| 129 | + return; |
| 130 | + } |
| 131 | + }); |
| 132 | + setContinueButtonDisabledStatus(disableStatus); |
| 133 | + }) |
| 134 | + .each(function (index, element) { |
| 135 | + var parentObj = $(element).parent(); |
| 136 | + if ($(element).val() !== "") { |
| 137 | + parentObj.addClass("active"); |
| 138 | + } else { |
| 139 | + parentObj.removeClass("active"); |
| 140 | + } |
| 141 | + |
| 142 | + if ($(element).val() === "" && continueBtnDisable === false) { |
| 143 | + continueBtnDisable = true; |
| 144 | + } |
| 145 | + |
| 146 | + setContinueButtonDisabledStatus(continueBtnDisable); |
| 147 | + }); |
| 148 | +}); |
| 149 | +function setContinueButtonDisabledStatus(status) { |
| 150 | + var continueBtnObj = $("#continueBtn"); |
| 151 | + if (status) { |
| 152 | + continueBtnObj.attr("disabled", true); |
| 153 | + } else { |
| 154 | + continueBtnObj.removeAttr("disabled"); |
| 155 | + } |
| 156 | +} |
0 commit comments