My SMM panel
 
 
 
 
 
 

147 lines
3.9 KiB

  1. import RegisterArea from './register-area/register-area.vue'
  2. import Panel from './panel/panel.vue'
  3. import '../scss/main.scss'
  4. import { createApp } from 'vue'
  5. importAll(require.context('../images', false, /\.(png|jpe?g|svg)$/))
  6. let heroText = document.querySelectorAll(".landing-hero h2,.landing-hero p")
  7. let registerToggles = document.querySelectorAll(".register-btn, .register-area\
  8. .cancel-button, .services-cards button")
  9. let token = getCookie('XSRF-TOKEN')
  10. function importAll(r) {
  11. return r.keys().map(r)
  12. }
  13. function getCookie(name) {
  14. var re = new RegExp(name + "=([^;]+)")
  15. var value = re.exec(document.cookie)
  16. return (value != null) ? unescape(value[1]) : null
  17. }
  18. function getToken(app) {
  19. fetch("/sanctum/csrf-cookie", {
  20. method: 'GET'
  21. }).then( () => {
  22. token = getCookie('XSRF-TOKEN')
  23. })
  24. app.token = token
  25. }
  26. function login(event) {
  27. fetch("/login", {
  28. method: 'POST',
  29. headers: {'Content-Type': 'application/json',
  30. 'Accept': 'application/json',
  31. 'X-XSRF-TOKEN': token},
  32. body: JSON.stringify({"email":
  33. document.getElementById("login_email").value,
  34. "password": document.getElementById("login_password").value}),
  35. }).then(response => {
  36. if (response.ok) {
  37. window.location.assign("/panel")
  38. } else {
  39. document.querySelector("#login_form .error").innerText =
  40. "Invalid credentials."
  41. }
  42. })
  43. event.preventDefault()
  44. event.stopPropogation()
  45. }
  46. function getUser(app) {
  47. fetch("/panel/user", {
  48. method: 'GET',
  49. headers: {'Content-Type': 'application/json',
  50. 'Accept': 'application/json',
  51. 'X-XSRF-TOKEN': token},
  52. }).then(response => {
  53. return response.json()
  54. }).then(data => {
  55. app.user = data
  56. })
  57. /* return this.user.name */
  58. }
  59. function getOrders(app) {
  60. fetch("/panel/orders", {
  61. method: 'GET',
  62. headers: {'Content-Type': 'application/json',
  63. 'Accept': 'application/json',
  64. 'X-XSRF-TOKEN': token},
  65. }).then(response => {
  66. return response.json()
  67. }).then(data => {
  68. app.orders = data
  69. })
  70. /* return this.user.name */
  71. }
  72. //Attempt to resend the verification link
  73. function resendLink(event) {
  74. fetch("/resend-verification", {
  75. method: 'POST',
  76. headers: {'Content-Type': 'application/json',
  77. 'Accept': 'application/json',
  78. 'X-XSRF-TOKEN': token},
  79. }).then(response => {
  80. if (response.ok) {
  81. event.target.parentNode.getElementsByTagName('h3')[0].innerText =
  82. "The link has been resent."
  83. } else {
  84. event.target.parentNode.getElementsByTagName('h3')[0].innerText =
  85. `${response.status} : ${response.statusText}`
  86. }
  87. })
  88. event.stopPropogation();
  89. event.preventDefault();
  90. }
  91. function toggleNav() {
  92. heroText.forEach(item => {
  93. item.classList.toggle("hidden")
  94. })
  95. document.querySelector("nav form.login").classList.toggle("active")
  96. this.classList.toggle("toggled")
  97. }
  98. if (window.location.pathname == '/') {
  99. document.getElementById('nav_toggle').addEventListener('click', toggleNav)
  100. document.querySelector('#login_form button').addEventListener('click', login)
  101. const app = createApp(RegisterArea).mount('#app')
  102. // app.token = token
  103. if (!token) {getToken(app)}
  104. //Triggers for registration menu
  105. for (let i = 0; i < registerToggles.length; i++) {
  106. registerToggles[i].addEventListener("click", function() {
  107. document.querySelector(".register-area").classList.add("active")
  108. app.active = 'register'
  109. })
  110. }
  111. document.getElementById("forgot-password-btn").onclick = event => {
  112. document.querySelector(".register-area").classList.add("active")
  113. app.active = 'forgot'
  114. event.preventDefault()
  115. }
  116. //FAQ collapsibles
  117. let cols = document.getElementsByClassName("collapsible");
  118. for (let i = 0; i < cols.length; i++) {
  119. cols[i].addEventListener("click", function() {
  120. this.classList.toggle("active");
  121. });
  122. }
  123. } else if (window.location.pathname == '/verify-email') {
  124. document.getElementById('resend_verification').addEventListener("click", resendLink)
  125. } else if (window.location.pathname == '/panel') {
  126. if (!token) {getToken(app)}
  127. const app = createApp(Panel).mount('#panel')
  128. window.onhashchange = ()=>{app.active = location.hash}
  129. getUser(app)
  130. }