Skouter mortgage estimates. Web application with view written in PHP and Vue, but controller and models in Go.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

45 lines
884 B

  1. <template>
  2. <div class="page">
  3. <section class="form inputs">
  4. <h3>Login</h3>
  5. <label>Email</label>
  6. <input v-model="email" required>
  7. <label>Password</label>
  8. <input v-model="password" type="password" required>
  9. <button @click="login">Login</button>
  10. <div class="error"> {{error}} </div>
  11. </section>
  12. </div>
  13. </template>
  14. <script>
  15. function login() {
  16. this.error = ""
  17. return fetch(`/api/login`,
  18. {method: 'POST',
  19. body: JSON.stringify( {email: this.email, password: this.password} ),
  20. }).then(response => {
  21. if (response.ok) {
  22. return response.text()
  23. } else {
  24. this.error = "Invalid credentials"
  25. }
  26. }).then(result => {
  27. if (!result || !result.length) return // Exit if there is no token
  28. this.$emit('login')
  29. window.location.hash = ''
  30. })
  31. }
  32. export default {
  33. emits: [ 'login' ],
  34. methods: { login },
  35. data() {
  36. return { email: "", password: "", error: ""}
  37. },
  38. }
  39. </script>