Skouter mortgage estimates. Web application with view written in PHP and Vue, but controller and models in Go.
 
 
 
 
 
 

92 rindas
1.8 KiB

  1. <template>
  2. <section class="shadowbox">
  3. <h2>Register</h2>
  4. <account v-if="!step" :err="err" @submit="create" />
  5. <billing v-if="step" :err="err" @submit="create" />
  6. </section>
  7. </template>
  8. <script setup>
  9. import { ref, onMounted } from "vue"
  10. import Account from "./account.vue"
  11. import Billing from "./billing.vue"
  12. let err = ref("")
  13. const step = ref(0)
  14. const token = ref("")
  15. function getCookie(name) {
  16. var re = new RegExp(name + "=([^;]+)")
  17. var value = re.exec(document.cookie)
  18. return (value != null) ? unescape(value[1]) : null
  19. }
  20. function getUser() {
  21. token.value = getCookie("skouter")
  22. return fetch(`/api/user`,
  23. {method: 'GET',
  24. headers: {
  25. "Accept": "application/json",
  26. "Authorization": `Bearer ${token.value}`,
  27. },
  28. }).then(response => {
  29. if (response.ok) {
  30. return response.json()
  31. }
  32. })
  33. }
  34. function create(user) {
  35. console.log(user)
  36. fetch(`/api/user`,
  37. {method: 'POST',
  38. body: JSON.stringify(user),
  39. headers: {
  40. "Accept": "application/json",
  41. },
  42. }).then(resp => {
  43. if (resp.ok) {
  44. return resp.json().then(u => { err.value = "" }).
  45. then( () => intent(user) )
  46. } else {
  47. resp.text().then( e => err.value = e)
  48. }
  49. })
  50. }
  51. function intent(user) {
  52. console.log(user)
  53. return fetch(`/api/user/subscribe`,
  54. {method: 'POST',
  55. body: JSON.stringify(user),
  56. headers: {
  57. "Accept": "application/json",
  58. "Authorization": `Bearer ${token.value}`,
  59. },
  60. }).then(resp => {
  61. if (resp.ok) {
  62. return resp.json().then(u => { err.value = "" })
  63. } else {
  64. resp.text().then( e => err.value = e)
  65. }
  66. })
  67. }
  68. onMounted(() => {
  69. getUser().then( u => {
  70. intent(u)
  71. })
  72. })
  73. </script>
  74. <style scoped>
  75. section {
  76. max-width: 400px;
  77. margin: auto;
  78. }
  79. </style>