Examples of code I've written in PHP, Javascript, SCSS, etc.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

120 linhas
3.6 KiB

  1. <template>
  2. <div>
  3. <h2>Settings</h2>
  4. <section class="change-name-pane">
  5. <h4>Name</h4>
  6. <input :value="user.name" name="name" id="changed_name" type="text">
  7. <button @click="changeName">Save <loading src="../../images/loading-white.svg" alt=""></loading></button>
  8. <span></span>
  9. </section>
  10. <section class="change-email-pane">
  11. <h4>Email</h4>
  12. <input :value="user.email" name="email" type="text" id="changed_email">
  13. <button @click="changeEmail">Save<img class="loading-icon" src="../../images/loading-white.svg" alt=""></button>
  14. <span></span>
  15. </section>
  16. <section class="change-password-pane">
  17. <h4>Change Password</h4>
  18. <h5>Current Password</h5><input name="current_passowrd" id="current_password" type="password">
  19. <h5>New Password</h5><input id="new_password" name="password" type="password">
  20. <h5>Confirm Password</h5><input id="confirm_password" name="confirm_passowrd" type="password">
  21. <button @click="changePassword">Save<img class="loading-icon" src="../../images/loading-white.svg" alt=""></button>
  22. <span></span>
  23. </section>
  24. </div>
  25. </template>
  26. <script>
  27. import Loading from '../icons/loading.vue'
  28. function changeName() {
  29. let name = document.getElementById('changed_name').value
  30. let info = document.querySelector('.change-name-pane span')
  31. let pane = document.querySelector('.change-name-pane')
  32. pane.classList.add('loading')
  33. pane.classList.remove('error')
  34. fetch("/panel/change-name", {
  35. method: 'POST',
  36. headers: {'Content-Type': 'application/json',
  37. 'Accept': 'application/json',
  38. 'X-XSRF-TOKEN': this.token},
  39. body: JSON.stringify({'name': name}),
  40. }).then(response => {
  41. if (response.ok) {
  42. pane.classList.add('completed')
  43. info.textContent = 'Completed'
  44. } else {
  45. pane.classList.add('error')
  46. info.textContent = 'Error: ' + response.status
  47. }
  48. pane.classList.remove('loading')
  49. })
  50. }
  51. function changeEmail() {
  52. let email = document.getElementById('changed_email').value
  53. let info = document.querySelector('.change-email-pane span')
  54. let pane = document.querySelector('.change-email-pane')
  55. pane.classList.add('loading')
  56. pane.classList.remove('error')
  57. fetch("/panel/change-email", {
  58. method: 'POST',
  59. headers: {'Content-Type': 'application/json',
  60. 'Accept': 'application/json',
  61. 'X-XSRF-TOKEN': this.token},
  62. body: JSON.stringify({'email': email}),
  63. }).then(response => {
  64. if (response.ok) {
  65. pane.classList.add('completed')
  66. info.textContent = 'Verification link sent'
  67. } else {
  68. pane.classList.add('error')
  69. info.textContent = 'Error: ' + response.status
  70. }
  71. pane.classList.remove('loading')
  72. })
  73. }
  74. function changePassword() {
  75. let info = document.querySelector('.change-password-pane span')
  76. let pane = document.querySelector('.change-password-pane')
  77. pane.classList.add('loading')
  78. pane.classList.remove('error')
  79. fetch("/panel/change-password", {
  80. method: 'POST',
  81. headers: {'Content-Type': 'application/json',
  82. 'Accept': 'application/json',
  83. 'X-XSRF-TOKEN': this.token},
  84. body: JSON.stringify({'current_password':
  85. document.getElementById('current_password').value,
  86. 'password': document.getElementById('new_password').value,
  87. 'password_confirmation':
  88. document.getElementById('confirm_password').value}),
  89. }).then(response => {
  90. response.json().then(data => {console.log(data)})
  91. if (response.ok) {
  92. pane.classList.add('completed')
  93. info.textContent = 'Completed'
  94. } else {
  95. pane.classList.add('error')
  96. info.textContent = 'Error: ' + response.status
  97. }
  98. pane.classList.remove('loading')
  99. })
  100. }
  101. export default {
  102. components: {Loading,},
  103. methods: {
  104. changePassword, changeName, changeEmail
  105. },
  106. props: ['user', 'token']
  107. }
  108. </script>