Browse Source

Allow password reset requests from settings.vue

master
Immanuel Onyeka 1 year ago
parent
commit
24f34e47db
1 changed files with 44 additions and 5 deletions
  1. +44
    -5
      components/settings.vue

+ 44
- 5
components/settings.vue View File

@@ -43,11 +43,16 @@

<section class="form inputs special">
<h3>Login</h3>
<label for="">Email</label>
<input type="text">
<label for="">Old Password</label>
<input type="text" v-model="oldPass">
<label for="">New Password</label>
<input type="text">
<button @click="check">Save</button>
<input type="text" v-model="newPass">
<label for="">Confirm Password</label>
<input type="text" v-model="confirmPass">
<button
:disabled="!(oldPass && newPass && confirmPass)"
@click="check">Save</button>
<label class="error">{{passError}}</label>
</section>

<Dialog v-if="ready" @close="() => ready = false">
@@ -68,8 +73,11 @@ let letterhead = ref(null) // the canvas element
let ready = ref(false)
let avatarChanged = ref(false)
let avatarError = ref('')
let letterHeadError = ref('')
let letterheadError = ref('')
let passError = ref('')
let oldPass = ref('')
let newPass = ref('')
let confirmPass = ref('')
const props = defineProps(['user', 'token'])
const emit = defineEmits(['updateAvatar', 'updateLetterhead'])
let user = Object.assign({}, props.user)
@@ -181,6 +189,37 @@ function saveProfile() {
})
}

function changePassword(f) {
const validTypes = ['image/jpeg', 'image/png']
if (!validTypes.includes(f.type)) {
letterheadError.value = 'Image must be JPEG of PNG format'
return
}
fetch(`/api/user/password`,
{method: 'POST',
body: JSON.stringify({
oldPass: oldPass.value,
newPass: newPass.value,
confirmPass: confirmPass.value,
}),
headers: {
"Accept": "application/json",
"Authorization": `Bearer ${props.token}`,
},
}).then(resp => {
if (resp.ok) {
resp.blob().then(b => {
oldPass.value = ""
newPass.value = ""
confirmPass.value = ""
})
} else {
resp.text().then(e => passError.value = e)
}
})
}

watch(props.user, (u) => {
if (props.user.avatar) {
changeAvatar(props.user.avatar)


Loading…
Cancel
Save