login.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <section class="hero is-success is-fullheight">
  3. <div class="hero-body">
  4. <div class="container has-text-centered">
  5. <div class="column is-4 is-offset-4">
  6. <h3 class="title has-text-grey">Login</h3>
  7. <p class="subtitle has-text-grey">Please login to proceed.</p>
  8. <div class="box">
  9. <figure class="avatar">
  10. <img src="https://via.placeholder.com/300">
  11. </figure>
  12. <form>
  13. <div class="field">
  14. <div class="control">
  15. <input class="input is-large"
  16. @blur="$v.form.email.$touch()"
  17. v-model="form.email"
  18. type="email"
  19. placeholder="Your Email"
  20. autofocus=""
  21. autocomplete="email">
  22. <div v-if="$v.form.email.$error" class="form-error">
  23. <span v-if="!$v.form.email.required" class="help is-danger">Email is required</span>
  24. <span v-if="!$v.form.email.emailValidator" class="help is-danger">Email address is not valid</span>
  25. </div>
  26. </div>
  27. </div>
  28. <div class="field">
  29. <div class="control">
  30. <input
  31. @blur="$v.form.password.$touch()"
  32. v-model="form.password"
  33. class="input is-large"
  34. type="password"
  35. placeholder="Your Password"
  36. autocomplete="current-password">
  37. <div v-if="$v.form.password.$error" class="form-error">
  38. <span v-if="!$v.form.password.required" class="help is-danger">Password is required</span>
  39. </div>
  40. </div>
  41. </div>
  42. <!-- Login Button -->
  43. <button
  44. @click.prevent="login"
  45. :disabled="$v.form.$invalid"
  46. class="button is-block is-info is-large is-fullwidth">
  47. Login
  48. </button>
  49. </form>
  50. </div>
  51. <p class="has-text-grey">
  52. <a>Sign In With Google</a> &nbsp;·&nbsp;
  53. <nuxt-link to="/register">Sign Up</nuxt-link> &nbsp;·&nbsp;
  54. <a href="../">Need Help?</a>
  55. </p>
  56. </div>
  57. </div>
  58. </div>
  59. </section>
  60. </template>
  61. <script>
  62. import { required, email } from 'vuelidate/lib/validators'
  63. export default {
  64. middleware: 'guest',
  65. data() {
  66. return {
  67. form : {
  68. email : null,
  69. password : null
  70. }
  71. }
  72. },
  73. validations: {
  74. form: {
  75. email: {
  76. emailValidator : email,
  77. required
  78. },
  79. password: {
  80. required
  81. }
  82. }
  83. },
  84. computed : {
  85. isFormValid() {
  86. return !this.$v.$invalid
  87. }
  88. },
  89. methods: {
  90. async login() {
  91. // console.log(this.form)
  92. this.$v.form.$touch()
  93. if(this.isFormValid){
  94. const result = await this.$store.dispatch('auth/login', this.form)
  95. console.log('login.vue login done this.$store.dispatch');
  96. console.log(result);
  97. if(result.isAxiosError === true){
  98. this.$toasted.error('Wrong email or password', {duration: 3000})
  99. }else{
  100. this.$router.push('/')
  101. }
  102. }
  103. }
  104. }
  105. }
  106. </script>
  107. <style scoped>
  108. .hero.is-success {
  109. background: #F2F6FA;
  110. }
  111. .hero .nav, .hero.is-success .nav {
  112. -webkit-box-shadow: none;
  113. box-shadow: none;
  114. }
  115. .box {
  116. margin-top: 5rem;
  117. }
  118. .avatar {
  119. margin-top: -70px;
  120. padding-bottom: 20px;
  121. }
  122. .avatar img {
  123. height: 128px;
  124. width: 128px;
  125. padding: 5px;
  126. background: #fff;
  127. border-radius: 50%;
  128. -webkit-box-shadow: 0 2px 3px rgba(10,10,10,.1), 0 0 0 1px rgba(10,10,10,.1);
  129. box-shadow: 0 2px 3px rgba(10,10,10,.1), 0 0 0 1px rgba(10,10,10,.1);
  130. }
  131. p.subtitle {
  132. padding-top: 1rem;
  133. }
  134. </style>