Built files from Bizgaze WebServer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

registeruser.js 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  2. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  3. return new (P || (P = Promise))(function (resolve, reject) {
  4. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  5. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  6. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  7. step((generator = generator.apply(thisArg, _arguments || [])).next());
  8. });
  9. };
  10. var Unibase;
  11. (function (Unibase) {
  12. let Themes;
  13. (function (Themes) {
  14. let Compact;
  15. (function (Compact) {
  16. let Components;
  17. (function (Components) {
  18. class RegisterUser extends Unibase.Platform.Core.BaseComponent {
  19. jsFiles() {
  20. return ["tenants/themes/compact/index.anonymous.js", "platform/membership/managers/accountmanager.js", "libs/passwordrequirement/passwordrequirement.js"];
  21. }
  22. cssFiles() {
  23. return ["libs/passwordrequirement/passwordrequirement.css"];
  24. }
  25. html(id, containerid) {
  26. if (jQuery("#external-form").length === 0) {
  27. var index = new Components.Index_Anonymous();
  28. index.init(null);
  29. }
  30. const html = `<div><form id="frm_RegisterUser" default="" data-validate="parsley" data-isdynamic="false"><div id="div_ValidationSummary"></div><div id="div_RegisterUser"><h1 class="display-4 mb-30 text-dark-100 text-center">Registration</h1><div class="alert alert-primary d-none">We will send new code to your <a href=""><u>Email or Phone</u></a> to create your password.</div><div class="form-group"><input class="form-control" required autocomplete="off" placeholder="Enter Registered Email or Phone" id="txt_EmailorPhone" type="text"></div>
  31. <div class="form-group floating-label-form-group floating-label-form-group-with-value focus" id="div_TenantsAutoComplete">
  32. <select id="ddl_Tenant" class="form-control value-control" data-isdynamic="false"></select></div><button class="btn btn-primary btn-block" type="button" id="btn_SendOtp">Confirm</button><p class="text-right mt-20"><a href="Index.html#/login">Back to login</a></p></div><div id="div_CreatePswd" class="d-none"><h1 class="display-5 mb-30 text-center">Create your Password</h1><div class="form-group"><label class="form-control" id="lbl_Email"></label></div><div class="form-group"><input class="form-control pr-password " required id="txt_NewPswd" placeholder="New password" type="password" autocomplete="new-password"><span toggle="#txt_NewPswd" id="passwordHide" class="fa fa-eye-slash font-15 mr-10 field-icon"></span><div class="showpwsdreq"></div></div><div class="form-group"><input class="form-control" required id="txt_ConfirmPswd" placeholder="Re-enter new password" type="password" autocomplete="new-password"><span toggle="#txt_ConfirmPswd" id="confirmPasswordHide" class="fa fa-eye-slash font-15 mr-10 field-icon"></span></div><button class="btn btn-primary btn-block mb-20" type="button" id="btn_CreatePswd">Create Password</button><p class="text-right"><a href="Index.html#/login">Back to login</a></p></div><div id="div_SuccessMsg" class="d-none"><div class="d-62 bg-white rounded-circle mb-10 d-flex align-items-center justify-content-center mx-auto"><i class="fa fa-check font-50 text-success"></i></div><h1 class="display-4 mb-20 text-center">Password Created Successfully</h1><p class="text-center"><a href="Index.html#/login">Click here to Login</a></p></div></form><div id="modal_Otp" class="modal fade hide"><div class="modal-dialog"><div class="modal-content"><div class="modal-header mt-2 mb-2"><h5 class="modal-title pull-left">Mobile or Email Verification</h5><button type="button" class="btn btn-primary btn-simple pull-right" data-dismiss="modal" aria-hidden="true" >&times;</button></div><div class="modal-body" id="div_modalbody"><div class="mb-10"><p class="lbl_Otp">We have sent OTP on your Mobile Number and Email!</p></div><div class="floating-label-form-group mb-2"><input class="form-control" id ="txt_Otp" placeholder="Enter Mobile OTP/Email OTP" type="password" autocomplete="new-password"><span toggle="#txt_Otp" id="OtpHide" class="fa fa-eye-slash font-15 mr-10 field-icon"></span></div></div><div class="modal-footer mb-2" style="display:block"><button type = "button" class="btn btn-primary pull-left" id="btn_ResendOtp">Resend</button><button type = "button" class="btn btn-primary pull-right" id="btn_VerifyOtp">Verify</button></div></div></div></div></div>`;
  33. return html;
  34. }
  35. load(id, containerid, callback) {
  36. return __awaiter(this, void 0, void 0, function* () {
  37. this._accountManager = yield Unibase.Platform.Membership.Managers.AccountManager.Instance();
  38. yield this.loadTenants(callback);
  39. jQuery(".preloader-it").delay(500).fadeOut("slow");
  40. jQuery("#external-container").delay(500).fadeIn("slow");
  41. jQuery("#bizgaze_body").css("background-color", "#f4f6f7");
  42. $("#div_modalbody").removeAttr("style");
  43. $(".pr-password").click(function () {
  44. var signUpPswd = $(".pr-password");
  45. signUpPswd.passwordRequirements({
  46. numCharacters: 8,
  47. useLowercase: true,
  48. useUppercase: true,
  49. useNumbers: true,
  50. useSpecial: true
  51. });
  52. });
  53. $("#passwordHide").click(function () {
  54. var input = $('#txt_NewPswd');
  55. input.attr('type') == "password" ? input.attr('type', 'text') : input.attr('type', 'password');
  56. $("#passwordHide").toggleClass('fa-eye-slash fa-eye');
  57. });
  58. $("#confirmPasswordHide").click(function () {
  59. var input = $('#txt_ConfirmPswd');
  60. input.attr('type') == "password" ? input.attr('type', 'text') : input.attr('type', 'password');
  61. $('#confirmPasswordHide').toggleClass('fa-eye-slash fa-eye');
  62. });
  63. $("#OtpHide").click(function () {
  64. var input = $('#txt_Otp');
  65. input.attr('type') == "password" ? input.attr('type', 'text') : input.attr('type', 'password');
  66. $('#OtpHide').toggleClass('fa-eye-slash fa-eye');
  67. });
  68. $("#txt_EmailorPhone").keypress(function (e) {
  69. if (e.which == 13)
  70. document.getElementById("btn_SendOtp").click();
  71. });
  72. $("#txt_Otp").keypress(function (e) {
  73. if (e.which == 13)
  74. document.getElementById("btn_VerifyOtp").click();
  75. });
  76. $("#txt_NewPswd,#txt_ConfirmPswd").keypress(function (e) {
  77. if (e.which == 13)
  78. document.getElementById("btn_CreatePswd").click();
  79. });
  80. var instance = this;
  81. $("#btn_SendOtp").click(function () {
  82. instance.validate();
  83. });
  84. $("#btn_CreatePswd").click(function () {
  85. instance.createPassword();
  86. });
  87. $("#btn_VerifyOtp").click(function () {
  88. instance.verifyOtp();
  89. });
  90. $("#btn_ResendOtp").click(function () {
  91. instance.sendOtp(instance.OtpId);
  92. });
  93. if (callback != null)
  94. callback();
  95. });
  96. }
  97. loadTenants(callback) {
  98. var instance = this;
  99. instance._accountManager.getTenants().then(function (response) {
  100. var res = response;
  101. let cmbLob = document.getElementById('ddl_Tenant');
  102. $('#ddl_Tenant').empty();
  103. $('#ddl_Tenant').append('<option value=0>Select Tenant</option>');
  104. for (var i = 0; i < response.result.length; i++) {
  105. var data = response.result[i];
  106. var opt = document.createElement("option");
  107. var Name = data.tenantName;
  108. var id = data.tenantId;
  109. opt.text = Name;
  110. opt.value = id;
  111. cmbLob.append(opt);
  112. }
  113. if (res.result.filter(x => x.isTemplateDb == false).length == 1) {
  114. var Id = $('#ddl_Tenant option[value=' + res.result.filter(x => x.isTemplateDb == false)[0].tenantId + ']');
  115. Id.attr("selected", true);
  116. $("#ddl_Tenant").prop('disabled', true);
  117. }
  118. if (callback != null) {
  119. callback();
  120. }
  121. });
  122. }
  123. validate() {
  124. $(".lbl_Otp").text("");
  125. $("#txt_Otp").val('');
  126. $("#div_ValidationSummary").empty();
  127. var phoneOrEmail = $("#txt_EmailorPhone").val();
  128. var tenantId = $("#ddl_Tenant option:selected").val();
  129. if (phoneOrEmail == "" && tenantId == 0) {
  130. MessageHelper.Instance().showError("Please enter Email/Phone and select a Tenant !", "div_ValidationSummary");
  131. return false;
  132. }
  133. if (phoneOrEmail == "") {
  134. MessageHelper.Instance().showError("Email or Phone cannot be Empty!", "div_ValidationSummary");
  135. return false;
  136. }
  137. if (tenantId == 0) {
  138. MessageHelper.Instance().showError("Please select a Tenant", "div_ValidationSummary");
  139. return false;
  140. }
  141. else {
  142. var instance = this;
  143. instance._accountManager.getContact(phoneOrEmail, tenantId).then(function (response) {
  144. if (response.result != null) {
  145. instance.Email = response.result.emailAddress;
  146. instance.ContactNumber = response.result.phoneNumber;
  147. instance.UserName = response.result.unibaseId;
  148. instance.TenantId = response.result.tenantId;
  149. instance.ContactName = response.result.userName;
  150. $(".lbl_Otp").removeClass('text-danger text-success').text("We have sent OTP on your Mobile Number and Email !");
  151. $("#txt_Otp").val('');
  152. $("#div_ValidationSummary").empty();
  153. instance.sendOtp(0);
  154. }
  155. else {
  156. MessageHelper.Instance().showError(response.message, "div_ValidationSummary");
  157. }
  158. });
  159. }
  160. }
  161. sendOtp(IsResend) {
  162. var instance = this;
  163. $(".preloader-it").fadeIn();
  164. var postData = {
  165. ContactOrEmail: $("#txt_EmailorPhone").val(),
  166. FirstName: instance.ContactName,
  167. LastName: "",
  168. ContactNumber: "",
  169. Email: "",
  170. TenantName: "",
  171. IsSignup: false,
  172. IsForgotPswd: false,
  173. IsRegisterUser: true,
  174. UnibaseId: instance.UserName,
  175. OtpId: IsResend,
  176. UserOtp: ""
  177. };
  178. instance._accountManager.sendOtp(postData).then(function (response) {
  179. if (IsResend != 0) {
  180. $(".lbl_Otp").text("OTP has been Resent!").removeClass('text-danger', '').addClass('text-success', '');
  181. }
  182. if (response == 0) {
  183. $(".preloader-it").delay(200).fadeOut("slow");
  184. MessageHelper.Instance().showError("Some Error has occurred!", 'div_ValidationSummary');
  185. }
  186. else {
  187. instance.OtpId = response;
  188. $("#modal_Otp").modal("show");
  189. $(".preloader-it").delay(200).fadeOut("slow");
  190. }
  191. }, function () {
  192. $(".preloader-it").delay(200).fadeOut("slow");
  193. MessageHelper.Instance().showError("Some Error has occurred!", 'div_ValidationSummary');
  194. });
  195. }
  196. verifyOtp() {
  197. var instance = this;
  198. if ($("#txt_Otp").val() == "")
  199. $(".lbl_Otp").text("Please Enter OTP!").addClass('text-danger', '');
  200. else {
  201. var postData = {
  202. FirstName: "",
  203. LastName: "",
  204. ContactNumber: "",
  205. Email: "",
  206. TenantName: "",
  207. ContactOrEmail: "",
  208. IsForgotPswd: false,
  209. IsRegisterUser: false,
  210. IsSignup: true,
  211. UnibaseId: "",
  212. OtpId: instance.OtpId,
  213. UserOtp: $("#txt_Otp").val(),
  214. };
  215. instance._accountManager.verifyOtp(postData).then(function (response) {
  216. if (response.code.toString() == "2") {
  217. $(".preloader-it").delay(200).fadeOut("slow");
  218. $(".lbl_Otp").text("Otp Expired, Please click on Resend to get new OTP").addClass('text-danger', '');
  219. $("#txt_Otp").val('');
  220. }
  221. else if (response.result != null) {
  222. if (response.result.contactConfirmed == false && response.result.emailConfirmed == false) {
  223. $(".preloader-it").delay(200).fadeOut("slow");
  224. $(".lbl_Otp").text("Invalid OTP!").addClass('text-danger', '');
  225. $("#txt_Otp").text('');
  226. }
  227. else {
  228. $(".preloader-it").fadeIn();
  229. $("#div_RegisterUser").addClass('d-none');
  230. $("#modal_Otp").modal("hide");
  231. $(".preloader-it").delay(200).fadeOut("slow");
  232. $("#lbl_Email").text($("#txt_EmailorPhone").val());
  233. $("#div_CreatePswd").removeClass('d-none');
  234. }
  235. }
  236. });
  237. }
  238. }
  239. createPassword() {
  240. var instance = this;
  241. $("#div_ValidationSummary").empty();
  242. var confirmPassword = $("#txt_ConfirmPswd").val();
  243. var password = $("#txt_NewPswd").val();
  244. if (password.length == 0 || confirmPassword.length == 0) {
  245. MessageHelper.Instance().showError("Password fields cannot be empty!", 'div_ValidationSummary');
  246. return false;
  247. }
  248. if (password.length < 8 || confirmPassword.length < 8) {
  249. MessageHelper.Instance().showError("Password must be atleast 8 characters!", 'div_ValidationSummary');
  250. return false;
  251. }
  252. if (password != confirmPassword) {
  253. MessageHelper.Instance().showError("New and Confirm Passwords doesn't match!", "div_ValidationSummary");
  254. return false;
  255. }
  256. var password = password;
  257. var decimal = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9])(?!.*\s).{8,15}$/;
  258. var checkpassword = password.match(decimal) ? true : false;
  259. if (checkpassword == false) {
  260. $(".pr-password").focus();
  261. MessageHelper.Instance().showError("Please Match the Password in requested Format", "div_ValidationSummary");
  262. return false;
  263. }
  264. var postData = {
  265. Password: $("#txt_NewPswd").val(),
  266. UserName: instance.UserName,
  267. Email: instance.Email,
  268. ContactNumber: instance.ContactNumber,
  269. TenantId: instance.TenantId,
  270. };
  271. instance._accountManager.registerUser(postData).then(function (response) {
  272. if (response.errors == null) {
  273. $("#div_CreatePswd").addClass('d-none');
  274. $("#div_SuccessMsg").removeClass('d-none');
  275. MessageHelper.Instance().showSuccess("Password Created Successfully", 'div_ValidationSummary');
  276. }
  277. else {
  278. $(".preloader-it").delay(200).fadeOut("slow");
  279. MessageHelper.Instance().showError(response.errors[0], "div_ValidationSummary");
  280. }
  281. });
  282. }
  283. submit() {
  284. }
  285. static Instance() {
  286. return new RegisterUser();
  287. }
  288. }
  289. Components.RegisterUser = RegisterUser;
  290. })(Components = Compact.Components || (Compact.Components = {}));
  291. })(Compact = Themes.Compact || (Themes.Compact = {}));
  292. })(Themes = Unibase.Themes || (Unibase.Themes = {}));
  293. })(Unibase || (Unibase = {}));