Add password reset to profile

This commit is contained in:
Johannes Zellner
2025-01-14 11:54:19 +01:00
parent 109eefa7e3
commit 63b5e28537
2 changed files with 69 additions and 26 deletions
+43 -26
View File
@@ -14,40 +14,31 @@
<table style="width: 100%; max-width: 1024px;">
<tbody>
<tr>
<td class="text-muted" style="vertical-align: top;">{{ $t('main.username') }}</td>
<td class="text-right" style="vertical-align: top;">
{{ user.username }} &nbsp;&nbsp;&nbsp;
</td>
<td class="text-muted">{{ $t('main.username') }}</td>
<td style="width: 100px; height: 34px;">{{ user.username }}</td>
<td style="width: 32px"></td>
</tr>
<tr>
<td class="text-muted" style="vertical-align: top;">{{ $t('main.displayName') }}</td>
<td class="text-right" style="vertical-align: top; white-space: nowrap;">
{{ user.displayName }} <Button small tool outline @click="onChangeDisplayName(user.displayName)" v-show="!user.source && !config.profileLocked" icon="fa fa-edit text-small" />
</td>
<td class="text-muted">{{ $t('main.displayName') }}</td>
<td style="white-space: nowrap;">{{ user.displayName }}</td>
<td><Button small tool outline @click="onChangeDisplayName(user.displayName)" v-show="!user.source && !config.profileLocked" icon="fa fa-edit text-small" /></td>
</tr>
<tr>
<td class="text-muted" style="vertical-align: top;">{{ $t('profile.primaryEmail') }}</td>
<td class="text-right" style="vertical-align: top; white-space: nowrap;">
{{ user.email }} <Button small tool outline @click="onChangeEmail(user.email)" v-show="!user.source && !config.profileLocked" icon="fa fa-edit text-small" />
</td>
<td class="text-muted">{{ $t('profile.primaryEmail') }}</td>
<td style="white-space: nowrap;">{{ user.email }}</td>
<td><Button small tool outline @click="onChangeEmail(user.email)" v-show="!user.source && !config.profileLocked" icon="fa fa-edit text-small" /></td>
</tr>
<tr>
<td class="text-muted" style="vertical-align: top;">{{ $t('profile.passwordRecoveryEmail') }}</td>
<td class="text-right" style="vertical-align: top; white-space: nowrap;">
{{ user.fallbackEmail }} <a href="" ng-click="fallbackEmailChange.show()" ng-hide="user.source || config.profileLocked"><i class="fa fa-edit text-small"></i></a>
</td>
<td class="text-muted">{{ $t('profile.passwordRecoveryEmail') }}</td>
<td style="white-space: nowrap;">{{ user.fallbackEmail }}</td>
<td><Button small tool outline @click="onChangeFallbackEmail(user.fallbackEmail)" v-show="!user.source && !config.profileLocked" icon="fa fa-edit text-small" /></td>
</tr>
<tr ng-hide="user.source">
<td colspan="2" class="text-right">
<a href="" ng-click="sendPasswordReset()">{{ $t('profile.passwordResetAction') }}</a>
</td>
</tr>
<tr><td colspan="2">&nbsp;</td></tr>
<tr>
<td class="text-muted" style="vertical-align: middle;">{{ $t('profile.language') }}</td>
<td class="text-right" style="vertical-align: middle;">
<Dropdown small v-model="language" :options="languages" option-label="display" option-key="id" @select="onSelectLanguage"/>
</td>
<td class="text-muted">{{ $t('profile.language') }}</td>
<td colspan="2" class="text-right"><Dropdown small tool outline v-model="language" :options="languages" option-label="display" option-key="id" @select="onSelectLanguage"/></td>
</tr>
<tr v-show="!user.source">
<td colspan="3" class="text-right"><Button small tool outline @click="onPasswordReset()">{{ $t('profile.passwordResetAction') }}</Button></td>
</tr>
</tbody>
</table>
@@ -146,6 +137,32 @@ async function onChangeEmail(currentEmail) {
user.value = await profileModel.get();
}
async function onChangeFallbackEmail(currentFallbackEmail) {
const result = await inputDialog.value.prompt({
message: [ t('profile.changeFallbackEmail.title'), t('profile.changeEmail.password') ],
type: [ 'email', 'password' ],
modal: false,
value: [ currentFallbackEmail, '' ],
confirmStyle: 'success',
confirmLabel: t('main.dialog.save'),
rejectLabel: t('main.dialog.cancel')
});
if (!result || !result[1] || currentFallbackEmail === result[0]) return;
const error = await profileModel.setFallbackEmail(result[0], result[1]);
if (error) return console.error('Failed to set fallback email', error);
user.value = await profileModel.get();
}
async function onPasswordReset() {
const error = await profileModel.sendPasswordReset(user.value.email);
if (error) return console.error('Failed to reset password:', error);
window.pankow.notify({ type: 'success', timeout: 5000, text: t('profile.passwordResetNotification.title') + '. ' + t('profile.passwordResetNotification.body', { email: user.value.fallbackEmail || user.value.email }) });
}
</script>
<style scoped>