2018-12-13 09:53:39 +00:00
|
|
|
|
import React from 'react';
|
|
|
|
|
import PropTypes from 'prop-types';
|
2018-12-21 06:25:15 +00:00
|
|
|
|
import { Button, Modal, Input, ModalBody, Form, FormGroup } from 'reactstrap';
|
2018-12-22 05:42:45 +00:00
|
|
|
|
import { gettext, siteRoot, mediaUrl } from '../../utils/constants';
|
2018-12-13 09:53:39 +00:00
|
|
|
|
import { seafileAPI } from '../../utils/seafile-api';
|
|
|
|
|
|
2018-12-22 05:42:45 +00:00
|
|
|
|
import '../../css/lib-decrypt.css';
|
|
|
|
|
|
2018-12-21 06:25:15 +00:00
|
|
|
|
const propTypes = {
|
|
|
|
|
repoID: PropTypes.string.isRequired,
|
2018-12-21 08:28:20 +00:00
|
|
|
|
onLibDecryptDialog: PropTypes.func.isRequired
|
2018-12-21 06:25:15 +00:00
|
|
|
|
};
|
|
|
|
|
|
2018-12-13 09:53:39 +00:00
|
|
|
|
|
|
|
|
|
class LibDecryptDialog extends React.Component {
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.state = {
|
|
|
|
|
password: '',
|
|
|
|
|
showError: false,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-20 05:57:53 +00:00
|
|
|
|
handleSubmit = (e) => {
|
2018-12-13 09:53:39 +00:00
|
|
|
|
let repoID = this.props.repoID;
|
|
|
|
|
let password = this.state.password;
|
|
|
|
|
seafileAPI.setRepoDecryptPassword(repoID, password).then(res => {
|
|
|
|
|
this.props.onLibDecryptDialog();
|
|
|
|
|
}).catch(res => {
|
|
|
|
|
this.setState({
|
|
|
|
|
showError: true
|
|
|
|
|
});
|
2018-12-21 06:25:15 +00:00
|
|
|
|
});
|
|
|
|
|
|
2018-12-20 05:57:53 +00:00
|
|
|
|
e.preventDefault();
|
2018-12-13 09:53:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-20 05:57:53 +00:00
|
|
|
|
handleKeyPress = (e) => {
|
|
|
|
|
if (e.key == 'Enter') {
|
|
|
|
|
this.handleSubmit(e);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-12-13 09:53:39 +00:00
|
|
|
|
handleChange = (e) => {
|
|
|
|
|
this.setState({
|
|
|
|
|
password: e.target.value,
|
|
|
|
|
showError: false
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toggle = () => {
|
2018-12-14 08:49:55 +00:00
|
|
|
|
window.location.href = siteRoot;
|
2018-12-13 09:53:39 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
return (
|
2018-12-14 08:49:55 +00:00
|
|
|
|
<Modal isOpen={true} centered={true}>
|
2018-12-13 09:53:39 +00:00
|
|
|
|
<ModalBody>
|
2018-12-21 06:25:15 +00:00
|
|
|
|
<button type="button" className="close" onClick={this.toggle}><span aria-hidden="true">×</span></button>
|
|
|
|
|
<Form className="lib-decrypt-form text-center">
|
2018-12-22 05:42:45 +00:00
|
|
|
|
<img src={`${mediaUrl}img/lock.png`} alt="" aria-hidden="true" />
|
|
|
|
|
<p className="intro">{gettext('This library is password protected')}</p>
|
2018-12-21 06:25:15 +00:00
|
|
|
|
{this.state.showError &&
|
|
|
|
|
<p className="error">{gettext('Wrong password')}</p>
|
|
|
|
|
}
|
2018-12-22 05:42:45 +00:00
|
|
|
|
<input type="password" name="password" className="form-control password-input" autoComplete="off" onKeyPress={this.handleKeyPress} placeholder={gettext('Password')} onChange={this.handleChange} />
|
2018-12-22 06:57:42 +00:00
|
|
|
|
<button type="submit" className="btn btn-primary submit" onClick={this.handleSubmit}>{gettext('Submit')}</button>
|
2018-12-21 06:25:15 +00:00
|
|
|
|
<p className="tip">{'* '}{gettext('The password will be kept in the server for only 1 hour.')}</p>
|
|
|
|
|
</Form>
|
2018-12-13 09:53:39 +00:00
|
|
|
|
</ModalBody>
|
|
|
|
|
</Modal>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-21 06:25:15 +00:00
|
|
|
|
LibDecryptDialog.propTypes = propTypes;
|
|
|
|
|
|
2018-12-13 09:53:39 +00:00
|
|
|
|
export default LibDecryptDialog;
|