reset.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="zoraxy.csrf.Token" content="{{.csrfToken}}">
  6. <meta name="robots" content="noindex" />
  7. <meta name="viewport" content="width=device-width, initial-scale=1">
  8. <link rel="icon" type="image/png" href="./favicon.png" />
  9. <title>Account Reset | Zoraxy</title>
  10. <link rel="stylesheet" href="script/semantic/semantic.min.css">
  11. <link href="script/aos.css" rel="stylesheet">
  12. <script src="script/aos.js"></script>
  13. <script type="application/javascript" src="script/jquery-3.6.0.min.js"></script>
  14. <script type="application/javascript" src="script/semantic/semantic.min.js"></script>
  15. <style>
  16. body {
  17. background: rgb(38,60,71);
  18. background: linear-gradient(215deg, rgba(38,60,71,1) 13%, rgba(2,3,42,1) 84%);
  19. }
  20. .background{
  21. position: fixed;
  22. top: 0;
  23. right: 0;
  24. height: 100%;
  25. width: 100%;
  26. opacity: 0.8;
  27. z-index: -99;
  28. background-image: url("img/public/bg2.jpg");
  29. background-size: auto 100%;
  30. background-position: right top;
  31. background-repeat: no-repeat;
  32. overflow-x: hidden;
  33. }
  34. form {
  35. margin:auto;
  36. }
  37. #errmsg{
  38. color: #9f3a38;
  39. margin-top: 1em;
  40. margin-bottom: 0.4em;
  41. text-align: left;
  42. }
  43. .backBtn{
  44. position: absolute;
  45. top: 0em;
  46. left: 2em;
  47. transition: opacity 0.3s linear;
  48. }
  49. .backBtn:hover{
  50. opacity: 0.8;
  51. }
  52. #loginForm {
  53. border-radius: 1em;
  54. width: 25em;
  55. height: 550px;
  56. position: absolute; /*Can also be `fixed`*/
  57. left: 0;
  58. right: 0;
  59. top: 0;
  60. bottom: 0;
  61. margin: auto;
  62. /*Solves a problem in which the content is being cut when the div is smaller than its' wrapper:*/
  63. max-width: 100%;
  64. max-height: 100%;
  65. overflow: auto;
  66. background-color: white;
  67. }
  68. .wavebase {
  69. position:fixed;
  70. bottom: 0;
  71. left: 0;
  72. width: 100%;
  73. height:5vh;
  74. text-align:center;
  75. padding-top: 1em;
  76. background-color: white;
  77. }
  78. /*
  79. Waves CSS
  80. */
  81. #wavesWrapper{
  82. position: fixed;
  83. bottom: 5vh;
  84. width: 100%;
  85. left: 0;
  86. }
  87. .waves {
  88. position:relative;
  89. width: 100%;
  90. height:15vh;
  91. margin-bottom:-7px; /*Fix for safari gap*/
  92. min-height:100px;
  93. max-height:150px;
  94. }
  95. .parallax > use {
  96. animation: move-forever 25s cubic-bezier(.55,.5,.45,.5) infinite;
  97. }
  98. .parallax > use:nth-child(1) {
  99. animation-delay: -8s;
  100. animation-duration: 28s;
  101. }
  102. .parallax > use:nth-child(2) {
  103. animation-delay: -12s;
  104. animation-duration: 40s;
  105. }
  106. .parallax > use:nth-child(3) {
  107. animation-delay: -16s;
  108. animation-duration: 52s;
  109. }
  110. .parallax > use:nth-child(4) {
  111. animation-delay: -20s;
  112. animation-duration: 80s;
  113. }
  114. @keyframes move-forever {
  115. 0% {
  116. transform: translate3d(-90px,0,0);
  117. }
  118. 100% {
  119. transform: translate3d(85px,0,0);
  120. }
  121. }
  122. /*Shrinking for mobile*/
  123. @media (max-width: 768px) {
  124. .waves {
  125. height:40px;
  126. min-height:40px;
  127. }
  128. }
  129. </style>
  130. </head>
  131. <body>
  132. <div id="loginForm" class="ui middle aligned center aligned grid" data-aos="fade-up">
  133. <div class="column">
  134. <form class="ui large form">
  135. <div class="ui basic segment">
  136. <img class="ui fluid image" src="img/public/logo.svg" style="pointer-events:none;">
  137. <p>Reset Password</p>
  138. <div class="field">
  139. <div class="ui left icon input">
  140. <i class="user icon"></i>
  141. <input id="username" type="text" name="username" placeholder="Username">
  142. </div>
  143. </div>
  144. <div class="field">
  145. <div class="ui left icon input">
  146. <i class="ticket alternate icon"></i>
  147. <input id="token" type="text" name="token" placeholder="Token">
  148. </div>
  149. </div>
  150. <div class="field">
  151. <div class="ui left icon input">
  152. <i class="lock icon"></i>
  153. <input id="magic" type="password" name="New password" placeholder="New Password">
  154. </div>
  155. </div>
  156. <div id="resetBtn" class="ui fluid basic button"><i class="ui green lock open icon"></i> Reset Password</div>
  157. <div id="errmsg" class="ui red message" style="display: none;">
  158. <i class="red remove icon"></i> Unknown Error Occured
  159. </div>
  160. <div id="succmsg" class="ui message" style="display:none;">
  161. <i class="ui green check circle icon"></i> Password Updated. <br><small>Redirecting to <a href="/">login page</a> in 3 seconds</small>
  162. </div>
  163. <div id="countdown" class="ui message" style="color: grey;">
  164. <span id="countdownText"><i class="ui loading circle notch icon"></i> Resend email in <span id="countdown-num">30</span> seconds</span>
  165. <a href="#" id="resendEmailLink" onclick="sendResetAccountEmail();">Resend Email</a>
  166. </div>
  167. </div>
  168. </form>
  169. <a class="backBtn" href="/">
  170. <i class="big chevron circle left icon" style="color: #121d37;"></i>
  171. </a>
  172. </div>
  173. </div>
  174. <div id="wavesWrapper">
  175. <!-- CSS waves-->
  176. <svg class="waves" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
  177. viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto">
  178. <defs>
  179. <path id="gentle-wave" d="M-160 44c30 0 58-18 88-18s 58 18 88 18 58-18 88-18 58 18 88 18 v44h-352z" />
  180. </defs>
  181. <g class="parallax">
  182. <use xlink:href="#gentle-wave" x="48" y="0" fill="rgba(255,255,255,0.7" />
  183. <use xlink:href="#gentle-wave" x="48" y="3" fill="rgba(255,255,255,0.5)" />
  184. <use xlink:href="#gentle-wave" x="48" y="5" fill="rgba(255,255,255,0.3)" />
  185. <use xlink:href="#gentle-wave" x="48" y="7" fill="#fff" />
  186. </g>
  187. </svg>
  188. </div>
  189. <div class="wavebase">
  190. <p>Proudly powered by <a href="https://zoraxy.aroz.org" target="_blank">Zoraxy</a></p>
  191. </div>
  192. <script>
  193. AOS.init();
  194. var redirectionAddress = "/";
  195. var loginAddress = "/api/auth/login";
  196. $(".checkbox").checkbox();
  197. $(document).ready(function(){
  198. var currentdate = new Date();
  199. var datetime = currentdate.getDate() + "/"
  200. + (currentdate.getMonth()+1) + "/"
  201. + currentdate.getFullYear() + " "
  202. + currentdate.getHours() + ":"
  203. + currentdate.getMinutes() + ":"
  204. + currentdate.getSeconds();
  205. $("#requestTime").text(datetime);
  206. //Check if the user already logged in
  207. $.get("/api/auth/checkLogin",function(data){
  208. try{
  209. if (data === true || data.trim() == "true"){
  210. //User already logged in. Redirect to target page.
  211. if (redirectionAddress == ""){
  212. //Redirect back to index
  213. window.location.href = "/";
  214. }else{
  215. console.log(data);
  216. //window.location.href = redirectionAddress;
  217. }
  218. }
  219. }catch(ex){
  220. //Assume not logged in
  221. console.log(data);
  222. }
  223. });
  224. });
  225. //Bind reset password events
  226. $('#resetBtn').on('click', function() {
  227. // Get input values
  228. var username = $('#username').val();
  229. var token = $('#token').val();
  230. var newPassword = $('#magic').val();
  231. if (token.trim() == ""){
  232. $("#errmsg").html(`<i class="red circle times icon"></i> Token cannot be empty!`);
  233. $("#errmsg").show();
  234. return;
  235. }
  236. // Send POST request with input values as data
  237. let csrfToken = document.getElementsByTagName("meta")["zoraxy.csrf.Token"].getAttribute("content");
  238. $.ajax({
  239. url: "/api/account/new",
  240. method: "POST",
  241. data: {
  242. username: username,
  243. token: token,
  244. newpw: newPassword
  245. },
  246. headers: {
  247. "X-CSRF-Token": csrfToken,
  248. },
  249. success: function(data){
  250. // Handle successful response
  251. if (data.error != undefined){
  252. $("#errmsg").html(`<i class="red circle times icon"></i> ` + data.error);
  253. $("#errmsg").show();
  254. }else{
  255. $("#errmsg").hide();
  256. $("#countdown").hide();
  257. $("#succmsg").show();
  258. setTimeout(function(){
  259. window.location.href = "/";
  260. }, 3000);
  261. }
  262. },
  263. error: function(){
  264. console.error(error);
  265. }
  266. })
  267. });
  268. function updateYear() {
  269. const year = new Date().getFullYear();
  270. const elements = document.getElementsByClassName("year");
  271. for (let i = 0; i < elements.length; i++) {
  272. elements[i].textContent = year;
  273. }
  274. }
  275. updateYear();
  276. function startCountdown() {
  277. var count = 30;
  278. var countdownNum = $('#countdown-num');
  279. countdownNum.text(count);
  280. $("#countdownText").show();
  281. $('#resendEmailLink').hide();
  282. var countdownTimer = setInterval(function() {
  283. count--;
  284. if (count === 0) {
  285. clearInterval(countdownTimer);
  286. $("#countdownText").hide();
  287. $('#resendEmailLink').show();
  288. } else {
  289. countdownNum.text(count);
  290. }
  291. }, 1000);
  292. }
  293. //Send account reset email to preset admin account
  294. function sendResetAccountEmail(){
  295. $("#resendEmailLink").html(`<i class="ui loading spinner icon"></i> Sending Email`);
  296. $("#resendEmailLink").css({
  297. "opacity": "0.8",
  298. "pointer-events": "none"
  299. });
  300. $.get("/api/account/reset", function(data){
  301. $("#resendEmailLink").html(`<a href="#" onclick="sendResetAccountEmail();">Resend Email</a>`);
  302. $("#resendEmailLink").css({
  303. "opacity": "1",
  304. "pointer-events": "auto"
  305. });
  306. if (data.error !== undefined){
  307. alert(data.error);
  308. }else{
  309. //Start countdown again
  310. startCountdown();
  311. }
  312. });
  313. }
  314. $(".thisyear").text(new Date().getFullYear());
  315. function updateRenderElements(){
  316. if (window.innerHeight < 520){
  317. $(".bottombar").hide();
  318. }else{
  319. $(".bottombar").show();
  320. }
  321. }
  322. updateRenderElements();
  323. $(window).on("resize", function(){
  324. updateRenderElements();
  325. });
  326. //Start the countdown on redirect
  327. startCountdown();
  328. </script>
  329. </body>
  330. </html>