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.

92 lines
1.9 KiB

5 years ago
4 years ago
5 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
  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
  10. ref="form"
  11. v-model="valid"
  12. >
  13. <v-alert
  14. v-show="showError"
  15. v-model="showError"
  16. type="error"
  17. dismissible
  18. >
  19. Incorrect username or password or something went wrong.
  20. </v-alert>
  21. <v-text-field
  22. v-model="username"
  23. :rules="userNameRules($t('rules.userNameRules'))"
  24. :label="$t('user.username')"
  25. name="username"
  26. prepend-icon="person"
  27. type="text"
  28. autofocus
  29. @keyup.enter="tryLogin"
  30. />
  31. <v-text-field
  32. id="password"
  33. v-model="password"
  34. :rules="passwordRules($t('rules.passwordRules'))"
  35. :label="$t('user.password')"
  36. name="password"
  37. prepend-icon="lock"
  38. type="password"
  39. @keyup.enter="tryLogin"
  40. />
  41. </v-form>
  42. </template>
  43. </base-card>
  44. </template>
  45. <script>
  46. import { userNameRules, passwordRules } from '@/rules/index'
  47. import BaseCard from '@/components/molecules/BaseCard'
  48. export default {
  49. components: {
  50. BaseCard
  51. },
  52. props: {
  53. login: {
  54. type: Function,
  55. default: () => {}
  56. }
  57. },
  58. data() {
  59. return {
  60. valid: false,
  61. username: '',
  62. password: '',
  63. userNameRules,
  64. passwordRules,
  65. showError: false
  66. }
  67. },
  68. methods: {
  69. validate() {
  70. return this.$refs.form.validate()
  71. },
  72. tryLogin() {
  73. if (this.validate()) {
  74. this.login({
  75. username: this.username,
  76. password: this.password
  77. })
  78. .then((result) => {
  79. this.$router.push(this.localePath('/projects'))
  80. })
  81. .catch(() => {
  82. this.showError = true
  83. })
  84. }
  85. }
  86. }
  87. }
  88. </script>