login.html 14 KB

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