RegisterPage.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <q-page>
  3. <div style="height: 82px"></div>
  4. <div class="row q-mb-xl justify-center">
  5. <div
  6. class="col-10 col-sm-5 col-md-3 rounded-borders login-border shadow-7"
  7. >
  8. <div class="text-h5 text-left text-weight-bold text-black q-pa-md">
  9. {{ $t("register") }}
  10. </div>
  11. <div class="col-12 q-pa-md">
  12. <q-input
  13. :rules="[(val) => !!val || 'Field is required']"
  14. color="blue-12"
  15. v-model="username"
  16. :label="$t('enter_email')"
  17. ref="usernameInput"
  18. >
  19. <template v-slot:prepend>
  20. <q-icon name="account_circle" />
  21. </template>
  22. </q-input>
  23. </div>
  24. <div class="col-12 q-pa-md">
  25. <q-input
  26. :rules="[(val) => !!val || 'Field is required']"
  27. color="blue-12"
  28. v-model="password"
  29. type="password"
  30. :label="$t('enter_password')"
  31. ref="passwordInput"
  32. >
  33. <template v-slot:prepend>
  34. <q-icon name="lock" />
  35. </template>
  36. </q-input>
  37. </div>
  38. <div class="col-12 q-pa-md">
  39. <q-input
  40. color="blue-12"
  41. v-model="confPassword"
  42. error-message="Confirm password is not the same with password"
  43. :error="!correctConfPass"
  44. type="password"
  45. :label="$t('confirm_password')"
  46. ref="confPasswordInput"
  47. >
  48. <template v-slot:prepend>
  49. <q-icon name="lock" />
  50. </template>
  51. </q-input>
  52. </div>
  53. <div class="col-12 q-pa-md">
  54. <q-btn color="primary" @click="register()" :label="$t('register')" />
  55. </div>
  56. </div>
  57. </div>
  58. </q-page>
  59. </template>
  60. <script>
  61. import { ref, onMounted, getCurrentInstance, computed } from "vue";
  62. import { useQuasar } from "quasar";
  63. import { api } from "boot/axios";
  64. export default {
  65. name: "RegisterPage",
  66. setup() {
  67. const instance = getCurrentInstance();
  68. const app = getCurrentInstance().appContext.app;
  69. const gp = app.config.globalProperties;
  70. const $q = useQuasar();
  71. const username = ref("");
  72. const password = ref("");
  73. const confPassword = ref("");
  74. function register() {
  75. const isValidPassword = instance.refs.passwordInput.validate();
  76. const isValidConfPassword = instance.refs.confPasswordInput.validate();
  77. const isValidUsername = instance.refs.usernameInput.validate();
  78. if (
  79. isValidPassword &&
  80. isValidConfPassword &&
  81. isValidUsername &&
  82. confPassword.value == password.value
  83. ) {
  84. // do real reg logic
  85. var data = {
  86. email: username.value,
  87. password: password.value,
  88. };
  89. gp.$showLoading($q);
  90. api
  91. .post("/api/public/register", data)
  92. .then((response) => {
  93. console.log("==after register");
  94. console.log(response.data);
  95. if (response.data.ok == true) {
  96. gp.$generalNotify($q, true, "Succeed sending registering info");
  97. } else {
  98. gp.$generalNotify($q, false, response.data.message);
  99. }
  100. gp.$hideLoading($q);
  101. gp.$goPage("/regsuccess");
  102. })
  103. .catch((e) => {
  104. gp.$hideLoading($q);
  105. gp.$generalNotify($q, false, "Error message: " + e);
  106. });
  107. } else {
  108. gp.$generalNotify($q, false, "Input not valid");
  109. }
  110. }
  111. return {
  112. password,
  113. confPassword,
  114. username,
  115. register,
  116. correctConfPass: computed(() => confPassword.value == password.value),
  117. };
  118. },
  119. };
  120. </script>