-
-
Notifications
You must be signed in to change notification settings - Fork 20
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 #36 from jhipster/add-change-password
Add page to change user password
- Loading branch information
Showing
9 changed files
with
152 additions
and
34 deletions.
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
34 changes: 34 additions & 0 deletions
34
...rators/client/templates/svelte/src/main/webapp/app/components/account/Password.svelte.ejs
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,34 @@ | ||
<script> | ||
import Icon from 'fa-svelte' | ||
import { faExclamationCircle } from '@fortawesome/free-solid-svg-icons/faExclamationCircle' | ||
import InputControl from '../InputControl.svelte' | ||
export let name = 'password' | ||
export let label = 'Password' | ||
export let value = '' | ||
</script> | ||
|
||
<InputControl | ||
type="password" | ||
label="{label}" | ||
value="{value}" | ||
name="{name}" | ||
on:input | ||
required | ||
validations="{[{ type: 'required', message: 'Password is mandatory' }, { type: 'minlength', minlength: 4, message: 'Password is required to be at least 4 characters' }, { type: 'maxlength', maxlength: 50, message: 'Password cannot be longer than 50 characters' }]}" | ||
on:validate | ||
let:message | ||
let:dirty | ||
let:valid | ||
{...$$restProps} | ||
> | ||
<slot message="{message}" dirty="{dirty}" valid="{valid}"> | ||
{#if dirty && !valid} | ||
<div class="flex items-center"> | ||
<Icon class="fa-icon mr-2" icon="{faExclamationCircle}" /> | ||
{message} | ||
</div> | ||
{:else} {/if} | ||
</slot> | ||
</InputControl> |
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
63 changes: 63 additions & 0 deletions
63
generators/client/templates/svelte/src/main/webapp/app/routes/account/password.svelte.ejs
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,63 @@ | ||
<script> | ||
import accountService from './../../components/account/account-service' | ||
import Alert from './../../components/Alert.svelte' | ||
import Password from './../../components/account/Password.svelte' | ||
import PasswordConfirm from './../../components/account/PasswordConfirm.svelte' | ||
let error | ||
let currentPassword | ||
let newPassword | ||
let validCurrentPassword = false | ||
let validNewPassword = false | ||
let passwordChanged = false | ||
$: validForm = validCurrentPassword && validNewPassword | ||
function changePassword() { | ||
error = undefined | ||
passwordChanged = false | ||
accountService | ||
.changeAccountPassword(currentPassword, newPassword) | ||
.then(() => (passwordChanged = true), (currentPassword = '')) | ||
.catch(err => ((currentPassword = ''), (error = err))) | ||
} | ||
</script> | ||
|
||
<svelte:head> | ||
<title>Change password</title> | ||
</svelte:head> | ||
|
||
<section class="m-3 relative bg-white shadow-md rounded p-4"> | ||
<div class="p-4 w-full sm:max-w-3xl sm:mx-auto"> | ||
<div class="px-4 w-full text-4xl text-center">Change password</div> | ||
<Alert show="{passwordChanged}" closeable="{false}"> | ||
Password changed! | ||
</Alert> | ||
<Alert type="danger" show="{error}" closeable="{false}"> | ||
An error has occurred! The password could not be changed. | ||
</Alert> | ||
<form class="mt-4 flex flex-col"> | ||
<Password | ||
name="currentPassword" | ||
label="Current Password" | ||
value="{currentPassword}" | ||
on:input="{event => (currentPassword = event.target.value)}" | ||
on:validate="{event => (validCurrentPassword = event.detail.valid)}" | ||
/> | ||
|
||
<PasswordConfirm | ||
name="newPassword" | ||
label="New Password" | ||
value="{newPassword}" | ||
on:input="{event => (newPassword = event.detail.value)}" | ||
on:validate="{event => (validNewPassword = event.detail.valid)}" | ||
/> | ||
<button | ||
type="submit" | ||
on:click|preventDefault="{changePassword}" | ||
class="my-4 w-64 m-auto btn btn-primary" | ||
disabled="{!validForm}" | ||
>Update password</button> | ||
</form> | ||
</div> | ||
</section> |
6 changes: 3 additions & 3 deletions
6
.../routes/account/password-reset.svelte.ejs → .../app/routes/account/reset/init.svelte.ejs
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