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.

105 lines
4.3 KiB

  1. <template>
  2. <section class="vh-100 background-color">
  3. <div class="container py-5 h-100">
  4. <div class="row justify-content-center align-items-center h-100">
  5. <div class="col-12 col-lg-9 col-xl-7">
  6. <div class="card shadow-2-strong card-registration border-2" style="border-radius: 15px;">
  7. <div class="card-body p-4 p-md-5">
  8. <h3 class="mb-4 pb-2 pb-md-0 mb-md-5">Login</h3>
  9. <Form @submit="login" v-slot="{ meta, errors }">
  10. <div class="row">
  11. <div class="col-md-12 mb-4 pb-2">
  12. <div class="form-outline">
  13. <Field
  14. v-model="email"
  15. type="email"
  16. id="emailAddress"
  17. name="Email"
  18. class="form-control form-control-lg"
  19. :class="errors['Email'] ? 'invalid' : ''"
  20. rules="required|email"/>
  21. <label v-if="!errors['Email']" class="form-label" for="email">Email</label>
  22. <ErrorMessage name="Email" as="label" class="form-label" for="email"/>
  23. </div>
  24. </div>
  25. </div>
  26. <div class="row">
  27. <div class="col-md-12 mb-4 pb-2">
  28. <div class="form-outline">
  29. <Field
  30. v-model="password"
  31. type="password"
  32. id="emailAddress"
  33. name="Password"
  34. class="form-control form-control-lg"
  35. :class="errors['Password'] ? 'invalid' : ''"
  36. rules="required|min:8"/>
  37. <label v-if="!errors['Password']" class="form-label" for="password">Password</label>
  38. <ErrorMessage name="Password" as="label" class="form-label" for="password"/>
  39. </div>
  40. </div>
  41. </div>
  42. <div class="mt-2 pt-2 center-align">
  43. <button
  44. :disabled="!meta.touched || !meta.valid"
  45. class="btn btn-primary btn-lg"
  46. type="submit"
  47. >
  48. Login
  49. </button>
  50. </div>
  51. <div class="mt-2 pt-2 center-align">
  52. <p style="padding-right: 10px;">Don't have an account? </p><router-link :to='{"name": "AdminSignup"}'>Sign up</router-link>
  53. </div>
  54. </Form>
  55. </div>
  56. </div>
  57. </div>
  58. </div>
  59. </div>
  60. </section>
  61. </template>
  62. <script>
  63. import { Form, Field, ErrorMessage } from 'vee-validate'
  64. export default {
  65. name: 'AdminLogin',
  66. data() {
  67. return {
  68. email: '',
  69. password: '',
  70. }
  71. },
  72. components: {
  73. Form,
  74. Field,
  75. ErrorMessage,
  76. },
  77. methods: {
  78. async login () {
  79. try {
  80. const response = await this.axios.post(
  81. '/admin/login',
  82. {
  83. email: this.email,
  84. password: this.password,
  85. }
  86. )
  87. if (response.status === 200) {
  88. this.$store.dispatch('setUser', response.data)
  89. this.$router.push({ name: 'AdminUsersList' })
  90. }
  91. } catch (error) {
  92. this.$toast.error('An error occured')
  93. }
  94. }
  95. }
  96. }
  97. </script>