FormPasswordField.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 :disabled="isDisabled" :id="this.inputId('password',fieldName)" :type="currentType" class="input" v-model="form[fieldName]" :placeholder="placeholder" v-bind="$attrs" v-on:change="$emit('field-changed', form[fieldName])"/>
  6. <span v-if="currentType == 'password'" class="icon is-small is-right is-clickable" @click="currentType = 'text'" :title="$t('auth.forms.reveal_password')">
  7. <font-awesome-icon :icon="['fas', 'eye-slash']" />
  8. </span>
  9. <span v-else class="icon is-small is-right is-clickable" @click="currentType = 'password'" :title="$t('auth.forms.hide_password')">
  10. <font-awesome-icon :icon="['fas', 'eye']" />
  11. </span>
  12. </div>
  13. <field-error :form="form" :field="fieldName" />
  14. <p class="help" v-html="help" v-if="help"></p>
  15. <div v-if="showRules" class="columns is-mobile is-size-7 mt-0">
  16. <div class="column is-one-third">
  17. <span class="has-text-weight-semibold">{{ $t("auth.forms.mandatory_rules") }}</span><br />
  18. <span class="is-underscored" :class="{'has-background-success-dark is-dot' : IsLongEnough}"></span>{{ $t('auth.forms.is_long_enough') }}<br/>
  19. </div>
  20. <div class="column">
  21. <span class="has-text-weight-semibold">{{ $t("auth.forms.optional_rules_you_should_follow") }}</span><br />
  22. <span class="is-underscored" :class="{'has-background-success-dark is-dot' : hasLowerCase}"></span>{{ $t('auth.forms.has_lower_case') }}<br/>
  23. <span class="is-underscored" :class="{'has-background-success-dark is-dot' : hasUpperCase}"></span>{{ $t('auth.forms.has_upper_case') }}<br/>
  24. <span class="is-underscored" :class="{'has-background-success-dark is-dot' : hasSpecialChar}"></span>{{ $t('auth.forms.has_special_char') }}<br/>
  25. <span class="is-underscored" :class="{'has-background-success-dark is-dot' : hasNumber}"></span>{{ $t('auth.forms.has_number') }}
  26. </div>
  27. </div>
  28. </div>
  29. </template>
  30. <script>
  31. export default {
  32. name: 'FormPasswordField',
  33. inheritAttrs: false,
  34. data() {
  35. return {
  36. currentType: this.inputType
  37. }
  38. },
  39. computed: {
  40. hasLowerCase() {
  41. return /[a-z]/.test(this.form[this.fieldName])
  42. },
  43. hasUpperCase() {
  44. return /[A-Z]/.test(this.form[this.fieldName])
  45. },
  46. hasNumber() {
  47. return /[0-9]/.test(this.form[this.fieldName])
  48. },
  49. hasSpecialChar() {
  50. return /[^A-Za-z0-9]/.test(this.form[this.fieldName])
  51. },
  52. IsLongEnough() {
  53. return this.form[this.fieldName].length >= 8
  54. },
  55. },
  56. props: {
  57. label: {
  58. type: String,
  59. default: ''
  60. },
  61. fieldName: {
  62. type: String,
  63. default: '',
  64. required: true
  65. },
  66. inputType: {
  67. type: String,
  68. default: 'password'
  69. },
  70. form: {
  71. type: Object,
  72. required: true
  73. },
  74. placeholder: {
  75. type: String,
  76. default: ''
  77. },
  78. help: {
  79. type: String,
  80. default: ''
  81. },
  82. hasOffset: {
  83. type: Boolean,
  84. default: false
  85. },
  86. isDisabled: {
  87. type: Boolean,
  88. default: false
  89. },
  90. showRules: {
  91. type: Boolean,
  92. default: false
  93. },
  94. },
  95. }
  96. </script>