-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #724 from webitel/fix/user-password-input
fix: password regex input [WTEL-4784, WTEL-4785, WTEL-4786]
- Loading branch information
Showing
9 changed files
with
239 additions
and
128 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<template> | ||
<generate-password-input | ||
:v="v$.model" | ||
:value="model" | ||
class="user-password-input" | ||
v-bind="attrs" | ||
@input="model = $event" | ||
/> | ||
</template> | ||
|
||
<script setup> | ||
import { useVuelidate } from '@vuelidate/core'; | ||
import { helpers, required } from '@vuelidate/validators'; | ||
import { computed, ref, useAttrs } from 'vue'; | ||
import { useRoute } from 'vue-router'; | ||
import { EngineSystemSettingName } from 'webitel-sdk'; | ||
import ConfigurationAPI from '../../../modules/system/modules/configuration/api/configuration.js'; | ||
import GeneratePasswordInput from './generate-password-input.vue'; | ||
const model = defineModel({ | ||
type: String, | ||
default: '', | ||
}); | ||
const attrs = useAttrs(); | ||
const route = useRoute(); | ||
const vRegex = ref(false); | ||
const vErrorText = ref(false); | ||
// bad check: implicit dependency :( | ||
const isNew = computed(() => { | ||
// settings page allows empty value, because it's password edit | ||
return route.fullPath.includes('new'); | ||
}); | ||
const v$ = useVuelidate( | ||
computed(() => { | ||
const vRegexRule = (v) => (vRegex.value ? vRegex.value.test(v) : false); | ||
const regex = helpers.withParams( | ||
{ regex: vRegex.value }, | ||
vErrorText.value ? helpers.withMessage(vErrorText.value, vRegexRule) : vRegexRule, | ||
); | ||
if (isNew.value) { | ||
return { | ||
model: { | ||
required, | ||
regex, | ||
}, | ||
}; | ||
} | ||
return { | ||
model: model.value ? { regex } : {}, | ||
}; | ||
}), | ||
{ model }, | ||
{ | ||
$autoDirty: true, | ||
}, | ||
); | ||
const loadV = async () => { | ||
const configurations = await ConfigurationAPI.getList({ | ||
name: [EngineSystemSettingName.PasswordRegExp, EngineSystemSettingName.PasswordValidationText], | ||
}); | ||
const regex = configurations.items.find( | ||
({ name }) => name === EngineSystemSettingName.PasswordRegExp, | ||
)?.value; | ||
if (!regex) return; | ||
const errorText = configurations.items.find( | ||
({ name }) => name === EngineSystemSettingName.PasswordValidationText, | ||
)?.value; | ||
vRegex.value = new RegExp(regex); | ||
vErrorText.value = errorText; | ||
}; | ||
loadV(); | ||
</script> | ||
<style lang="scss" scoped> | ||
.user-password-input { | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<template> | ||
<article class="change-password"> | ||
<header class="content-header"> | ||
<h3 class="content-title"> | ||
{{ $t('settings.changePassword') }} | ||
</h3> | ||
</header> | ||
<form @submit="changePassword"> | ||
<user-password-input | ||
:model-value="newPassword" | ||
:label="$t('auth.password')" | ||
@update:model-value="newPassword = $event" | ||
/> | ||
<wt-input | ||
v-model="confirmNewPassword" | ||
:label="$t('auth.confirmPassword')" | ||
:v="v$.confirmNewPassword" | ||
type="password" | ||
/> | ||
<wt-button | ||
:disabled="v$.$invalid" | ||
:loading="isPasswordPatching" | ||
type="submit" | ||
@click.prevent="changePassword" | ||
> | ||
{{ $t('objects.save') }} | ||
</wt-button> | ||
</form> | ||
</article> | ||
</template> | ||
|
||
<script setup> | ||
import { useVuelidate } from '@vuelidate/core'; | ||
import { required, sameAs } from '@vuelidate/validators'; | ||
import getNamespacedState from '@webitel/ui-sdk/src/store/helpers/getNamespacedState'; | ||
import { computed, inject, ref } from 'vue'; | ||
import { useStore } from 'vuex'; | ||
import UserPasswordInput from '../../../app/components/utils/user-password-input.vue'; | ||
import { changePassword as requestChangePassword } from '../api/settings'; | ||
const $eventBus = inject('$eventBus'); | ||
const store = useStore(); | ||
const userId = computed(() => getNamespacedState(store.state, 'userinfo').userId); | ||
const isPasswordPatching = ref(false); | ||
const newPassword = ref(''); | ||
const confirmNewPassword = ref(''); | ||
const v$ = useVuelidate( | ||
computed(() => ({ | ||
confirmNewPassword: { | ||
sameAs: sameAs(newPassword), | ||
}, | ||
})), | ||
{ newPassword, confirmNewPassword }, | ||
{ $autoDirty: true }, | ||
); | ||
async function changePassword() { | ||
try { | ||
isPasswordPatching.value = true; | ||
const changes = { | ||
password: newPassword.value, | ||
}; | ||
await requestChangePassword({ | ||
id: userId.value, | ||
changes, | ||
}); | ||
$eventBus.$emit('notification', { | ||
type: 'success', | ||
text: 'Password is successfully updated!', | ||
}); | ||
} finally { | ||
isPasswordPatching.value = false; | ||
} | ||
} | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.change-password { | ||
} | ||
</style> |
Oops, something went wrong.