login.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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>Login | Zoraxy</title>
  9. <link rel="stylesheet" href="script/semantic/semantic.min.css">
  10. <link href="script/aos.css" rel="stylesheet">
  11. <script src="script/aos.js"></script>
  12. <script type="application/javascript" src="script/jquery-3.6.0.min.js"></script>
  13. <script type="application/javascript" src="script/semantic/semantic.min.js"></script>
  14. <style>
  15. body {
  16. background: linear-gradient(60deg, rgba(84,58,183,1) 0%, rgba(0,172,193,1) 100%);
  17. }
  18. #errmsg{
  19. color: #9f3a38;
  20. margin-top: 1em;
  21. margin-bottom: 0.4em;
  22. text-align: left;
  23. }
  24. .registerOnly{
  25. display:none;
  26. }
  27. .ui.fluid.button.registerOnly{
  28. display:none;
  29. }
  30. #loginForm {
  31. border-radius: 1em;
  32. width: 25em;
  33. height: 450px;
  34. position: absolute; /*Can also be `fixed`*/
  35. left: 0;
  36. right: 0;
  37. top: 0;
  38. bottom: 0;
  39. margin: auto;
  40. /*Solves a problem in which the content is being cut when the div is smaller than its' wrapper:*/
  41. max-width: 100%;
  42. max-height: 100%;
  43. overflow: auto;
  44. background-color: white;
  45. }
  46. .wavebase {
  47. position:fixed;
  48. bottom: 0;
  49. left: 0;
  50. width: 100%;
  51. height:5vh;
  52. text-align:center;
  53. padding-top: 1em;
  54. background-color: white;
  55. }
  56. /*
  57. Waves CSS
  58. */
  59. #wavesWrapper{
  60. position: fixed;
  61. bottom: 5vh;
  62. width: 100%;
  63. left: 0;
  64. }
  65. .waves {
  66. position:relative;
  67. width: 100%;
  68. height:15vh;
  69. margin-bottom:-7px; /*Fix for safari gap*/
  70. min-height:100px;
  71. max-height:150px;
  72. }
  73. .parallax > use {
  74. animation: move-forever 25s cubic-bezier(.55,.5,.45,.5) infinite;
  75. }
  76. .parallax > use:nth-child(1) {
  77. animation-delay: -8s;
  78. animation-duration: 28s;
  79. }
  80. .parallax > use:nth-child(2) {
  81. animation-delay: -12s;
  82. animation-duration: 40s;
  83. }
  84. .parallax > use:nth-child(3) {
  85. animation-delay: -16s;
  86. animation-duration: 52s;
  87. }
  88. .parallax > use:nth-child(4) {
  89. animation-delay: -20s;
  90. animation-duration: 80s;
  91. }
  92. @keyframes move-forever {
  93. 0% {
  94. transform: translate3d(-90px,0,0);
  95. }
  96. 100% {
  97. transform: translate3d(85px,0,0);
  98. }
  99. }
  100. /*Shrinking for mobile*/
  101. @media (max-width: 768px) {
  102. .waves {
  103. height:40px;
  104. min-height:40px;
  105. }
  106. }
  107. </style>
  108. </head>
  109. <body>
  110. <div id="loginForm" class="ui middle aligned center aligned grid" data-aos="fade-up">
  111. <div class="column" style="padding-top: 0 !important;">
  112. <form class="ui large form content">
  113. <div class="ui basic segment">
  114. <img class="ui fluid image" src="img/public/logo.svg" style="pointer-events:none;">
  115. <p class="registerOnly">Account Setup</p>
  116. <div class="field">
  117. <div class="ui left icon input">
  118. <i class="user icon"></i>
  119. <input id="username" type="text" name="username" placeholder="Username">
  120. </div>
  121. </div>
  122. <div class="field">
  123. <div class="ui left icon input">
  124. <i class="lock icon"></i>
  125. <input id="magic" type="password" name="password" placeholder="Password">
  126. </div>
  127. </div>
  128. <div class="field registerOnly">
  129. <div class="ui left icon input">
  130. <i class="lock icon"></i>
  131. <input id="repeatMagic" type="password" name="passwordconfirm" placeholder="Confirm Password">
  132. </div>
  133. </div>
  134. <div class="field loginOnly" style="text-align: left;">
  135. <div class="ui checkbox">
  136. <input id="rmbme" type="checkbox" tabindex="0" class="hidden">
  137. <label>Remember Me</label>
  138. </div>
  139. </div>
  140. <div id="loginbtn" class="ui fluid basic button loginOnly"> <i class="ui blue sign-in icon"></i> Login</div>
  141. <div id="regsiterbtn" class="ui fluid basic button registerOnly"><i class="ui green checkmark icon"></i> Confirm</div>
  142. <div id="errmsg"></div>
  143. <div id="forgetPassword" class="field loginOnly" style="text-align: right; margin-top: 2em;">
  144. <a href="#" onclick="sendResetAccountEmail();">Forget Password</a>
  145. </div>
  146. </div>
  147. </form>
  148. </div>
  149. </div>
  150. <div id="wavesWrapper">
  151. <!-- CSS waves-->
  152. <svg class="waves" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
  153. viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto">
  154. <defs>
  155. <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" />
  156. </defs>
  157. <g class="parallax">
  158. <use xlink:href="#gentle-wave" x="48" y="0" fill="rgba(255,255,255,0.7" />
  159. <use xlink:href="#gentle-wave" x="48" y="3" fill="rgba(255,255,255,0.5)" />
  160. <use xlink:href="#gentle-wave" x="48" y="5" fill="rgba(255,255,255,0.3)" />
  161. <use xlink:href="#gentle-wave" x="48" y="7" fill="#fff" />
  162. </g>
  163. </svg>
  164. </div>
  165. <div class="wavebase">
  166. <p>Proudly powered by <a href="https://zoraxy.arozos.com" target="_blank">Zoraxy</a></p>
  167. </div>
  168. <script>
  169. AOS.init();
  170. var redirectionAddress = "/";
  171. var loginAddress = "/api/auth/login";
  172. $(".checkbox").checkbox();
  173. $(document).ready(function(){
  174. var currentdate = new Date();
  175. var datetime = currentdate.getDate() + "/"
  176. + (currentdate.getMonth()+1) + "/"
  177. + currentdate.getFullYear() + " "
  178. + currentdate.getHours() + ":"
  179. + currentdate.getMinutes() + ":"
  180. + currentdate.getSeconds();
  181. $("#requestTime").text(datetime);
  182. //Check if this is a new system
  183. $.get("/api/auth/userCount", function(data){
  184. if (data == 0){
  185. //Allow user creation
  186. $(".loginOnly").hide();
  187. $(".registerOnly").show();
  188. }
  189. });
  190. //Check if the user already logged in
  191. $.get("/api/auth/checkLogin",function(data){
  192. try{
  193. if (data === true || data.trim() == "true"){
  194. //User already logged in. Redirect to target page.
  195. if (redirectionAddress == ""){
  196. //Redirect back to index
  197. window.location.href = "/";
  198. }else{
  199. console.log(data);
  200. //window.location.href = redirectionAddress;
  201. }
  202. }
  203. }catch(ex){
  204. //Assume not logged in
  205. console.log(data);
  206. }
  207. });
  208. });
  209. function updateYear() {
  210. const year = new Date().getFullYear();
  211. const elements = document.getElementsByClassName("year");
  212. for (let i = 0; i < elements.length; i++) {
  213. elements[i].textContent = year;
  214. }
  215. }
  216. updateYear();
  217. //Event handlers for buttons
  218. $("#loginbtn").on("click",function(){
  219. login();
  220. });
  221. $("input").on("keydown",function(event){
  222. if (event.keyCode === 13) {
  223. event.preventDefault();
  224. if ($(this).attr("id") == "magic"){
  225. login();
  226. }else{
  227. //Fuocus to password field
  228. $("#magic").focus();
  229. }
  230. }
  231. });
  232. $("#regsiterbtn").on("click", function(event){
  233. var username = $("#username").val();
  234. var magic = $("#magic").val();
  235. var repeatMagic = $("#repeatMagic").val();
  236. if (magic !== repeatMagic) {
  237. alert("Password does not match");
  238. return;
  239. }
  240. $.ajax({
  241. url: "/api/auth/register",
  242. method: "POST",
  243. data: {
  244. username: username,
  245. password: magic
  246. },
  247. success: function(data) {
  248. if (data.error != undefined){
  249. alert(data.error);
  250. }else{
  251. //Register success. Refresh page
  252. window.location.reload();
  253. }
  254. },
  255. error: function(xhr, status, error) {
  256. console.error("Error registering user:", error);
  257. }
  258. });
  259. });
  260. //Send account reset email to preset admin account
  261. function sendResetAccountEmail(){
  262. $("#forgetPassword").html(`<i class="ui loading spinner icon"></i> Sending Email`);
  263. $("#forgetPassword").css("opacity", "0.8");
  264. $.get("/api/account/reset", function(data){
  265. if (data.error !== undefined){
  266. $("#forgetPassword").html(`<a href="#" onclick="sendResetAccountEmail();">Forget Password</a>`);
  267. alert(data.error);
  268. }else{
  269. window.location.href = "/web/reset.html"
  270. }
  271. });
  272. }
  273. //Login system with the given username and password
  274. function login(){
  275. var username = $("#username").val();
  276. var magic = $("#magic").val();
  277. var rmbme = document.getElementById("rmbme").checked;
  278. $("#errmsg").stop().finish().slideUp("fast");
  279. $("input").addClass('disabled');
  280. $.post(loginAddress, {"username": username, "password": magic, "rmbme": rmbme}).done(function(data){
  281. if (data.error !== undefined){
  282. //Something went wrong during the login
  283. $("#errmsg").html(`<i class="red remove icon"></i> ${data.error}`);
  284. $("#errmsg").stop().finish().slideDown('fast');
  285. }else if(data.redirect !== undefined){
  286. //LDAP Related Code
  287. window.location.href = data.redirect;
  288. }else{
  289. //Login succeed
  290. if (redirectionAddress == ""){
  291. //Redirect back to index
  292. window.location.href = "./";
  293. }else{
  294. window.location.href = redirectionAddress;
  295. }
  296. }
  297. $("input").removeClass('disabled');
  298. });
  299. }
  300. function get(name){
  301. if(name=(new RegExp('[?&]'+encodeURIComponent(name)+'=([^&]*)')).exec(location.search))
  302. return decodeURIComponent(name[1]);
  303. }
  304. $(".thisyear").text(new Date().getFullYear());
  305. function updateRenderElements(){
  306. if (window.innerHeight < 520){
  307. $(".bottombar").hide();
  308. }else{
  309. $(".bottombar").show();
  310. }
  311. }
  312. updateRenderElements();
  313. $(window).on("resize", function(){
  314. updateRenderElements();
  315. });
  316. </script>
  317. </body>
  318. </html>