header.html 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
  2. <link rel="stylesheet"
  3. href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@48,400,0,0" />
  4. <link rel="stylesheet"
  5. href="https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD@48,400,1,0" />
  6. <!-- <link rel="stylesheet" href="{{ " /css/main.css" | prepend: site.baseurl }}"> -->
  7. <style>
  8. .user-icon {
  9. display: inline-block;
  10. position: relative;
  11. }
  12. .dropdown_header {
  13. display: inline-block;
  14. position: relative;
  15. z-index: 1000;
  16. background-color: #FFC907;
  17. }
  18. .dropdown-content_header {
  19. display: none;
  20. position: absolute;
  21. width: auto;
  22. overflow: auto;
  23. box-shadow: 0px 10px 10px 0px rgba(0, 0, 0, 0.4);
  24. /* background-color: rgba(255, 255, 255, 0); */
  25. background-color: white;
  26. font-family: Reforma2018, serif;
  27. font-size: 1em;
  28. }
  29. .dropdown_header.active .dropdown-content_header {
  30. display: block;
  31. }
  32. .dropdown-content_header a {
  33. display: block;
  34. color: #000000;
  35. padding: 5px;
  36. text-decoration: none;
  37. }
  38. .dropdown-content_header a:hover {
  39. color: #FFFFFF;
  40. background-color: #FFC907;
  41. }
  42. .dropdown_header:hover {
  43. /* Resetting styles for hover state */
  44. border: none;
  45. box-shadow: none;
  46. display: block;
  47. /* Or any other appropriate display value */
  48. grid-template-columns: initial;
  49. /* Or any other appropriate value */
  50. }
  51. /* Style for the modal */
  52. /* #navBar.modal {
  53. display: flex;
  54. flex-direction: column;
  55. align-items: center;
  56. } */
  57. #emailCode,
  58. #emailCodeVerify {
  59. flex-direction: row;
  60. align-items: center;
  61. margin-bottom: 10px;
  62. }
  63. #emailCode {
  64. display: block;
  65. }
  66. #emailCodeVerify {
  67. display: none;
  68. }
  69. .modal {
  70. display: none;
  71. position: fixed;
  72. top: 50%;
  73. left: 50%;
  74. transform: translate(-50%, -50%);
  75. padding: 20px;
  76. background-color: white;
  77. border: 2px solid #ccc;
  78. z-index: 2000;
  79. width: 60%;
  80. height: 20%;
  81. text-align: center;
  82. font-family: Reforma2018, serif;
  83. font-size: 1em;
  84. }
  85. /* Additional styling for buttons */
  86. .btn_login_logout {
  87. position: relative;
  88. border-radius: 4px;
  89. background-color: transparent;
  90. border: 1px solid #29335C;
  91. font-family: Reforma2018, serif;
  92. margin: 10px;
  93. padding-left: 2px;
  94. padding-right: 2px;
  95. }
  96. .btn_login_logout.primary_login_logout {
  97. background-color: #FFC907;
  98. color: black;
  99. border: 1px solid #d3a500;
  100. }
  101. .btn_login_logout.is-large_login_logout {
  102. font-size: 1em;
  103. text-align: center;
  104. }
  105. .btn_login_logout:hover {
  106. cursor: pointer;
  107. background-color: #d3a500
  108. }
  109. @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&display=swap');
  110. * {
  111. margin: 0;
  112. padding: 0;
  113. box-sizing: border-box;
  114. font-family: "Poppins", sans-serif;
  115. }
  116. .CRChatbot {
  117. background: #E3F2FD;
  118. }
  119. .chatbot-toggler {
  120. position: fixed;
  121. bottom: 30px;
  122. right: 35px;
  123. outline: none;
  124. border: none;
  125. height: 50px;
  126. width: 50px;
  127. display: flex;
  128. cursor: pointer;
  129. align-items: center;
  130. justify-content: center;
  131. border-radius: 50%;
  132. background: #FFC907;
  133. transition: all 0.2s ease;
  134. }
  135. .CRChatbot.show-chatbot .chatbot-toggler {
  136. transform: rotate(90deg);
  137. }
  138. .chatbot-toggler span {
  139. color: #fff;
  140. position: absolute;
  141. }
  142. .chatbot-toggler span:last-child,
  143. .CRChatbot.show-chatbot .chatbot-toggler span:first-child {
  144. opacity: 0;
  145. }
  146. .CRChatbot.show-chatbot .chatbot-toggler span:last-child {
  147. opacity: 1;
  148. }
  149. .chatbot {
  150. position: fixed;
  151. right: 35px;
  152. bottom: 90px;
  153. width: 420px;
  154. background: #fff;
  155. border-radius: 15px;
  156. overflow: hidden;
  157. opacity: 0;
  158. pointer-events: none;
  159. transform: scale(0.5);
  160. transform-origin: bottom right;
  161. box-shadow: 0 0 128px 0 rgba(0, 0, 0, 0.1),
  162. 0 32px 64px -48px rgba(0, 0, 0, 0.5);
  163. transition: all 0.1s ease;
  164. }
  165. .CRChatbot.show-chatbot .chatbot {
  166. opacity: 1;
  167. pointer-events: auto;
  168. transform: scale(1);
  169. }
  170. .chatbot header {
  171. padding: 16px 0;
  172. position: relative;
  173. text-align: center;
  174. color: #fff;
  175. background: #FFC907;
  176. box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  177. }
  178. .chatbot header span {
  179. position: absolute;
  180. right: 15px;
  181. top: 50%;
  182. display: none;
  183. cursor: pointer;
  184. transform: translateY(-50%);
  185. }
  186. header h2 {
  187. font-size: 1.4rem;
  188. }
  189. .chatbot .chatbox {
  190. overflow-y: auto;
  191. height: 510px;
  192. padding: 30px 20px 100px;
  193. }
  194. .chatbot :where(.chatbox, textarea)::-webkit-scrollbar {
  195. width: 6px;
  196. }
  197. .chatbot :where(.chatbox, textarea)::-webkit-scrollbar-track {
  198. background: #fff;
  199. border-radius: 25px;
  200. }
  201. .chatbot :where(.chatbox, textarea)::-webkit-scrollbar-thumb {
  202. background: #ccc;
  203. border-radius: 25px;
  204. }
  205. .chatbox .chat {
  206. display: flex;
  207. list-style: none;
  208. }
  209. .chatbox .outgoing {
  210. margin: 20px 0;
  211. justify-content: flex-end;
  212. }
  213. .chatbox .incoming span {
  214. width: 32px;
  215. height: 32px;
  216. color: #fff;
  217. cursor: default;
  218. text-align: center;
  219. line-height: 32px;
  220. align-self: flex-end;
  221. background:#FFC907;
  222. border-radius: 4px;
  223. margin: 0 10px 7px 0;
  224. }
  225. .chatbox .chat p {
  226. white-space: pre-wrap;
  227. padding: 12px 16px;
  228. border-radius: 10px 10px 0 10px;
  229. max-width: 75%;
  230. color: #fff;
  231. font-size: 0.95rem;
  232. background: #FFC907;
  233. }
  234. .chatbox .incoming p {
  235. border-radius: 10px 10px 10px 0;
  236. }
  237. .chatbox .chat p.error {
  238. color: #721c24;
  239. background: #f8d7da;
  240. }
  241. .chatbox .incoming p {
  242. color: #000;
  243. background: #f2f2f2;
  244. }
  245. .chatbot .chat-input {
  246. display: flex;
  247. gap: 5px;
  248. position: absolute;
  249. bottom: 0;
  250. width: 100%;
  251. background: #fff;
  252. padding: 3px 20px;
  253. border-top: 1px solid #ddd;
  254. }
  255. .chat-input textarea {
  256. height: 55px;
  257. width: 100%;
  258. border: none;
  259. outline: none;
  260. resize: none;
  261. max-height: 180px;
  262. padding: 15px 15px 15px 0;
  263. font-size: 0.95rem;
  264. }
  265. .chat-input span {
  266. align-self: flex-end;
  267. color:#FFC907;
  268. cursor: pointer;
  269. height: 55px;
  270. display: flex;
  271. align-items: center;
  272. visibility: hidden;
  273. font-size: 1.35rem;
  274. }
  275. .chat-input textarea:valid~span {
  276. visibility: visible;
  277. }
  278. @media (max-width: 490px) {
  279. .chatbot-toggler {
  280. right: 20px;
  281. bottom: 20px;
  282. }
  283. .chatbot {
  284. right: 0;
  285. bottom: 0;
  286. height: 100%;
  287. border-radius: 0;
  288. width: 100%;
  289. }
  290. .chatbot .chatbox {
  291. height: 90%;
  292. padding: 25px 15px 100px;
  293. }
  294. .chatbot .chat-input {
  295. padding: 5px 15px;
  296. }
  297. .chatbot header span {
  298. display: block;
  299. }
  300. }
  301. </style>
  302. <header class="site-header">
  303. <div class="wrapper">
  304. <a class="site-title" href="{{ site.baseurl }}/">{{ site.title }}</a>
  305. <img src="{% link assets/elements/icon_do.svg %}" alt="do-ocracy icon"
  306. style="height:40px; padding: 5px 0 0 20px;" />
  307. <nav class="site-nav">
  308. <a href="#" class="menu-icon">
  309. <svg viewBox="0 0 18 15">
  310. <path fill="#424242"
  311. d="M18,1.484c0,0.82-0.665,1.484-1.484,1.484H1.484C0.665,2.969,0,2.304,0,1.484l0,0C0,0.665,0.665,0,1.484,0 h15.031C17.335,0,18,0.665,18,1.484L18,1.484z" />
  312. <path fill="#424242"
  313. d="M18,7.516C18,8.335,17.335,9,16.516,9H1.484C0.665,9,0,8.335,0,7.516l0,0c0-0.82,0.665-1.484,1.484-1.484 h15.031C17.335,6.031,18,6.696,18,7.516L18,7.516z" />
  314. <path fill="#424242"
  315. d="M18,13.516C18,14.335,17.335,15,16.516,15H1.484C0.665,15,0,14.335,0,13.516l0,0 c0-0.82,0.665-1.484,1.484-1.484h15.031C17.335,12.031,18,12.696,18,13.516L18,13.516z" />
  316. </svg>
  317. </a>
  318. <div class="trigger" style="display: inline-block;">
  319. {% for my_page in site.pages %}
  320. {% if my_page.title %}
  321. <a class="page-link{% if page.url == my_page.url %} page-link-active{% endif %}"
  322. href="{{ my_page.url | prepend: site.baseurl }}">{{ my_page.title }}</a>
  323. {% endif %}
  324. {% endfor %}
  325. <div class="user-icon" id="loginLogoutButton">
  326. <div id="login">
  327. <button class="btn_login_logout primary_login_logout is-large_login_logout" onclick="showLoginModal()"
  328. style="height: 42px; width: 100px; padding: 2px; text-align: center">
  329. <img src="{% link assets/tabler_icons/login.svg %}" alt="Login"> Login
  330. </button>
  331. </div>
  332. <div id="logout" class="dropdown_header">
  333. <button class="btn_login_logout primary_login_logout is-large_login_logout" onclick="toggleDropdown()"
  334. style="height: 40px; width: 40px; padding: 2px; text-align: center">
  335. <img src="{% link assets/tabler_icons/user.svg %}" alt="Login">
  336. </button>
  337. <div class="dropdown-content_header">
  338. <div id="emailText"
  339. style="padding: 10px; padding-top: 20px; margin-top: 1px; margin-bottom: 1px; height: 10 px">
  340. </div>
  341. <a href="#" style="padding: 10px; margin-top: 1px; margin-bottom: 1px; height: 10 px"
  342. @click="logout">Logout</a>
  343. </div>
  344. </div>
  345. </div>
  346. </div>
  347. </div>
  348. <div id="navBar" class="modal"
  349. style="width: 40%; height: 15%; padding-top: 1%; flex-direction: column; justify-content: center; align-items: center;">
  350. <div id="emailCode" style="align-items: center; text-align: center;">
  351. <label for="emailInput">Enter your email:</label>
  352. <input type="email" id="emailInput" v-model="loginEmail" required>
  353. <div style="display: flex; flex-direction: row; justify-content: center; margin-top: 20px;">
  354. <button class="btn primary is-large" @click="sendOTP">Send Code</button>
  355. <span style="margin: 0 10px;"></span> <!-- Spacer -->
  356. <button class="btn primary is-large" @click="closeModal">Close</button>
  357. </div>
  358. </div>
  359. <div id="emailCodeVerify" style="text-align: center;">
  360. <label for="otpInput">Enter Code to Login:</label>
  361. <input type="text" id="otpInput" v-model="otpCode" required>
  362. <div style="display: flex; flex-direction: row; justify-content: center; margin-top: 20px;">
  363. <button class="btn primary is-large" @click="verifyOTP">Verify Code</button>
  364. <span style="margin: 0 10px;"></span> <!-- Spacer -->
  365. <button class="btn primary is-large" @click="sendOTPAagin">Send Code Again</button>
  366. <span style="margin: 0 10px;"></span> <!-- Spacer -->
  367. <button class="btn primary is-large" @click="closeModal">Close</button>
  368. </div>
  369. </div>
  370. </div>
  371. </nav>
  372. <!-- <!DOCTYPE html>
  373. <html lang="en" dir="ltr">
  374. <head>
  375. <meta charset="utf-8">
  376. <title>Chatbot in JavaScript | CodingNepal</title>
  377. <link rel="stylesheet" href="style.css">
  378. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  379. <script src="script.js" defer></script>
  380. </head> -->
  381. <div class="CRChatbot">
  382. <button class="chatbot-toggler">
  383. <span class="material-symbols-rounded">search</span>
  384. <span class="material-symbols-outlined">close</span>
  385. </button>
  386. <div class="chatbot">
  387. <header>
  388. <h2>Search</h2>
  389. <span class="close-btn material-symbols-outlined">close</span>
  390. </header>
  391. <ul class="chatbox">
  392. <li class="chat incoming">
  393. <span class="material-symbols-outlined"><img src="/assets/elements/icon_do.svg" style="height:25px; padding: 3px 3px 3px 3px;"></img></span>
  394. <p>Please enter keywords you're looking for, and I'll provide the best matched community rules from library for you.
  395. <br>Also, follow <a href="https://communityrule.info/templates/" target="_blank">this</a> link to see various existing templates.
  396. </p>
  397. </li>
  398. </ul>
  399. <div class="chat-input">
  400. <textarea placeholder="Enter keywords..." spellcheck="false" required></textarea>
  401. <span id="send-btn" class="material-symbols-rounded">send</span>
  402. </div>
  403. </div>
  404. </div>
  405. </header>
  406. <script>
  407. const chatbotToggler = document.querySelector(".chatbot-toggler");
  408. const closeBtn = document.querySelector(".close-btn");
  409. const chatbox = document.querySelector(".chatbox");
  410. const chatInput = document.querySelector(".chat-input textarea");
  411. const sendChatBtn = document.querySelector(".chat-input span");
  412. let userMessage = null; // Variable to store user's message
  413. const API_KEY = "PASTE-YOUR-API-KEY"; // Paste your API key here
  414. const inputInitHeight = chatInput.scrollHeight;
  415. const createChatLi = (message, className) => {
  416. // Create a chat <li> element with passed message and className
  417. const chatLi = document.createElement("li");
  418. chatLi.classList.add("chat", `${className}`);
  419. let chatContent = className === "outgoing" ? `<p></p>` : `<span class="material-symbols-outlined">smart_toy</span><p></p>`;
  420. chatLi.innerHTML = chatContent;
  421. chatLi.querySelector("p").textContent = message;
  422. return chatLi; // return chat <li> element
  423. }
  424. // const generateResponse = (chatElement) => {
  425. // const API_URL = "https://api.openai.com/v1/chat/completions";
  426. // const messageElement = chatElement.querySelector("p");
  427. // // Define the properties and message for the API request
  428. // const requestOptions = {
  429. // method: "POST",
  430. // headers: {
  431. // "Content-Type": "application/json",
  432. // "Authorization": `Bearer ${API_KEY}`
  433. // },
  434. // body: JSON.stringify({
  435. // model: "gpt-3.5-turbo",
  436. // messages: [{ role: "user", content: userMessage }],
  437. // })
  438. // }
  439. // // Send POST request to API, get response and set the reponse as paragraph text
  440. // fetch(API_URL, requestOptions).then(res => res.json()).then(data => {
  441. // messageElement.textContent = data.choices[0].message.content.trim();
  442. // }).catch(() => {
  443. // messageElement.classList.add("error");
  444. // messageElement.textContent = "Oops! Something went wrong. Please try again.";
  445. // }).finally(() => chatbox.scrollTo(0, chatbox.scrollHeight));
  446. // }
  447. const generateResponse = (chatElement) => {
  448. const apiUrl = new URL("http://127.0.0.1:5000/request");
  449. const params = { question: userMessage };
  450. apiUrl.search = new URLSearchParams(params).toString();
  451. const messageElement = chatElement.querySelector("p");
  452. // Define the properties and message for the API request
  453. const requestOptions = {
  454. method: "GET",
  455. headers: {
  456. "Content-Type": "application/json",
  457. },
  458. };
  459. // Send POST request to API, get response and set the reponse as paragraph text
  460. fetch(apiUrl, requestOptions)
  461. .then(res => res.json())
  462. .then(data => {
  463. // console.log(data)
  464. let responseMessage = 'Here are the top 3 most suitable community rules we found based on your description:<br>';
  465. data.forEach((item, index) => {
  466. const community = item.community.replace(/\n/g, '').trim();
  467. responseMessage += `${index + 1}. ${community}<br><a href="${item.link}" target="_blank">Learn more</a><br><br>`;
  468. });
  469. messageElement.innerHTML = responseMessage;
  470. }).catch((err) => {
  471. messageElement.classList.add("error");
  472. messageElement.textContent = "Oops! Something went wrong. Please try again.";
  473. }).finally(() => chatbox.scrollTo(0, chatbox.scrollHeight));
  474. }
  475. const handleChat = () => {
  476. userMessage = chatInput.value.trim(); // Get user entered message and remove extra whitespace
  477. if (!userMessage) return;
  478. // Clear the input textarea and set its height to default
  479. chatInput.value = "";
  480. chatInput.style.height = `${inputInitHeight}px`;
  481. // Append the user's message to the chatbox
  482. chatbox.appendChild(createChatLi(userMessage, "outgoing"));
  483. chatbox.scrollTo(0, chatbox.scrollHeight);
  484. setTimeout(() => {
  485. // Display "Thinking..." message while waiting for the response
  486. const incomingChatLi = createChatLi("Thinking...", "incoming");
  487. chatbox.appendChild(incomingChatLi);
  488. chatbox.scrollTo(0, chatbox.scrollHeight);
  489. generateResponse(incomingChatLi);
  490. }, 600);
  491. }
  492. chatInput.addEventListener("input", () => {
  493. // Adjust the height of the input textarea based on its content
  494. chatInput.style.height = `${inputInitHeight}px`;
  495. chatInput.style.height = `${chatInput.scrollHeight}px`;
  496. });
  497. chatInput.addEventListener("keydown", (e) => {
  498. // If Enter key is pressed without Shift key and the window
  499. // width is greater than 800px, handle the chat
  500. if (e.key === "Enter" && !e.shiftKey && window.innerWidth > 800) {
  501. e.preventDefault();
  502. handleChat();
  503. }
  504. });
  505. sendChatBtn.addEventListener("click", handleChat);
  506. closeBtn.addEventListener("click", () => document.querySelector(".CRChatbot").classList.remove("show-chatbot"));
  507. chatbotToggler.addEventListener("click", () => document.querySelector(".CRChatbot").classList.toggle("show-chatbot"));
  508. function toggleDropdown() {
  509. var dropdown = document.getElementById('logout');
  510. dropdown.classList.toggle('active');
  511. var myDiv = document.getElementById('emailText'); // Get the div element by ID
  512. myDiv.textContent = localStorage.getItem('userEmail');
  513. }
  514. function showLoginModal() {
  515. // Show the modal and overlay
  516. document.getElementById('navBar').style.display = 'block';
  517. document.getElementById('overlay').style.display = 'block';
  518. }
  519. function logout() {
  520. // Remove email from local storage
  521. localStorage.removeItem('userEmail');
  522. // Hide the dropdown and overlay
  523. document.getElementById('login').style.display = 'block';
  524. document.getElementById('logout').style.display = 'none';
  525. document.getElementById('emailCode').style.display = 'block';
  526. document.getElementById('emailCodeVerify').style.display = 'none';
  527. window.location.reload();
  528. }
  529. // function showLoginModal() {
  530. // document.getElementById('navBar').style.display = 'block';
  531. // // document.getElementById('overlay').style.display = 'block';
  532. // }
  533. function hideLoginModal() {
  534. document.getElementById('navBar').style.display = 'none';
  535. document.getElementById('overlay').style.display = 'none';
  536. }
  537. function isValidEmail(email) {
  538. // Regular expression for a basic email validation
  539. const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
  540. return emailRegex.test(email);
  541. }
  542. new Vue({
  543. el: '#loginLogoutButton',
  544. data: {
  545. email: localStorage.getItem('userEmail') || null,
  546. showDropdown: false,
  547. },
  548. mounted() {
  549. // Retrieve email from local storage on component mount
  550. this.email = localStorage.getItem('userEmail');
  551. if (this.email) {
  552. document.getElementById('login').style.display = 'none';
  553. document.getElementById('logout').style.display = 'block';
  554. } else {
  555. document.getElementById('login').style.display = 'block';
  556. document.getElementById('logout').style.display = 'none';
  557. }
  558. },
  559. });
  560. new Vue({
  561. el: '#navBar',
  562. data: {
  563. loginEmail: '',
  564. email: localStorage.getItem('userEmail'),
  565. otpCode: "",
  566. backendUrlOtp: "/api/send_otp",
  567. backendUrlValidateOtp: "/api/validate_otp"
  568. },
  569. methods: {
  570. sendOTPAagin() {
  571. document.getElementById('emailCode').style.display = 'block';
  572. document.getElementById('emailCodeVerify').style.display = 'none';
  573. },
  574. sendOTP() {
  575. const requestData = {
  576. email: this.loginEmail
  577. }
  578. if (isValidEmail(this.loginEmail)) {
  579. fetch(this.backendUrlOtp, {
  580. method: 'POST',
  581. headers: {
  582. 'Content-Type': 'application/json',
  583. 'Access-Control-Allow-Methods': 'POST',
  584. 'Access-Control-Allow-Headers': 'Content-Type'
  585. // Add any other headers you may need, such as authorization headers
  586. },
  587. body: JSON.stringify(requestData),
  588. }).then(response => {
  589. if (!response.ok) {
  590. alert('Error while sending OTP');
  591. } else {
  592. alert(`Code sent to: ${this.loginEmail}`);
  593. document.getElementById('emailCode').style.display = 'none';
  594. document.getElementById('emailCodeVerify').style.display = 'block';
  595. }
  596. })
  597. } else {
  598. alert(`Please enter valid email address`);
  599. }
  600. },
  601. verifyOTP() {
  602. const requestData = {
  603. email: this.loginEmail,
  604. otp: this.otpCode
  605. }
  606. fetch(this.backendUrlValidateOtp, {
  607. method: 'POST',
  608. headers: {
  609. 'Content-Type': 'application/json',
  610. 'Access-Control-Allow-Methods': 'POST',
  611. 'Access-Control-Allow-Headers': 'Content-Type'
  612. // Add any other headers you may need, such as authorization headers
  613. },
  614. body: JSON.stringify(requestData),
  615. }).then(response => {
  616. if (response.status == 500) {
  617. alert('Error while validating code');
  618. } else if (response.status == 200) {
  619. alert('Logged in successfully');
  620. localStorage.setItem('userEmail', this.loginEmail)
  621. document.getElementById('login').style.display = 'none';
  622. document.getElementById('logout').style.display = 'block';
  623. document.getElementById('logout').classList.remove('active');
  624. this.closeModal();
  625. } else {
  626. alert('Invalid code, please enter valid code');
  627. }
  628. })
  629. },
  630. closeModal() {
  631. document.getElementById('navBar').style.display = 'none';
  632. },
  633. },
  634. });
  635. </script>