FormPasswordField.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <div class="field" :class="{ 'pt-3' : hasOffset }">
  3. <label :for="this.inputId('password',fieldName)" class="label" v-html="label"></label>
  4. <div class="control has-icons-right">
  5. <input
  6. :disabled="isDisabled"
  7. :id="this.inputId('password',fieldName)"
  8. :type="currentType"
  9. class="input"
  10. v-model="form[fieldName]"
  11. :placeholder="placeholder"
  12. v-bind="$attrs"
  13. v-on:change="$emit('field-changed', form[fieldName])"
  14. v-on:keyup="checkCapsLock"
  15. />
  16. <span v-if="currentType == 'password'" role="button" tabindex="0" class="icon is-small is-right is-clickable" @keyup.enter="setFieldType('text')" @click="setFieldType('text')" :title="$t('auth.forms.reveal_password')">
  17. <font-awesome-icon :icon="['fas', 'eye-slash']" />
  18. </span>
  19. <span v-else role="button" tabindex="0" class="icon is-small is-right is-clickable" @keyup.enter="setFieldType('password')" @click="setFieldType('password')" :title="$t('auth.forms.hide_password')">
  20. <font-awesome-icon :icon="['fas', 'eye']" />
  21. </span>
  22. </div>
  23. <p class="help is-warning" v-if="hasCapsLockOn" v-html="$t('auth.forms.caps_lock_is_on')" />
  24. <field-error :form="form" :field="fieldName" />
  25. <p class="help" v-html="help" v-if="help"></p>
  26. <div v-if="showRules" class="columns is-mobile is-size-7 mt-0">
  27. <div class="column is-one-third">
  28. <span class="has-text-weight-semibold">{{ $t("auth.forms.mandatory_rules") }}</span><br />
  29. <span class="is-underscored" :class="{'is-dot' : IsLongEnough}"></span>{{ $t('auth.forms.is_long_enough') }}<br/>
  30. </div>
  31. <div class="column">
  32. <span class="has-text-weight-semibold">{{ $t("auth.forms.optional_rules_you_should_follow") }}</span><br />
  33. <span class="is-underscored" :class="{'is-dot' : hasLowerCase}"></span>{{ $t('auth.forms.has_lower_case') }}<br/>
  34. <span class="is-underscored" :class="{'is-dot' : hasUpperCase}"></span>{{ $t('auth.forms.has_upper_case') }}<br/>
  35. <span class="is-underscored" :class="{'is-dot' : hasSpecialChar}"></span>{{ $t('auth.forms.has_special_char') }}<br/>
  36. <span class="is-underscored" :class="{'is-dot' : hasNumber}"></span>{{ $t('auth.forms.has_number') }}
  37. </div>
  38. </div>
  39. </div>
  40. </template>
  41. <script>
  42. export default {
  43. name: 'FormPasswordField',
  44. inheritAttrs: false,
  45. data() {
  46. return {
  47. currentType: this.inputType,
  48. hasCapsLockOn: false,
  49. }
  50. },
  51. computed: {
  52. hasLowerCase() {
  53. return /[a-z]/.test(this.form[this.fieldName])
  54. },
  55. hasUpperCase() {
  56. return /[A-Z]/.test(this.form[this.fieldName])
  57. },
  58. hasNumber() {
  59. return /[0-9]/.test(this.form[this.fieldName])
  60. },
  61. hasSpecialChar() {
  62. return /[^A-Za-z0-9]/.test(this.form[this.fieldName])
  63. },
  64. IsLongEnough() {
  65. return this.form[this.fieldName].length >= 8
  66. },
  67. },
  68. props: {
  69. label: {
  70. type: String,
  71. default: ''
  72. },
  73. fieldName: {
  74. type: String,
  75. default: '',
  76. required: true
  77. },
  78. inputType: {
  79. type: String,
  80. default: 'password'
  81. },
  82. form: {
  83. type: Object,
  84. required: true
  85. },
  86. placeholder: {
  87. type: String,
  88. default: ''
  89. },
  90. help: {
  91. type: String,
  92. default: ''
  93. },
  94. hasOffset: {
  95. type: Boolean,
  96. default: false
  97. },
  98. isDisabled: {
  99. type: Boolean,
  100. default: false
  101. },
  102. showRules: {
  103. type: Boolean,
  104. default: false
  105. },
  106. },
  107. methods: {
  108. checkCapsLock(event) {
  109. this.hasCapsLockOn = event.getModifierState('CapsLock') ? true : false
  110. },
  111. setFieldType(event) {
  112. if (this.currentType != event) {
  113. this.currentType = event
  114. }
  115. }
  116. },
  117. }
  118. </script>