2017-01-25 18:51:41 +01:00
|
|
|
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
2016-10-25 17:54:01 +02:00
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import Paper from 'material-ui/Paper';
|
2016-12-28 18:09:45 +01:00
|
|
|
import { Tabs, Tab } from 'material-ui/Tabs';
|
|
|
|
import { observer } from 'mobx-react';
|
|
|
|
import React, { Component, PropTypes } from 'react';
|
|
|
|
import { FormattedMessage } from 'react-intl';
|
2017-01-03 17:41:21 +01:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { bindActionCreators } from 'redux';
|
2016-10-25 17:54:01 +02:00
|
|
|
|
2017-01-03 17:41:21 +01:00
|
|
|
import { newError, openSnackbar } from '~/redux/actions';
|
2017-02-22 15:26:58 +01:00
|
|
|
import { Button, IdentityName, IdentityIcon, Portal } from '~/ui';
|
2017-02-09 15:30:57 +01:00
|
|
|
import PasswordStrength from '~/ui/Form/PasswordStrength';
|
2016-12-28 18:09:45 +01:00
|
|
|
import Form, { Input } from '~/ui/Form';
|
|
|
|
import { CancelIcon, CheckIcon, SendIcon } from '~/ui/Icons';
|
2016-10-25 17:54:01 +02:00
|
|
|
|
2016-12-28 18:09:45 +01:00
|
|
|
import Store, { CHANGE_ACTION, TEST_ACTION } from './store';
|
2016-10-25 17:54:01 +02:00
|
|
|
import styles from './passwordManager.css';
|
|
|
|
|
2016-12-28 18:09:45 +01:00
|
|
|
const MSG_SUCCESS_STYLE = {
|
|
|
|
backgroundColor: 'rgba(174, 213, 129, 0.75)'
|
|
|
|
};
|
|
|
|
const MSG_FAILURE_STYLE = {
|
|
|
|
backgroundColor: 'rgba(229, 115, 115, 0.75)'
|
|
|
|
};
|
|
|
|
const TABS_INKBAR_STYLE = {
|
2017-02-22 15:26:58 +01:00
|
|
|
backgroundColor: 'rgb(0, 151, 167)' // 'rgba(255, 255, 255, 0.55)'
|
2016-12-28 18:09:45 +01:00
|
|
|
};
|
|
|
|
const TABS_ITEM_STYLE = {
|
|
|
|
backgroundColor: 'rgba(255, 255, 255, 0.05)'
|
|
|
|
};
|
|
|
|
|
|
|
|
@observer
|
2017-01-03 17:41:21 +01:00
|
|
|
class PasswordManager extends Component {
|
2016-10-25 17:54:01 +02:00
|
|
|
static contextTypes = {
|
|
|
|
api: PropTypes.object.isRequired
|
|
|
|
}
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
account: PropTypes.object.isRequired,
|
2017-01-03 17:41:21 +01:00
|
|
|
openSnackbar: PropTypes.func.isRequired,
|
|
|
|
newError: PropTypes.func.isRequired,
|
2016-10-25 17:54:01 +02:00
|
|
|
onClose: PropTypes.func
|
|
|
|
}
|
|
|
|
|
2016-12-28 18:09:45 +01:00
|
|
|
store = new Store(this.context.api, this.props.account);
|
2016-10-25 17:54:01 +02:00
|
|
|
|
|
|
|
render () {
|
|
|
|
return (
|
2017-02-22 15:26:58 +01:00
|
|
|
<Portal
|
|
|
|
buttons={ this.renderDialogActions() }
|
|
|
|
onClose={ this.onClose }
|
|
|
|
open
|
2016-12-28 18:09:45 +01:00
|
|
|
title={
|
|
|
|
<FormattedMessage
|
|
|
|
id='passwordChange.title'
|
2017-01-18 13:05:01 +01:00
|
|
|
defaultMessage='Password Manager'
|
|
|
|
/>
|
2016-12-28 18:09:45 +01:00
|
|
|
}
|
2017-01-18 13:05:01 +01:00
|
|
|
>
|
2016-10-25 17:54:01 +02:00
|
|
|
{ this.renderAccount() }
|
|
|
|
{ this.renderPage() }
|
|
|
|
{ this.renderMessage() }
|
2017-02-22 15:26:58 +01:00
|
|
|
</Portal>
|
2016-10-25 17:54:01 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderMessage () {
|
2016-12-28 18:09:45 +01:00
|
|
|
const { infoMessage } = this.store;
|
2016-10-25 17:54:01 +02:00
|
|
|
|
2016-12-28 18:09:45 +01:00
|
|
|
if (!infoMessage) {
|
|
|
|
return null;
|
2016-10-25 17:54:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Paper
|
2016-12-28 18:09:45 +01:00
|
|
|
className={ `${styles.message}` }
|
|
|
|
style={
|
|
|
|
infoMessage.success
|
|
|
|
? MSG_SUCCESS_STYLE
|
|
|
|
: MSG_FAILURE_STYLE
|
|
|
|
}
|
2017-01-18 13:05:01 +01:00
|
|
|
zDepth={ 1 }
|
|
|
|
>
|
2016-12-28 18:09:45 +01:00
|
|
|
{ infoMessage.value }
|
2016-10-25 17:54:01 +02:00
|
|
|
</Paper>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderAccount () {
|
2016-12-28 18:09:45 +01:00
|
|
|
const { address, passwordHint } = this.store;
|
2016-10-25 17:54:01 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={ styles.accountContainer }>
|
2016-12-28 18:09:45 +01:00
|
|
|
<IdentityIcon address={ address } />
|
2016-10-25 17:54:01 +02:00
|
|
|
<div className={ styles.accountInfos }>
|
|
|
|
<IdentityName
|
|
|
|
address={ address }
|
2016-12-28 18:09:45 +01:00
|
|
|
className={ styles.accountName }
|
2017-01-18 13:05:01 +01:00
|
|
|
unknown
|
|
|
|
/>
|
2016-10-25 17:54:01 +02:00
|
|
|
<span className={ styles.accountAddress }>
|
|
|
|
{ address }
|
|
|
|
</span>
|
2016-12-28 18:09:45 +01:00
|
|
|
<span className={ styles.passwordHint }>
|
|
|
|
<span className={ styles.hintLabel }>Hint </span>
|
|
|
|
{ passwordHint || '-' }
|
|
|
|
</span>
|
2016-10-25 17:54:01 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderPage () {
|
2017-01-13 15:52:42 +01:00
|
|
|
const { busy, isRepeatValid, newPassword, passwordHint } = this.store;
|
2016-10-25 17:54:01 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Tabs
|
2016-12-28 18:09:45 +01:00
|
|
|
inkBarStyle={ TABS_INKBAR_STYLE }
|
2017-01-18 13:05:01 +01:00
|
|
|
tabItemContainerStyle={ TABS_ITEM_STYLE }
|
|
|
|
>
|
2016-10-25 17:54:01 +02:00
|
|
|
<Tab
|
2016-12-28 18:09:45 +01:00
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='passwordChange.tabTest.label'
|
2017-01-18 13:05:01 +01:00
|
|
|
defaultMessage='Test Password'
|
|
|
|
/>
|
2016-12-28 18:09:45 +01:00
|
|
|
}
|
2017-01-18 13:05:01 +01:00
|
|
|
onActive={ this.onActivateTestTab }
|
|
|
|
>
|
2016-12-28 18:09:45 +01:00
|
|
|
<Form className={ styles.form }>
|
2016-10-25 17:54:01 +02:00
|
|
|
<div>
|
|
|
|
<Input
|
2016-12-28 18:09:45 +01:00
|
|
|
disabled={ busy }
|
|
|
|
hint={
|
|
|
|
<FormattedMessage
|
|
|
|
id='passwordChange.testPassword.hint'
|
2017-01-18 13:05:01 +01:00
|
|
|
defaultMessage='your account password'
|
|
|
|
/>
|
2016-12-28 18:09:45 +01:00
|
|
|
}
|
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='passwordChange.testPassword.label'
|
2017-01-18 13:05:01 +01:00
|
|
|
defaultMessage='password'
|
|
|
|
/>
|
2016-12-28 18:09:45 +01:00
|
|
|
}
|
|
|
|
onChange={ this.onEditTestPassword }
|
|
|
|
onSubmit={ this.testPassword }
|
2016-10-25 17:54:01 +02:00
|
|
|
submitOnBlur={ false }
|
2017-01-18 13:05:01 +01:00
|
|
|
type='password'
|
|
|
|
/>
|
2016-10-25 17:54:01 +02:00
|
|
|
</div>
|
|
|
|
</Form>
|
|
|
|
</Tab>
|
|
|
|
<Tab
|
2016-12-28 18:09:45 +01:00
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='passwordChange.tabChange.label'
|
2017-01-18 13:05:01 +01:00
|
|
|
defaultMessage='Change Password'
|
|
|
|
/>
|
2016-12-28 18:09:45 +01:00
|
|
|
}
|
2017-01-18 13:05:01 +01:00
|
|
|
onActive={ this.onActivateChangeTab }
|
|
|
|
>
|
2016-12-28 18:09:45 +01:00
|
|
|
<Form className={ styles.form }>
|
2016-10-25 17:54:01 +02:00
|
|
|
<div>
|
|
|
|
<Input
|
2016-12-28 18:09:45 +01:00
|
|
|
disabled={ busy }
|
|
|
|
hint={
|
|
|
|
<FormattedMessage
|
|
|
|
id='passwordChange.currentPassword.hint'
|
2017-01-18 13:05:01 +01:00
|
|
|
defaultMessage='your current password for this account'
|
|
|
|
/>
|
2016-12-28 18:09:45 +01:00
|
|
|
}
|
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='passwordChange.currentPassword.label'
|
2017-01-18 13:05:01 +01:00
|
|
|
defaultMessage='current password'
|
|
|
|
/>
|
2016-12-28 18:09:45 +01:00
|
|
|
}
|
|
|
|
onChange={ this.onEditCurrentPassword }
|
2017-01-18 13:05:01 +01:00
|
|
|
type='password'
|
|
|
|
/>
|
2016-10-25 17:54:01 +02:00
|
|
|
<Input
|
2016-12-28 18:09:45 +01:00
|
|
|
disabled={ busy }
|
|
|
|
hint={
|
|
|
|
<FormattedMessage
|
|
|
|
id='passwordChange.passwordHint.hint'
|
2017-01-18 13:05:01 +01:00
|
|
|
defaultMessage='hint for the new password'
|
|
|
|
/>
|
2016-12-28 18:09:45 +01:00
|
|
|
}
|
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='passwordChange.passwordHint.label'
|
2017-01-18 13:05:01 +01:00
|
|
|
defaultMessage='(optional) new password hint'
|
|
|
|
/>
|
2016-12-28 18:09:45 +01:00
|
|
|
}
|
|
|
|
onChange={ this.onEditNewPasswordHint }
|
2017-01-18 13:05:01 +01:00
|
|
|
value={ passwordHint }
|
|
|
|
/>
|
2016-10-29 17:39:08 +02:00
|
|
|
<div className={ styles.passwords }>
|
|
|
|
<div className={ styles.password }>
|
|
|
|
<Input
|
2016-12-28 18:09:45 +01:00
|
|
|
disabled={ busy }
|
|
|
|
hint={
|
|
|
|
<FormattedMessage
|
|
|
|
id='passwordChange.newPassword.hint'
|
2017-01-18 13:05:01 +01:00
|
|
|
defaultMessage='the new password for this account'
|
|
|
|
/>
|
2016-12-28 18:09:45 +01:00
|
|
|
}
|
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='passwordChange.newPassword.label'
|
2017-01-18 13:05:01 +01:00
|
|
|
defaultMessage='new password'
|
|
|
|
/>
|
2016-12-28 18:09:45 +01:00
|
|
|
}
|
|
|
|
onChange={ this.onEditNewPassword }
|
|
|
|
onSubmit={ this.changePassword }
|
2016-10-29 17:39:08 +02:00
|
|
|
submitOnBlur={ false }
|
2017-01-18 13:05:01 +01:00
|
|
|
type='password'
|
|
|
|
/>
|
2016-10-29 17:39:08 +02:00
|
|
|
</div>
|
|
|
|
<div className={ styles.password }>
|
|
|
|
<Input
|
2016-12-28 18:09:45 +01:00
|
|
|
disabled={ busy }
|
|
|
|
error={
|
|
|
|
isRepeatValid
|
|
|
|
? null
|
|
|
|
: <FormattedMessage
|
|
|
|
id='passwordChange.repeatPassword.error'
|
2017-01-18 13:05:01 +01:00
|
|
|
defaultMessage='the supplied passwords do not match'
|
|
|
|
/>
|
2016-12-28 18:09:45 +01:00
|
|
|
}
|
|
|
|
hint={
|
|
|
|
<FormattedMessage
|
|
|
|
id='passwordChange.repeatPassword.hint'
|
2017-01-18 13:05:01 +01:00
|
|
|
defaultMessage='repeat the new password for this account'
|
|
|
|
/>
|
2016-12-28 18:09:45 +01:00
|
|
|
}
|
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='passwordChange.repeatPassword.label'
|
2017-01-18 13:05:01 +01:00
|
|
|
defaultMessage='repeat new password'
|
|
|
|
/>
|
2016-12-28 18:09:45 +01:00
|
|
|
}
|
|
|
|
onChange={ this.onEditNewPasswordRepeat }
|
|
|
|
onSubmit={ this.changePassword }
|
2016-10-29 17:39:08 +02:00
|
|
|
submitOnBlur={ false }
|
2017-01-18 13:05:01 +01:00
|
|
|
type='password'
|
|
|
|
/>
|
2016-10-29 17:39:08 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2017-01-13 15:52:42 +01:00
|
|
|
|
|
|
|
<PasswordStrength input={ newPassword } />
|
2016-10-25 17:54:01 +02:00
|
|
|
</div>
|
|
|
|
</Form>
|
|
|
|
</Tab>
|
|
|
|
</Tabs>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderDialogActions () {
|
2016-12-28 18:09:45 +01:00
|
|
|
const { actionTab, busy, isRepeatValid } = this.store;
|
2016-10-25 17:54:01 +02:00
|
|
|
|
|
|
|
const cancelBtn = (
|
|
|
|
<Button
|
2016-12-28 18:09:45 +01:00
|
|
|
icon={ <CancelIcon /> }
|
|
|
|
key='cancel'
|
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='passwordChange.button.cancel'
|
2017-01-18 13:05:01 +01:00
|
|
|
defaultMessage='Cancel'
|
|
|
|
/>
|
2016-12-28 18:09:45 +01:00
|
|
|
}
|
2017-02-22 15:26:58 +01:00
|
|
|
onClick={ this.onClose }
|
2017-01-18 13:05:01 +01:00
|
|
|
/>
|
2016-10-25 17:54:01 +02:00
|
|
|
);
|
|
|
|
|
2016-12-28 18:09:45 +01:00
|
|
|
if (busy) {
|
|
|
|
return [
|
|
|
|
cancelBtn,
|
2016-10-25 17:54:01 +02:00
|
|
|
<Button
|
|
|
|
disabled
|
2016-12-28 18:09:45 +01:00
|
|
|
key='wait'
|
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='passwordChange.button.wait'
|
2017-01-18 13:05:01 +01:00
|
|
|
defaultMessage='Wait...'
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
2016-12-28 18:09:45 +01:00
|
|
|
];
|
2016-10-25 17:54:01 +02:00
|
|
|
}
|
|
|
|
|
2016-12-28 18:09:45 +01:00
|
|
|
if (actionTab === TEST_ACTION) {
|
|
|
|
return [
|
|
|
|
cancelBtn,
|
2016-10-25 17:54:01 +02:00
|
|
|
<Button
|
|
|
|
icon={ <CheckIcon /> }
|
2016-12-28 18:09:45 +01:00
|
|
|
key='test'
|
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='passwordChange.button.test'
|
2017-01-18 13:05:01 +01:00
|
|
|
defaultMessage='Test'
|
|
|
|
/>
|
2016-12-28 18:09:45 +01:00
|
|
|
}
|
2017-01-18 13:05:01 +01:00
|
|
|
onClick={ this.testPassword }
|
|
|
|
/>
|
2016-12-28 18:09:45 +01:00
|
|
|
];
|
2016-10-25 17:54:01 +02:00
|
|
|
}
|
|
|
|
|
2016-12-28 18:09:45 +01:00
|
|
|
return [
|
|
|
|
cancelBtn,
|
2016-10-25 17:54:01 +02:00
|
|
|
<Button
|
2016-12-28 18:09:45 +01:00
|
|
|
disabled={ !isRepeatValid }
|
2016-10-25 17:54:01 +02:00
|
|
|
icon={ <SendIcon /> }
|
2016-12-28 18:09:45 +01:00
|
|
|
key='change'
|
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='passwordChange.button.change'
|
2017-01-18 13:05:01 +01:00
|
|
|
defaultMessage='Change'
|
|
|
|
/>
|
2016-12-28 18:09:45 +01:00
|
|
|
}
|
2017-01-18 13:05:01 +01:00
|
|
|
onClick={ this.changePassword }
|
|
|
|
/>
|
2016-12-28 18:09:45 +01:00
|
|
|
];
|
2016-10-25 17:54:01 +02:00
|
|
|
}
|
|
|
|
|
2016-12-28 18:09:45 +01:00
|
|
|
onActivateChangeTab = () => {
|
|
|
|
this.store.setActionTab(CHANGE_ACTION);
|
2016-10-25 17:54:01 +02:00
|
|
|
}
|
|
|
|
|
2016-12-28 18:09:45 +01:00
|
|
|
onActivateTestTab = () => {
|
|
|
|
this.store.setActionTab(TEST_ACTION);
|
2016-10-25 17:54:01 +02:00
|
|
|
}
|
|
|
|
|
2016-12-28 18:09:45 +01:00
|
|
|
onEditCurrentPassword = (event, password) => {
|
|
|
|
this.store.setPassword(password);
|
2016-10-25 17:54:01 +02:00
|
|
|
}
|
|
|
|
|
2016-12-28 18:09:45 +01:00
|
|
|
onEditNewPassword = (event, password) => {
|
|
|
|
this.store.setNewPassword(password);
|
2016-10-25 17:54:01 +02:00
|
|
|
}
|
|
|
|
|
2016-12-28 18:09:45 +01:00
|
|
|
onEditNewPasswordHint = (event, passwordHint) => {
|
|
|
|
this.store.setNewPasswordHint(passwordHint);
|
2016-10-25 17:54:01 +02:00
|
|
|
}
|
|
|
|
|
2016-12-28 18:09:45 +01:00
|
|
|
onEditNewPasswordRepeat = (event, password) => {
|
|
|
|
this.store.setNewPasswordRepeat(password);
|
2016-10-25 17:54:01 +02:00
|
|
|
}
|
|
|
|
|
2016-12-28 18:09:45 +01:00
|
|
|
onEditTestPassword = (event, password) => {
|
|
|
|
this.store.setValidatePassword(password);
|
2016-10-25 17:54:01 +02:00
|
|
|
}
|
|
|
|
|
2017-02-22 15:26:58 +01:00
|
|
|
onClose = () => {
|
|
|
|
this.props.onClose();
|
|
|
|
}
|
|
|
|
|
2016-12-28 18:09:45 +01:00
|
|
|
changePassword = () => {
|
|
|
|
return this.store
|
|
|
|
.changePassword()
|
|
|
|
.then((result) => {
|
|
|
|
if (result) {
|
2017-01-03 17:41:21 +01:00
|
|
|
this.props.openSnackbar(
|
2016-12-28 18:09:45 +01:00
|
|
|
<div>
|
|
|
|
<FormattedMessage
|
|
|
|
id='passwordChange.success'
|
2017-01-18 13:05:01 +01:00
|
|
|
defaultMessage='Your password has been successfully changed'
|
|
|
|
/>
|
2016-12-28 18:09:45 +01:00
|
|
|
</div>
|
|
|
|
);
|
2017-02-22 15:26:58 +01:00
|
|
|
this.onClose();
|
2016-10-25 17:54:01 +02:00
|
|
|
}
|
|
|
|
})
|
2016-12-28 18:09:45 +01:00
|
|
|
.catch((error) => {
|
2017-01-03 17:41:21 +01:00
|
|
|
this.props.newError(error);
|
2016-10-25 17:54:01 +02:00
|
|
|
});
|
|
|
|
}
|
2016-11-29 00:21:54 +01:00
|
|
|
|
2016-12-28 18:09:45 +01:00
|
|
|
testPassword = () => {
|
|
|
|
return this.store
|
|
|
|
.testPassword()
|
|
|
|
.catch((error) => {
|
2017-01-03 17:41:21 +01:00
|
|
|
this.props.newError(error);
|
2016-12-28 18:09:45 +01:00
|
|
|
});
|
|
|
|
}
|
2016-11-29 00:21:54 +01:00
|
|
|
}
|
2017-01-03 17:41:21 +01:00
|
|
|
|
|
|
|
function mapDispatchToProps (dispatch) {
|
|
|
|
return bindActionCreators({
|
|
|
|
openSnackbar,
|
|
|
|
newError
|
|
|
|
}, dispatch);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
null,
|
|
|
|
mapDispatchToProps
|
|
|
|
)(PasswordManager);
|