-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
180 additions
and
5 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
webapp/src/main/java/com/box/l10n/mojito/rest/security/PasswordChangeRequest.java
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,3 @@ | ||
package com.box.l10n.mojito.rest.security; | ||
|
||
public record PasswordChangeRequest(String currentPassword, String newPassword) {} |
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
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
105 changes: 105 additions & 0 deletions
105
webapp/src/main/resources/public/js/components/header/ChangePasswordModal.js
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,105 @@ | ||
import React from "react"; | ||
import {Button, FormControl, Modal, FormGroup, ControlLabel, Alert, Collapse} from "react-bootstrap"; | ||
import {FormattedMessage, injectIntl} from "react-intl"; | ||
import UserStatics from "../../utils/UserStatics"; | ||
import UserClient from "../../sdk/UserClient"; | ||
|
||
let createClass = require('create-react-class'); | ||
|
||
let ChangePasswordModal = createClass({ | ||
|
||
getInitialState() { | ||
return { | ||
currPasswordValue: '', | ||
newPasswordValue: '', | ||
newPasswordValidationValue: '', | ||
showAlert: false, | ||
}; | ||
}, | ||
|
||
isValidPassword() { | ||
let passwordState = this.state.newPasswordValue; | ||
let passwordValidationState = this.state.newPasswordValidationValue; | ||
|
||
let isPasswordEmpty = passwordState.length <= 0 || passwordValidationState.length <= 0; | ||
let isPasswordLengthExceeded = passwordState.length > UserStatics.modalFormMaxLength() || passwordValidationState.length > UserStatics.modalFormMaxLength(); | ||
|
||
return !isPasswordEmpty && !isPasswordLengthExceeded && passwordState === passwordValidationState; | ||
}, | ||
|
||
onSaveClicked() { | ||
UserClient | ||
.updatePassword(this.state.currPasswordValue, this.state.newPasswordValue) | ||
.then(() => { | ||
this.doClose(); | ||
}) | ||
.catch(() => { | ||
this.setState({showAlert: true}); | ||
}); | ||
}, | ||
|
||
getAlert() { | ||
return ( | ||
<Collapse in={this.state.showAlert}> | ||
<div> | ||
<Alert bsStyle="danger"> | ||
<p className="text-center text-muted"><FormattedMessage id="userEditModal.alertMessage"/></p> | ||
</Alert> | ||
</div> | ||
</Collapse> | ||
); | ||
}, | ||
|
||
doClose() { | ||
this.setState(this.getInitialState()); | ||
this.props.onClose(); | ||
}, | ||
|
||
render() { | ||
return ( | ||
<Modal show={this.props.show} onHide={this.doClose}> | ||
<Modal.Header> | ||
<Modal.Title className="text-center"> | ||
<span className="mutedBold"><FormattedMessage id="header.change-pw"/></span></Modal.Title> | ||
</Modal.Header> | ||
<Modal.Body> | ||
{this.getAlert()} | ||
<FormGroup validationState={this.state.currPasswordValue ? "success" : "error"}> | ||
<ControlLabel className="mutedBold pbs"><FormattedMessage id="userEditModal.form.label.currentPassword"/></ControlLabel> | ||
<FormControl id="current password input" | ||
onChange={(e) => this.setState({currPasswordValue: e.target.value})} | ||
type="password" value={this.state.currPasswordValue} | ||
placeholder={this.props.intl.formatMessage({ id: "userEditModal.form.placeholder.currentPassword" })}/> | ||
</FormGroup> | ||
|
||
<hr /> | ||
|
||
<FormGroup validationState={this.isValidPassword() ? "success" : "error"}> | ||
<ControlLabel className="mutedBold pbs"><FormattedMessage id="userEditModal.form.label.newPassword"/></ControlLabel> | ||
<FormControl id="password input" | ||
onChange={(e) => this.setState({newPasswordValue: e.target.value})} | ||
type="password" value={this.state.newPasswordValue} | ||
placeholder={this.props.intl.formatMessage({ id: "userEditModal.form.placeholder.password" })}/> | ||
<FormControl id="password validation input" | ||
className="mtm" | ||
onChange={(e) => this.setState({newPasswordValidationValue: e.target.value})} | ||
type="password" value={this.state.newPasswordValidationValue} | ||
placeholder={this.props.intl.formatMessage({ id: "userEditModal.form.placeholder.passwordValidation" })}/> | ||
</FormGroup> | ||
</Modal.Body> | ||
<Modal.Footer> | ||
<div className="text-center"> | ||
<Button bsStyle="primary" onClick={this.onSaveClicked} disabled={!this.isValidPassword() || !this.state.currPasswordValue}> | ||
<FormattedMessage id="label.save"/> | ||
</Button> | ||
<Button onClick={this.doClose}> | ||
<FormattedMessage id="label.cancel"/> | ||
</Button> | ||
</div> | ||
</Modal.Footer> | ||
</Modal> | ||
); | ||
} | ||
}); | ||
|
||
export default injectIntl(ChangePasswordModal); |
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