Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
intrn(authentication): make component to ask for password automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethTrecy committed Oct 11, 2022
1 parent ca025c5 commit c3dba93
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions components/authentication/change_password.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<template>
<Overlay :is-shown="isOverlayShown">
<template #header>
<h1>Update your password</h1>
</template>
<template #default>
<form class="verification">
<SensitiveTextField
v-model="currentPassword"
label="Current password"
placeholder="enter your current password"/>
<SensitiveTextField
v-model="newPassword"
label="New password"
placeholder="enter your new password"/>
<SensitiveTextField
v-model="confirmNewPassword"
label="Confirm new password"
placeholder="confirm your new password"/>
</form>
</template>
<template #footer>
<button type="button" @click="savePassword">
Save password
</button>
</template>
</Overlay>
</template>

<style scoped lang="scss">
.verification {
@apply flex flex-col text-black;
label {
padding: .5em 1em;
input {
padding: .25em .5em;
}
}
}
</style>

<script setup lang="ts">
import { ref, inject, onMounted } from "vue"
import type { PageContext } from "$/types/renderer"
import Fetcher from "$@/fetchers/user"
import makeSwitch from "$@/helpers/make_switch"
import Overlay from "@/helpers/overlay.vue"
import SensitiveTextField from "@/fields/sensitive_text.vue"
const pageContext = inject("pageContext") as PageContext<"deserialized">
const { pageProps } = pageContext
const { userProfile } = pageProps
const {
"off": closeDialog,
"on": openDialog,
"state": isOverlayShown
} = makeSwitch(false)
const currentPassword = ref<string>("")
const newPassword = ref<string>("")
const confirmNewPassword = ref<string>("")
const fetcher: Fetcher = new Fetcher()
function clearPasswords(): void {
[
currentPassword,
newPassword,
confirmNewPassword
].forEach(password => {
password.value = ""
})
}
function cancel(): void {
clearPasswords()
closeDialog()
}
function savePassword() {
fetcher.updatePassword(
userProfile.data.id,
currentPassword.value,
newPassword.value,
confirmNewPassword.value
).then(cancel)
}
onMounted(() => {
if (userProfile.meta.hasDefaultPassword) {
openDialog()
}
})
</script>

0 comments on commit c3dba93

Please sign in to comment.