-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
147 additions
and
1 deletion.
There are no files selected for viewing
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,97 @@ | ||
<!-- | ||
Copyright (C) 2023 Nethesis S.r.l. | ||
SPDX-License-Identifier: GPL-3.0-or-later | ||
--> | ||
|
||
<script lang="ts" setup> | ||
import { | ||
getAxiosErrorMessage, | ||
NeButton, | ||
NeInlineNotification, | ||
NeTextInput | ||
} from '@nethserver/vue-tailwind-lib' | ||
import { ref } from 'vue' | ||
import { useI18n } from 'vue-i18n' | ||
import { MessageBag, validateEqual, validatePassword, validateRequired } from '@/lib/validation' | ||
import { useLoginStore } from '@/stores/standalone/standaloneLogin' | ||
import { ubusCall } from '@/lib/standalone/ubus' | ||
import type { AxiosError } from 'axios' | ||
|
||
const { t } = useI18n() | ||
|
||
const loginStore = useLoginStore() | ||
|
||
const newPassword = ref('') | ||
const confirmPassword = ref('') | ||
|
||
const validationBag = ref(new MessageBag()) | ||
|
||
const loading = ref(false) | ||
const error = ref<Error>() | ||
const success = ref(false) | ||
|
||
function validate(): boolean { | ||
validationBag.value.clear() | ||
let errMessage = validateRequired(newPassword.value).errMessage | ||
if (errMessage) { | ||
validationBag.value.set('new_password', String(errMessage)) | ||
} | ||
errMessage = validatePassword(newPassword.value).errMessage | ||
if (errMessage) { | ||
validationBag.value.set('new_password', String(errMessage)) | ||
} | ||
errMessage = validateEqual(newPassword.value, confirmPassword.value).errMessage | ||
if (errMessage) { | ||
validationBag.value.set('confirm_password', String(errMessage)) | ||
} | ||
return validationBag.value.size == 0 | ||
} | ||
|
||
function updatePassword() { | ||
if (validate()) { | ||
loading.value = true | ||
success.value = false | ||
ubusCall('ns.account', 'set-password', { | ||
username: loginStore.username, | ||
password: newPassword.value | ||
}) | ||
.then(() => { | ||
success.value = true | ||
newPassword.value = '' | ||
confirmPassword.value = '' | ||
}) | ||
.catch((reason: AxiosError) => (error.value = reason)) | ||
.finally(() => (loading.value = false)) | ||
} | ||
} | ||
</script> | ||
|
||
<template> | ||
<div class="space-y-6"> | ||
<NeInlineNotification v-if="error" :title="t(getAxiosErrorMessage(error))" kind="error" /> | ||
<NeInlineNotification | ||
v-if="success" | ||
:title="t('standalone.change_password.success_message')" | ||
kind="success" | ||
/> | ||
<NeTextInput | ||
v-model="newPassword" | ||
:disabled="loading" | ||
:invalid-message="t(validationBag.getFirstFor('new_password'))" | ||
:label="t('standalone.change_password.new_password')" | ||
is-password | ||
/> | ||
<NeTextInput | ||
v-model="confirmPassword" | ||
:disabled="loading" | ||
:invalid-message="t(validationBag.getFirstFor('confirm_password'))" | ||
:label="t('standalone.change_password.confirm_password')" | ||
is-password | ||
/> | ||
<div class="flex justify-end"> | ||
<NeButton :disabled="loading" :loading="loading" kind="primary" @click="updatePassword()"> | ||
{{ t('common.save') }} | ||
</NeButton> | ||
</div> | ||
</div> | ||
</template> |
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,28 @@ | ||
<!-- | ||
Copyright (C) 2023 Nethesis S.r.l. | ||
SPDX-License-Identifier: GPL-3.0-or-later | ||
--> | ||
|
||
<script lang="ts" setup> | ||
import { NeTitle } from '@nethserver/vue-tailwind-lib' | ||
import { useI18n } from 'vue-i18n' | ||
import ChangePassword from '@/components/standalone/account/ChangePassword.vue' | ||
import { useLoginStore } from '@/stores/standalone/standaloneLogin' | ||
import FormLayout from '@/components/standalone/FormLayout.vue' | ||
|
||
const { t } = useI18n() | ||
|
||
const loginStore = useLoginStore() | ||
</script> | ||
|
||
<template> | ||
<NeTitle>{{ t('standalone.account_management.title', { name: loginStore.username }) }}</NeTitle> | ||
<div class="max-w-3xl"> | ||
<FormLayout | ||
:title="t('standalone.account_management.change_password')" | ||
:description="t('standalone.account_management.change_password_description')" | ||
> | ||
<ChangePassword /> | ||
</FormLayout> | ||
</div> | ||
</template> |