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.

84 lines
1.8 KiB

5 years ago
4 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <template>
  2. <base-card
  3. :disabled="!valid"
  4. :title="$t('user.login')"
  5. :agree-text="$t('user.login')"
  6. @agree="tryLogin"
  7. >
  8. <template #content>
  9. <v-form v-model="valid">
  10. <v-alert
  11. v-show="showError"
  12. v-model="showError"
  13. type="error"
  14. dismissible
  15. >
  16. {{ $t('errors.invalidUserOrPass') }}
  17. </v-alert>
  18. <v-text-field
  19. v-model="username"
  20. :rules="userNameRules($t('rules.userNameRules'))"
  21. :label="$t('user.username')"
  22. name="username"
  23. prepend-icon="person"
  24. type="text"
  25. autofocus
  26. @keyup.enter="tryLogin"
  27. />
  28. <v-text-field
  29. id="password"
  30. v-model="password"
  31. :rules="passwordRules($t('rules.passwordRules'))"
  32. :label="$t('user.password')"
  33. name="password"
  34. prepend-icon="lock"
  35. type="password"
  36. @keyup.enter="tryLogin"
  37. />
  38. </v-form>
  39. </template>
  40. </base-card>
  41. </template>
  42. <script lang="ts">
  43. import Vue from 'vue'
  44. import { userNameRules, passwordRules } from '@/rules/index'
  45. import BaseCard from '@/components/utils/BaseCard.vue'
  46. export default Vue.extend({
  47. components: {
  48. BaseCard
  49. },
  50. props: {
  51. login: {
  52. type: Function,
  53. default: (username: string, password: string) => Promise
  54. }
  55. },
  56. data() {
  57. return {
  58. valid: false,
  59. username: '',
  60. password: '',
  61. userNameRules,
  62. passwordRules,
  63. showError: false
  64. }
  65. },
  66. methods: {
  67. async tryLogin() {
  68. try {
  69. await this.login({
  70. username: this.username,
  71. password: this.password
  72. })
  73. this.$router.push(this.localePath('/projects'))
  74. } catch {
  75. this.showError = true
  76. }
  77. }
  78. }
  79. })
  80. </script>