LoginByPassword.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <!--
  2. Copyright 2019 Hackware SpA <human@hackware.cl>
  3. This file is part of "Hackware Userland" and licensed under the terms
  4. of the GNU Affero General Public License version 3, or (at your option)
  5. a later version. You should have received a copy of this license along
  6. with the software. If not, see <https://www.gnu.org/licenses/>.
  7. -->
  8. <template>
  9. <form
  10. class="login-by-password"
  11. @submit.prevent="submitLogin"
  12. >
  13. <h1>Accede a tu panel</h1>
  14. <div
  15. v-if="errorMessage"
  16. class="login-error"
  17. >
  18. <i class="fa fa-exclamation-triangle" />
  19. {{ errorMessage }}
  20. </div>
  21. <input
  22. id="username"
  23. type="text"
  24. placeholder="Usuario o email"
  25. name="username"
  26. required
  27. autofocus
  28. >
  29. <input
  30. id="password"
  31. type="password"
  32. placeholder="Contraseña"
  33. name="password"
  34. required
  35. >
  36. <div class="checkbox-container">
  37. <input
  38. id="remember"
  39. type="checkbox"
  40. name="remember"
  41. >
  42. <label for="remember">Recordarme</label>
  43. </div>
  44. <button
  45. id="btnLogin"
  46. type="submit"
  47. >
  48. Iniciar sesión
  49. <i class="fa fa-sign-in-alt" />
  50. </button>
  51. <p>
  52. ¿Sin contraseña?
  53. <router-link :to="{ name: 'login-by-email' }">
  54. solicita acceso inmediato aquí
  55. </router-link>
  56. </p>
  57. </form>
  58. </template>
  59. <script>
  60. export default {
  61. name: 'LoginByPassword',
  62. data() {
  63. return {
  64. errorMessage: null,
  65. };
  66. },
  67. methods: {
  68. submitLogin(event) {
  69. const btnLogin = document.getElementById('btnLogin');
  70. btnLogin.setAttribute('disabled', true);
  71. this.errorMessage = null;
  72. return this.$fetcher.hawesePost('/auth/login', event.target, {}, false)
  73. .then(response => response.json())
  74. .then((body) => {
  75. if ('error' in body) {
  76. btnLogin.removeAttribute('disabled');
  77. this.errorMessage = body.error.message;
  78. } else {
  79. this.$auth.setUser(body);
  80. this.$router.push('/');
  81. this.$emit('login');
  82. }
  83. });
  84. },
  85. },
  86. };
  87. </script>