-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Ajouter un nouveau composant formulaire de demande de réini…
- Loading branch information
Showing
19 changed files
with
608 additions
and
87 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
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 |
---|---|---|
|
@@ -13,44 +13,85 @@ describe('Acceptance | Identity Access Management | Application | Route | passwo | |
describe('POST /api/password-reset-demands', function () { | ||
let options; | ||
|
||
beforeEach(async function () { | ||
options = { | ||
method: 'POST', | ||
url: '/api/password-reset-demands', | ||
payload: { | ||
data: { | ||
attributes: { email }, | ||
}, | ||
}, | ||
}; | ||
context('with simple payload', function () { | ||
beforeEach(async function () { | ||
options = { | ||
method: 'POST', | ||
url: '/api/password-reset-demands', | ||
payload: { email }, | ||
}; | ||
|
||
config.mailing.enabled = false; | ||
config.mailing.enabled = false; | ||
|
||
const userId = databaseBuilder.factory.buildUser({ email }).id; | ||
databaseBuilder.factory.buildAuthenticationMethod.withPixAsIdentityProviderAndHashedPassword({ userId }); | ||
await databaseBuilder.commit(); | ||
}); | ||
const userId = databaseBuilder.factory.buildUser({ email }).id; | ||
databaseBuilder.factory.buildAuthenticationMethod.withPixAsIdentityProviderAndHashedPassword({ userId }); | ||
await databaseBuilder.commit(); | ||
}); | ||
|
||
context('when given email doesn’t exist', function () { | ||
it('replies with 404', async function () { | ||
// given | ||
options.payload.email = '[email protected]'; | ||
|
||
context('when email provided is unknown', function () { | ||
it('replies with 404', async function () { | ||
// given | ||
options.payload.data.attributes.email = '[email protected]'; | ||
// when | ||
const response = await server.inject(options); | ||
|
||
// then | ||
expect(response.statusCode).to.equal(404); | ||
}); | ||
}); | ||
|
||
// when | ||
const response = await server.inject(options); | ||
context('when given email exists', function () { | ||
it('replies with 201', async function () { | ||
// when | ||
const response = await server.inject(options); | ||
|
||
// then | ||
expect(response.statusCode).to.equal(404); | ||
// then | ||
expect(response.statusCode).to.equal(201); | ||
}); | ||
}); | ||
}); | ||
|
||
context('when existing email is provided', function () { | ||
it('replies with 201', async function () { | ||
// when | ||
const response = await server.inject(options); | ||
context('with deprecated ember-data-centric payload', function () { | ||
beforeEach(async function () { | ||
options = { | ||
method: 'POST', | ||
url: '/api/password-reset-demands', | ||
payload: { | ||
data: { | ||
attributes: { email }, | ||
}, | ||
}, | ||
}; | ||
|
||
config.mailing.enabled = false; | ||
|
||
const userId = databaseBuilder.factory.buildUser({ email }).id; | ||
databaseBuilder.factory.buildAuthenticationMethod.withPixAsIdentityProviderAndHashedPassword({ userId }); | ||
await databaseBuilder.commit(); | ||
}); | ||
|
||
context('when given email doesn’t exist', function () { | ||
it('replies with 404', async function () { | ||
// given | ||
options.payload.data.attributes.email = '[email protected]'; | ||
|
||
// when | ||
const response = await server.inject(options); | ||
|
||
// then | ||
expect(response.statusCode).to.equal(404); | ||
}); | ||
}); | ||
|
||
context('when given email exists', function () { | ||
it('replies with 201', async function () { | ||
// when | ||
const response = await server.inject(options); | ||
|
||
// then | ||
expect(response.statusCode).to.equal(201); | ||
// then | ||
expect(response.statusCode).to.equal(201); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
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
122 changes: 122 additions & 0 deletions
122
mon-pix/app/components/authentication/password-reset-demand-form.gjs
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,122 @@ | ||
import PixButton from '@1024pix/pix-ui/components/pix-button'; | ||
import PixButtonLink from '@1024pix/pix-ui/components/pix-button-link'; | ||
import PixInput from '@1024pix/pix-ui/components/pix-input'; | ||
import PixMessage from '@1024pix/pix-ui/components/pix-message'; | ||
import { on } from '@ember/modifier'; | ||
import { action } from '@ember/object'; | ||
import { service } from '@ember/service'; | ||
import Component from '@glimmer/component'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import { t } from 'ember-intl'; | ||
import ENV from 'mon-pix/config/environment'; | ||
|
||
import isEmailValid from '../../utils/email-validator.js'; | ||
|
||
export default class PasswordResetDemandForm extends Component { | ||
@service intl; | ||
|
||
@tracked isLoading = false; | ||
@tracked errorMessage; | ||
@tracked emailInputPlaceholder = this.intl.t( | ||
'components.authentication.password-reset-demand-form.fields.email.placeholder', | ||
); | ||
@tracked emailInputvalidationStatus; | ||
@tracked emailInputvalidationErrorMessage; | ||
|
||
email; | ||
|
||
@action | ||
handleEmailChange(event) { | ||
this.email = event.target.value; | ||
this.emailInputvalidationStatus = isEmailValid(this.email) ? 'success' : 'error'; | ||
this.emailInputvalidationErrorMessage = this.intl.t( | ||
'components.authentication.password-reset-demand-form.fields.email.error-message-invalid', | ||
); | ||
} | ||
|
||
@action | ||
async handlePasswordResetDemand(event) { | ||
if (event) event.preventDefault(); | ||
|
||
this.errorMessage = null; | ||
|
||
const email = this.email.trim(); | ||
if (!email || this.emailInputvalidationStatus === 'error') { | ||
return; | ||
} | ||
|
||
try { | ||
this.isLoading = true; | ||
const response = await window.fetch(`${ENV.APP.API_HOST}/api/password-reset-demands`, { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Accept: 'application/json', | ||
}, | ||
method: 'POST', | ||
body: JSON.stringify({ email }), | ||
}); | ||
if (response.status == 404) { | ||
this.errorMessage = this.intl.t('components.authentication.password-reset-demand-form.404-message'); | ||
} else if (!response.ok) { | ||
throw new Error(`Response status: ${response.status}`); | ||
} | ||
} catch (error) { | ||
this.errorMessage = this.intl.t('common.api-error-messages.internal-server-error'); | ||
} finally { | ||
this.isLoading = false; | ||
} | ||
} | ||
|
||
<template> | ||
<form {{on "submit" this.handlePasswordResetDemand}} class="authentication-password-reset-demand-form"> | ||
<p class="authentication-password-reset-demand-form__rule"> | ||
{{t "components.authentication.password-reset-demand-form.rule"}} | ||
</p> | ||
|
||
{{#if this.errorMessage}} | ||
<PixMessage | ||
@type="error" | ||
@withIcon={{true}} | ||
class="authentication-password-reset-demand-form__error" | ||
role="alert" | ||
> | ||
{{this.errorMessage}} | ||
</PixMessage> | ||
{{/if}} | ||
<div class="authentication-password-reset-demand-form__input-block"> | ||
<PixInput | ||
@value={{this.email}} | ||
type="email" | ||
{{on "change" this.handleEmailChange}} | ||
@validationStatus={{this.emailInputvalidationStatus}} | ||
@errorMessage={{this.emailInputvalidationErrorMessage}} | ||
placeholder={{this.emailInputPlaceholder}} | ||
required={{true}} | ||
> | ||
<:label>{{t "components.authentication.password-reset-demand-form.fields.email.label"}}</:label> | ||
</PixInput> | ||
</div> | ||
<div> | ||
<PixButton | ||
@type="submit" | ||
@size="large" | ||
@isLoading={{this.isLoading}} | ||
class="authentication-password-reset-demand-form__button" | ||
> | ||
{{t "components.authentication.password-reset-demand-form.actions.receive-reset-button"}} | ||
</PixButton> | ||
</div> | ||
<p class="authentication-password-reset-demand-form__help"> | ||
{{t "components.authentication.password-reset-demand-form.no-email-question"}} | ||
<PixButtonLink | ||
@variant="tertiary" | ||
@href="{{t 'components.authentication.password-reset-demand-form.contact-us-link.link-url'}}" | ||
target="_blank" | ||
class="authentication-password-reset-demand-form__help-contact-us-link" | ||
> | ||
{{t "components.authentication.password-reset-demand-form.contact-us-link.link-text"}} | ||
</PixButtonLink> | ||
</p> | ||
</form> | ||
</template> | ||
} |
41 changes: 41 additions & 0 deletions
41
mon-pix/app/components/authentication/password-reset-demand.scss
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,41 @@ | ||
.authentication-password-reset-demand-form { | ||
input { | ||
padding: var(--pix-spacing-3x); | ||
} | ||
|
||
&__rule { | ||
@extend %pix-body-xs; | ||
|
||
color: var(--pix-neutral-500); | ||
} | ||
|
||
&__error { | ||
margin-top: var(--pix-spacing-4x); | ||
} | ||
|
||
&__input-block { | ||
margin-top: var(--pix-spacing-4x); | ||
|
||
.pix-input { | ||
width: 100%; | ||
} | ||
} | ||
|
||
&__button { | ||
width: 100%; | ||
margin-top: var(--pix-spacing-4x); | ||
} | ||
|
||
&__help { | ||
@extend %pix-body-s; | ||
|
||
margin-top: var(--pix-spacing-4x); | ||
color: var(--pix-neutral-70); | ||
text-align: center; | ||
} | ||
|
||
&__help-contact-us-link { | ||
display: inline; | ||
padding: 0; | ||
} | ||
} |
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,10 @@ | ||
import Controller from '@ember/controller'; | ||
import { service } from '@ember/service'; | ||
|
||
export default class LoginController extends Controller { | ||
@service featureToggles; | ||
|
||
get isNewAuthenticationDesignEnabled() { | ||
return this.featureToggles.featureToggles.isNewAuthenticationDesignEnabled; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,21 @@ | ||
{{page-title (t "pages.password-reset-demand.page-title")}} | ||
<div class="sign-form-page"> | ||
<PasswordResetDemandForm /> | ||
</div> | ||
{{page-title (t "pages.password-reset-demand.title")}} | ||
|
||
{{#if this.isNewAuthenticationDesignEnabled}} | ||
<AuthenticationLayout class="signin-page-layout"> | ||
<:header> | ||
<PixButtonLink @variant="secondary" @route="authentication.login"> | ||
{{t "common.actions.login"}} | ||
</PixButtonLink> | ||
</:header> | ||
|
||
<:content> | ||
<h1 class="pix-title-m">{{t "pages.password-reset-demand.title"}}</h1> | ||
<Authentication::PasswordResetDemandForm /> | ||
</:content> | ||
</AuthenticationLayout> | ||
|
||
{{else}} | ||
<div class="sign-form-page"> | ||
<PasswordResetDemandForm /> | ||
</div> | ||
{{/if}} |
Oops, something went wrong.