@material-ui/icons#VpnKey JavaScript Examples
The following examples show how to use
@material-ui/icons#VpnKey.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChangePasswordDialog.js From aws-amplify-identity-broker with MIT License | 4 votes |
ChangePasswordDialog = (props) => {
const classes = useStyles();
const [oldPassword, setOldPassword] = React.useState({
password: '',
showPassword: false
});
const [newPassword, setNewPassword] = React.useState({
password: '',
showPassword: false
});
const [snackBarOps, setSnackBarOps] = React.useState({
type: 'info',
open: false,
vertical: 'top',
horizontal: 'center',
autoHide: 0,
message: ''
});
const changePassword = (oldPassword, newPassword) => {
if (!oldPassword || !newPassword) {
setSnackBarOps({
type: 'error',
open: true,
vertical: 'top',
horizontal: 'center',
autoHide: 3000,
message: I18n.get('CHANGE_PASSWORD_MESSAGE_EROR')
})
return;
}
Auth.currentAuthenticatedUser()
.then(CognitoUser => {
Auth.changePassword(CognitoUser, oldPassword, newPassword)
.then((data) => {
handleCancel(data === 'SUCCESS');
})
.catch((err) => {
console.log(err);
setSnackBarOps({
type: 'error',
open: true,
vertical: 'top',
horizontal: 'center',
autoHide: 3000,
message: I18n.get('CHANGE_PASSWORD_MESSAGE_EROR')
})
})
})
.catch(err => {
console.log(err);
setSnackBarOps({
type: 'error',
open: true,
vertical: 'top',
horizontal: 'center',
autoHide: 3000,
message: I18n.get('CHANGE_PASSWORD_MESSAGE_EROR')
})
})
};
const handleMouseDownPassword = (event) => {
event.preventDefault();
};
const handleChangeOldPassword = (value) => {
setOldPassword({ ...oldPassword, password: value })
};
const handleChangeNewPassword = (value) => {
setNewPassword({ ...newPassword, password: value })
};
const handleClickSave = () => {
changePassword(oldPassword.password, newPassword.password)
};
const handleCancel = (succesful = false) => {
setOldPassword({ ...oldPassword, password: '' });
setNewPassword({ ...newPassword, password: '' });
props.close(succesful);
};
return (
<div>
{snackBarOps.open && (
<AppSnackbar ops={snackBarOps} />
)}
<Dialog
open={props.open}
onClose={handleCancel}
disableBackdropClick
aria-labelledby="change-password-dialog"
>
<DialogTitle id="change-password-dialog-title">
{I18n.get('CHANGE_PASSWORD_TITLE')}
</DialogTitle>
<DialogContent className={classes.dialogContent}>
<DialogContentText>
{I18n.get('CHANGE_PASSWORD_DESCRIPTION')}
</DialogContentText>
<Box className={classes.box}>
<FormControl>
<InputLabel htmlFor="inputOldPassword">
{I18n.get('CHANGE_PASSWORD_OLDPASSWORD_INPUT_LABEL')}
</InputLabel>
<Input
value={oldPassword.password}
type={oldPassword.showPassword ? 'text' : 'password'}
onChange={(event) => handleChangeOldPassword(event.target.value)}
id="inputOldPassword"
startAdornment={
<InputAdornment position="start">
<VpnKey className={classes.textFieldIcon} />
</InputAdornment>
}
endAdornment={
<InputAdornment position="end">
<IconButton
aria-label="toggle password visibility"
onClick={() => setOldPassword({ ...oldPassword, showPassword: !oldPassword.showPassword })}
onMouseDown={handleMouseDownPassword}
edge="end"
>
{oldPassword.showPassword ? <Visibility /> : <VisibilityOff />}
</IconButton>
</InputAdornment>
}
className={classes.input}
autoFocus
inputProps={{ style: { left: 0 } }}
/>
</FormControl>
</Box>
<Box className={classes.box}>
<FormControl>
<InputLabel htmlFor="inputNewPassword">
{I18n.get('CHANGE_PASSWORD_NEWPASSWORD_INPUT_LABEL')}
</InputLabel>
<Input
value={newPassword.password}
type={newPassword.showPassword ? 'text' : 'password'}
onChange={(event) => handleChangeNewPassword(event.target.value)}
id="inputNewPassword"
startAdornment={
<InputAdornment position="start">
<VpnKey className={classes.textFieldIcon} />
</InputAdornment>
}
endAdornment={
<InputAdornment position="end">
<IconButton
aria-label="toggle password visibility"
onClick={() => setNewPassword({ ...newPassword, showPassword: !newPassword.showPassword })}
onMouseDown={handleMouseDownPassword}
edge="end"
>
{newPassword.showPassword ? <Visibility /> : <VisibilityOff />}
</IconButton>
</InputAdornment>
}
className={classes.input}
inputProps={{ style: { left: 0 } }}
/>
</FormControl>
</Box>
</DialogContent>
<DialogActions className={classes.dialogActions}>
<Button
variant="outlined"
onClick={handleClickSave}
className={classes.buttonSave}
>
{I18n.get('CHANGE_PASSWORD_SAVE_BUTTON_LABEL')}
</Button>
<Button
variant="outlined"
onClick={handleCancel}
className={classes.buttonCancel}
>
{I18n.get('CHANGE_PASSWORD_CANCEL_BUTTON_LABEL')}
</Button>
</DialogActions>
</Dialog>
</div>
);
}