1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-15 16:04:01 +00:00
seahub/frontend/src/components/dialog/lib-decrypt-dialog.js

74 lines
2.1 KiB
JavaScript
Raw Normal View History

2018-12-13 09:53:39 +00:00
import React from 'react';
import PropTypes from 'prop-types';
import { Link } from '@reach/router';
2018-12-17 03:25:14 +00:00
import { Button, Modal, Input, ModalBody, Form, FormGroup, Label } from 'reactstrap';
2018-12-13 09:53:39 +00:00
import { gettext, siteRoot } from '../../utils/constants';
import { seafileAPI } from '../../utils/seafile-api';
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-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>
<button type="button" className="close" onClick={this.toggle}><span aria-hidden="true">×</span></button>
<Form className="lib-decrypt-form text-center">
<img src={siteRoot + 'media/img/lock.png'} alt=""/>
<p>{gettext('This library is password protected')}</p>
{this.state.showError &&
<p className="error">{gettext('Wrong password')}</p>
}
2018-12-14 08:49:55 +00:00
<FormGroup>
2018-12-20 05:57:53 +00:00
<Input type="password" name="password" onKeyPress={this.handleKeyPress} placeholder={gettext('Password')} onChange={this.handleChange}/>
</FormGroup>
<FormGroup>
<Button type="submit" value="Submit" onClick={this.handleSubmit}>{gettext('Submit')}</Button>
2018-12-14 08:49:55 +00:00
</FormGroup>
2018-12-17 03:25:14 +00:00
<p className="tip">{'* '}{gettext('The password will be kept in the server for only 1 hour.')}</p>
2018-12-13 09:53:39 +00:00
</Form>
</ModalBody>
</Modal>
);
}
}
export default LibDecryptDialog;