register.system 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  6. <title>{{host_name}} - Register</title>
  7. <link rel="stylesheet" href="../../script/semantic/semantic.css">
  8. <script type="application/javascript" src="../../script/jquery.min.js"></script>
  9. <script type="application/javascript" src="../../script/semantic/semantic.js"></script>
  10. <style>
  11. .imageRight{
  12. width:100%;
  13. }
  14. </style>
  15. </head>
  16. <body>
  17. <br><br><br>
  18. <div class="ui container" align="center">
  19. <div class="ui basic segment" style="max-width:400px;" align="left">
  20. <div class="imageRight" align="center">
  21. <img class="ui small image" src="data:image/png;base64, {{vendor_logo}}"></img>
  22. </div>
  23. <div class="ui divider"></div>
  24. <div class="ui text container">
  25. <p>Register your account on {{host_name}}</p>
  26. </div>
  27. <div class="ui divider"></div>
  28. <form class="ui form" onsubmit="handleFormSubmit(event, this);">
  29. <div class="field">
  30. <label>Email</label>
  31. <input id="emailfield" type="text" name="email" placeholder="Email">
  32. </div>
  33. <div class="field">
  34. <label>Username</label>
  35. <input type="text" name="username" placeholder="Username">
  36. </div>
  37. <div class="field">
  38. <label>Password</label>
  39. <input type="password" name="password" placeholder="Password">
  40. </div>
  41. <div id="cpw" class="field">
  42. <label>Confirm Password</label>
  43. <input type="password" name="confirmpw" placeholder="Confirm Password">
  44. <small style="display:none; color:#b33a38;">Password does not match</small>
  45. </div>
  46. <div class="field">
  47. <div class="ui checkbox">
  48. <input type="checkbox" tabindex="0" onchange="toggleSignupBox(this.checked)">
  49. <label>I agree to the <a href="../../SystemAO/vendor/public/termsAndConditions.html" target="_blank">Terms and Conditions</a></label>
  50. </div>
  51. </div>
  52. <button disabled="disabled" id="submitbtn" class="ui disabled button" type="submit">Sign Up</button>
  53. </form>
  54. <div id="errmsg" class="ui red inverted segment" style="display:none;">
  55. <i class="remove icon"></i> Internal Server Error
  56. </div>
  57. <div class="ui divider"></div>
  58. <p>Back to <a href="../../">Login</a></p>
  59. </div>
  60. </div>
  61. <div class="ui basic modal">
  62. <div class="ui icon header">
  63. <i class="green checkmark icon"></i>
  64. Account Created
  65. </div>
  66. <div class="content" align="center">
  67. <p>You will be redirected to login interface in 3 secounds...</p>
  68. </div>
  69. <div class="actions">
  70. <a class="ui green ok inverted button" href="../../">
  71. Redirect NOW
  72. </a>
  73. </div>
  74. </div>
  75. <script>
  76. //1. read the parameters from the URL
  77. if(get('user') != undefined){
  78. $("#emailfield").val(get('user'));
  79. $("#emailfield").attr("disabled", "disabled");
  80. $("input[name='username']").val(get('user'));
  81. $("input[name='username']").attr("disabled", "disabled");
  82. }
  83. function toggleSignupBox(toggle){
  84. if (toggle){
  85. $("#submitbtn").removeAttr('disabled');
  86. $("#submitbtn").removeClass('disabled');
  87. }else{
  88. $("#submitbtn").attr('disabled','disabled');
  89. $("#submitbtn").addClass('disabled');
  90. }
  91. }
  92. function handleFormSubmit(e, form){
  93. e.preventDefault();
  94. if (form.password.value != form.confirmpw.value){
  95. //Password not match
  96. $("#cpw").addClass("error");
  97. $("#cpw").find("small").show();
  98. return;
  99. }else{
  100. $("#cpw").removeClass("error");
  101. $("#cpw").find("small").hide();
  102. }
  103. //Check if the user has actually entered an emadil
  104. if (!ValidateEmail(form.email.value)){
  105. $("#emailfield").parent().addClass("error");
  106. return;
  107. }
  108. $.ajax({
  109. url: "./handleRegister.system",
  110. data: {
  111. "email":form.email.value,
  112. "username": form.username.value,
  113. "password": form.password.value,
  114. },
  115. method: "POST",
  116. success: function(data){
  117. console.log(data);
  118. if (data.error !== undefined){
  119. $("#errmsg").html(`<i class="remove icon"></i> ${data.error}`);
  120. $("#errmsg").stop().finish().slideDown("fast").delay(5000).slideUp("fast");
  121. }else{
  122. //Register succeed
  123. $('.ui.modal').modal("show");
  124. setTimeout(function(){
  125. window.location.href = "../../";
  126. },3000);
  127. }
  128. },
  129. error: function(xhr){
  130. alert("Register failed due to Internal Server Error")
  131. },
  132. timeout: 15000
  133. })
  134. }
  135. function ValidateEmail(email){
  136. if (/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/.test(email)){
  137. return true
  138. }else{
  139. return false
  140. }
  141. }
  142. //https://stackoverflow.com/questions/831030/how-to-get-get-request-parameters-in-javascript
  143. function get(name){
  144. if(name=(new RegExp('[?&]'+encodeURIComponent(name)+'=([^&]*)')).exec(location.search))
  145. return decodeURIComponent(name[1]);
  146. }
  147. </script>
  148. </body>
  149. </html>