diff --git a/src/Password.js b/src/Password.js index ef0a7f376655e27468a3d4122a84e72a42dddf0e..add8a73f1945f1ceed39d23a90498241ae850614 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