From c3a75c95d259131dd815a77910fde1d382817350 Mon Sep 17 00:00:00 2001 From: Quique <917-quique@users.noreply.0xacab.org> Date: Fri, 16 Oct 2020 19:10:07 +0200 Subject: [PATCH] Ask for the old password in order to change it --- src/Password.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Password.js b/src/Password.js index ef0a7f3..add8a73 100644 --- a/src/Password.js +++ b/src/Password.js @@ -8,6 +8,7 @@ class OwnPassword extends React.Component { constructor(props) { super(props); this.state = { + oldPassword: "", newPassword: "", newPassword2: "", formErrors: "", @@ -34,6 +35,8 @@ class OwnPassword extends React.Component { this.setState( { + error: null, + passwordChanged: null, formErrors: formErrors, isNewPasswordValid: isNewPasswordValid, isNewPassword2Valid: isNewPassword2Valid, @@ -55,6 +58,7 @@ class OwnPassword extends React.Component { this.setState({ isLoading: true, error: null }); const body = JSON.stringify({ + old_password: this.state.oldPassword, password: this.state.newPassword, }); fetch("/api/member/me", { @@ -92,7 +96,7 @@ class OwnPassword extends React.Component { if (this.state.error) { alert = ( <Alert variant="danger"> - Se produjo un error al intentar cambiar la contraseña:{" "} + Se produjo un error al intentar cambiar la contraseña: {this.state.error} </Alert> ); @@ -102,7 +106,6 @@ class OwnPassword extends React.Component { alert = ( <Alert variant="success">La contraseña se ha cambiado con éxito.</Alert> ); - this.state.passwordChanged = false; } return ( @@ -112,6 +115,21 @@ class OwnPassword extends React.Component { {alert} <Form onSubmit={this.handleSubmit}> + <Form.Group as={Row}> + <Form.Label as="legend" column sm={4}> + Contraseña actual + </Form.Label> + <Col sm={8}> + <Form.Control + placeholder="Contraseña actual" + type="password" + onChange={(e) => + this.setState({ oldPassword: e.target.value }) + } + /> + </Col> + </Form.Group> + <Form.Group as={Row}> <Form.Label as="legend" column sm={4}> Nueva contraseña -- GitLab