Login.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <template>
  2. <div class="auth-wrapper auth-v2">
  3. <b-row class="auth-inner m-0">
  4. <!-- Brand logo-->
  5. <b-link class="brand-logo">
  6. <vuexy-logo />
  7. <h2 class="brand-text text-primary ml-1">
  8. Vuexy
  9. </h2>
  10. </b-link>
  11. <!-- /Brand logo-->
  12. <!-- Left Text-->
  13. <b-col
  14. lg="8"
  15. class="d-none d-lg-flex align-items-center p-5"
  16. >
  17. <div class="w-100 d-lg-flex align-items-center justify-content-center px-5">
  18. <b-img
  19. fluid
  20. :src="imgUrl"
  21. alt="Login V2"
  22. />
  23. </div>
  24. </b-col>
  25. <!-- /Left Text-->
  26. <!-- Login-->
  27. <b-col
  28. lg="4"
  29. class="d-flex align-items-center auth-bg px-2 p-lg-5"
  30. >
  31. <b-col
  32. sm="8"
  33. md="6"
  34. lg="12"
  35. class="px-xl-2 mx-auto"
  36. >
  37. <b-card-title
  38. title-tag="h2"
  39. class="font-weight-bold mb-1"
  40. >
  41. Welcome to Vuexy! 👋
  42. </b-card-title>
  43. <b-card-text class="mb-2">
  44. Please sign-in to your account and start the adventure
  45. </b-card-text>
  46. <!-- form -->
  47. <validation-observer ref="loginValidation">
  48. <b-form
  49. class="auth-login-form mt-2"
  50. @submit.prevent
  51. >
  52. <!-- email -->
  53. <b-form-group
  54. label="Email"
  55. label-for="login-email"
  56. >
  57. <validation-provider
  58. #default="{ errors }"
  59. name="Email"
  60. rules="required|email"
  61. >
  62. <b-form-input
  63. id="login-email"
  64. ref="inputEmail"
  65. v-model="userEmail"
  66. :state="errors.length > 0 ? false:null"
  67. name="login-email"
  68. placeholder="john@example.com"
  69. />
  70. <small class="text-danger">{{ errors[0] }}</small>
  71. </validation-provider>
  72. </b-form-group>
  73. <!-- forgot password -->
  74. <b-form-group>
  75. <div class="d-flex justify-content-between">
  76. <label for="login-password">Password</label>
  77. <b-link :to="{name:'auth-forgot-password-v2'}">
  78. <small>Forgot Password?</small>
  79. </b-link>
  80. </div>
  81. <validation-provider
  82. #default="{ errors }"
  83. name="Password"
  84. rules="required"
  85. >
  86. <b-input-group
  87. class="input-group-merge"
  88. :class="errors.length > 0 ? 'is-invalid':null"
  89. >
  90. <b-form-input
  91. id="login-password"
  92. ref="inputPassword"
  93. v-model="password"
  94. :state="errors.length > 0 ? false:null"
  95. class="form-control-merge"
  96. :type="passwordFieldType"
  97. name="login-password"
  98. placeholder="············"
  99. />
  100. <b-input-group-append is-text>
  101. <feather-icon
  102. class="cursor-pointer"
  103. :icon="passwordToggleIcon"
  104. @click="togglePasswordVisibility"
  105. />
  106. </b-input-group-append>
  107. </b-input-group>
  108. <small class="text-danger">{{ errors[0] }}</small>
  109. </validation-provider>
  110. </b-form-group>
  111. <!-- checkbox -->
  112. <b-form-group>
  113. <b-form-checkbox
  114. id="remember-me"
  115. v-model="status"
  116. name="checkbox-1"
  117. >
  118. Remember Me
  119. </b-form-checkbox>
  120. </b-form-group>
  121. <!-- submit buttons -->
  122. <b-button
  123. type="submit"
  124. variant="primary"
  125. block
  126. @click="validationForm"
  127. >
  128. Sign in
  129. </b-button>
  130. </b-form>
  131. </validation-observer>
  132. <b-card-text class="text-center mt-2">
  133. <span>New on our platform? </span>
  134. <b-link :to="{name:'page-auth-register-v2'}">
  135. <span>&nbsp;Create an account</span>
  136. </b-link>
  137. </b-card-text>
  138. <!-- divider -->
  139. <div class="divider my-2">
  140. <div class="divider-text">
  141. or
  142. </div>
  143. </div>
  144. <!-- social buttons -->
  145. <div class="auth-footer-btn d-flex justify-content-center">
  146. <b-button
  147. variant="facebook"
  148. href="javascript:void(0)"
  149. >
  150. <feather-icon icon="FacebookIcon" />
  151. </b-button>
  152. <b-button
  153. variant="twitter"
  154. href="javascript:void(0)"
  155. >
  156. <feather-icon icon="TwitterIcon" />
  157. </b-button>
  158. <b-button
  159. variant="google"
  160. href="javascript:void(0)"
  161. >
  162. <feather-icon icon="MailIcon" />
  163. </b-button>
  164. <b-button
  165. variant="github"
  166. href="javascript:void(0)"
  167. >
  168. <feather-icon icon="GithubIcon" />
  169. </b-button>
  170. </div>
  171. </b-col>
  172. </b-col>
  173. <!-- /Login-->
  174. </b-row>
  175. </div>
  176. </template>
  177. <script>
  178. /* eslint-disable global-require */
  179. import { ValidationProvider, ValidationObserver } from 'vee-validate'
  180. import VuexyLogo from '@core/layouts/components/Logo.vue'
  181. import {
  182. BRow, BCol, BLink, BFormGroup, BFormInput, BInputGroupAppend, BInputGroup, BFormCheckbox, BCardText, BCardTitle, BImg, BForm, BButton,
  183. } from 'bootstrap-vue'
  184. import { required, email } from '@validations'
  185. import { togglePasswordVisibility } from '@core/mixins/ui/forms'
  186. import store from '@/store/index'
  187. import ToastificationContent from '@core/components/toastification/ToastificationContent.vue'
  188. import useJwt from '@/auth/jwt/useJwt'
  189. export default {
  190. components: {
  191. BRow,
  192. BCol,
  193. BLink,
  194. BFormGroup,
  195. BFormInput,
  196. BInputGroupAppend,
  197. BInputGroup,
  198. BFormCheckbox,
  199. BCardText,
  200. BCardTitle,
  201. BImg,
  202. BForm,
  203. BButton,
  204. VuexyLogo,
  205. ValidationProvider,
  206. ValidationObserver,
  207. },
  208. mixins: [togglePasswordVisibility],
  209. data() {
  210. return {
  211. status: '',
  212. password: '',
  213. userEmail: '',
  214. sideImg: require('@/assets/images/pages/login-v2.svg'),
  215. // validation rulesimport store from '@/store/index'
  216. required,
  217. email,
  218. }
  219. },
  220. computed: {
  221. passwordToggleIcon() {
  222. return this.passwordFieldType === 'password' ? 'EyeIcon' : 'EyeOffIcon'
  223. },
  224. imgUrl() {
  225. if (store.state.appConfig.layout.skin === 'dark') {
  226. // eslint-disable-next-line vue/no-side-effects-in-computed-properties
  227. this.sideImg = require('@/assets/images/pages/login-v2-dark.svg')
  228. return this.sideImg
  229. }
  230. return this.sideImg
  231. },
  232. },
  233. methods: {
  234. validationForm() {
  235. this.$refs.loginValidation.validate().then(success => {
  236. if (success) {
  237. this.$toast({
  238. component: ToastificationContent,
  239. props: {
  240. title: 'Form Submitted',
  241. icon: 'EditIcon',
  242. variant: 'success',
  243. },
  244. })
  245. useJwt.login({ email: this.$refs.inputEmail.value, password: this.$refs.inputPassword.value })
  246. .then(res => {
  247. useJwt.setToken(res.data.token)
  248. localStorage.setItem('userData', res.data.userData)
  249. if (this.$route.query.redirect) {
  250. this.$router.push(this.$route.query.redirect)
  251. } else {
  252. this.$router.push('/')
  253. }
  254. })
  255. }
  256. })
  257. },
  258. },
  259. }
  260. </script>
  261. <style lang="scss">
  262. @import '@resources/scss/vue/pages/page-auth.scss';
  263. </style>