reset.html 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="robots" content="noindex" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <link rel="icon" type="image/png" href="./favicon.png" />
  8. <title>Account Reset | Zoraxy</title>
  9. <link rel="stylesheet" href="script/semantic/semantic.min.css">
  10. <script type="application/javascript" src="script/jquery-3.6.0.min.js"></script>
  11. <script type="application/javascript" src="script/semantic/semantic.min.js"></script>
  12. <style>
  13. body {
  14. background: rgb(245,245,245);
  15. background: linear-gradient(28deg, rgba(245,245,245,1) 63%, rgba(255,255,255,1) 100%);
  16. }
  17. .background{
  18. position: fixed;
  19. top: 0;
  20. right: 0;
  21. height: 100%;
  22. width: 100%;
  23. opacity: 0.8;
  24. z-index: -99;
  25. background-image: url("img/public/bg2.jpg");
  26. background-size: auto 100%;
  27. background-position: right top;
  28. background-repeat: no-repeat;
  29. overflow-x: hidden;
  30. }
  31. form {
  32. margin:auto;
  33. }
  34. #loginForm{
  35. height: 100%;
  36. background-color: white;
  37. width: 25em;
  38. margin-left: 10em;
  39. margin-top: 0 !important;
  40. margin-bottom: 0 !important;
  41. }
  42. @media all and (max-width: 550px) {
  43. /* CSS rules here for screens lower than 750px */
  44. #loginForm{
  45. width: calc(100% - 4em);
  46. margin-left: 2em;
  47. }
  48. }
  49. #errmsg{
  50. color: #9f3a38;
  51. margin-top: 1em;
  52. margin-bottom: 0.4em;
  53. text-align: left;
  54. }
  55. .backBtn{
  56. position: absolute;
  57. top: 0em;
  58. left: 1em;
  59. margin-top: -4em;
  60. }
  61. </style>
  62. </head>
  63. <body>
  64. <div class="background"></div>
  65. <div id="loginForm" class="ui middle aligned center aligned grid">
  66. <div class="column">
  67. <a class="backBtn" href="/">
  68. <i class="huge black chevron circle left icon"></i>
  69. </a>
  70. <form class="ui large form">
  71. <div class="ui basic segment">
  72. <img class="ui fluid image" src="img/public/logo.svg" style="pointer-events:none;">
  73. <p>Reset Password</p>
  74. <div class="field">
  75. <div class="ui left icon input">
  76. <i class="user icon"></i>
  77. <input id="username" type="text" name="username" placeholder="Username">
  78. </div>
  79. </div>
  80. <div class="field">
  81. <div class="ui left icon input">
  82. <i class="ticket alternate icon"></i>
  83. <input id="token" type="text" name="token" placeholder="Token">
  84. </div>
  85. </div>
  86. <div class="field">
  87. <div class="ui left icon input">
  88. <i class="lock icon"></i>
  89. <input id="magic" type="password" name="New password" placeholder="New Password">
  90. </div>
  91. </div>
  92. <div id="resetBtn" class="ui fluid basic green button">Set New Password</div>
  93. <div id="errmsg" class="ui red message" style="display: none;">
  94. <i class="red remove icon"></i> Unknown Error Occured
  95. </div>
  96. <div id="succmsg" class="ui message" style="display:none;">
  97. <i class="ui green check circle icon"></i> Password Updated. <br><small>Redirecting to <a href="/">login page</a> in 3 seconds</small>
  98. </div>
  99. <div id="countdown" class="ui message" style="color: grey;">
  100. <span id="countdownText"><i class="ui loading circle notch icon"></i> Resend email in <span id="countdown-num">30</span> seconds</span>
  101. <a href="#" id="resendEmailLink" onclick="sendResetAccountEmail();">Resend Email</a>
  102. </div>
  103. </div>
  104. <div class="ui divider"></div>
  105. <small>Proudly powered by Zoraxy</small>
  106. </form>
  107. </div>
  108. </div>
  109. <script>
  110. var redirectionAddress = "/";
  111. var loginAddress = "/api/auth/login";
  112. $(".checkbox").checkbox();
  113. $(document).ready(function(){
  114. var currentdate = new Date();
  115. var datetime = currentdate.getDate() + "/"
  116. + (currentdate.getMonth()+1) + "/"
  117. + currentdate.getFullYear() + " "
  118. + currentdate.getHours() + ":"
  119. + currentdate.getMinutes() + ":"
  120. + currentdate.getSeconds();
  121. $("#requestTime").text(datetime);
  122. //Check if the user already logged in
  123. $.get("/api/auth/checkLogin",function(data){
  124. try{
  125. if (data === true || data.trim() == "true"){
  126. //User already logged in. Redirect to target page.
  127. if (redirectionAddress == ""){
  128. //Redirect back to index
  129. window.location.href = "/";
  130. }else{
  131. console.log(data);
  132. //window.location.href = redirectionAddress;
  133. }
  134. }
  135. }catch(ex){
  136. //Assume not logged in
  137. console.log(data);
  138. }
  139. });
  140. });
  141. //Bind reset password events
  142. $('#resetBtn').on('click', function() {
  143. // Get input values
  144. var username = $('#username').val();
  145. var token = $('#token').val();
  146. var newPassword = $('#magic').val();
  147. // Send POST request with input values as data
  148. $.post('/api/account/new', { username: username, token: token, newpw: newPassword })
  149. .done(function(data) {
  150. // Handle successful response
  151. if (data.error != undefined){
  152. $("#errmsg").html(`<i class="red circle times icon"></i> ` + data.error);
  153. $("#errmsg").show();
  154. }else{
  155. $("#errmsg").hide();
  156. $("#countdown").hide();
  157. $("#succmsg").show();
  158. setTimeout(function(){
  159. window.location.href = "/";
  160. }, 3000);
  161. }
  162. })
  163. .fail(function(error) {
  164. // Handle error response
  165. console.error(error);
  166. });
  167. });
  168. function updateYear() {
  169. const year = new Date().getFullYear();
  170. const elements = document.getElementsByClassName("year");
  171. for (let i = 0; i < elements.length; i++) {
  172. elements[i].textContent = year;
  173. }
  174. }
  175. updateYear();
  176. function startCountdown() {
  177. var count = 30;
  178. var countdownNum = $('#countdown-num');
  179. countdownNum.text(count);
  180. $("#countdownText").show();
  181. $('#resendEmailLink').hide();
  182. var countdownTimer = setInterval(function() {
  183. count--;
  184. if (count === 0) {
  185. clearInterval(countdownTimer);
  186. $("#countdownText").hide();
  187. $('#resendEmailLink').show();
  188. } else {
  189. countdownNum.text(count);
  190. }
  191. }, 1000);
  192. }
  193. //Send account reset email to preset admin account
  194. function sendResetAccountEmail(){
  195. $("#resendEmailLink").html(`<i class="ui loading spinner icon"></i> Sending Email`);
  196. $("#resendEmailLink").css({
  197. "opacity": "0.8",
  198. "pointer-events": "none"
  199. });
  200. $.get("/api/account/reset", function(data){
  201. $("#resendEmailLink").html(`<a href="#" onclick="sendResetAccountEmail();">Resend Email</a>`);
  202. $("#resendEmailLink").css({
  203. "opacity": "1",
  204. "pointer-events": "auto"
  205. });
  206. if (data.error !== undefined){
  207. alert(data.error);
  208. }else{
  209. //Start countdown again
  210. startCountdown();
  211. }
  212. });
  213. }
  214. $(".thisyear").text(new Date().getFullYear());
  215. function updateRenderElements(){
  216. if (window.innerHeight < 520){
  217. $(".bottombar").hide();
  218. }else{
  219. $(".bottombar").show();
  220. }
  221. }
  222. updateRenderElements();
  223. $(window).on("resize", function(){
  224. updateRenderElements();
  225. });
  226. //Start the countdown on redirect
  227. startCountdown();
  228. </script>
  229. </body>
  230. </html>