1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-14 06:11:16 +00:00
Files
seahub/frontend/src/components/user-settings/webdav-password.js

90 lines
2.8 KiB
JavaScript
Raw Normal View History

2019-05-07 14:57:22 +08:00
import React from 'react';
import ModalPortal from '../modal-portal';
2019-05-07 14:57:22 +08:00
import { gettext } from '../../utils/constants';
import { seafileAPI } from '../../utils/seafile-api';
import toaster from '../toast';
import UpdateWebdavPassword from '../dialog/update-webdav-password';
2019-05-07 14:57:22 +08:00
const { webdavPasswd } = window.app.pageOptions;
class WebdavPassword extends React.Component {
constructor(props) {
super(props);
this.state = {
password: webdavPasswd,
isPasswordVisible: false,
isDialogOpen: false
2019-05-07 14:57:22 +08:00
};
}
togglePasswordVisible = () => {
this.setState({
isPasswordVisible: !this.state.isPasswordVisible
2019-05-07 14:57:22 +08:00
});
}
updatePassword = (password) => {
seafileAPI.updateWebdavSecret(password).then((res) => {
this.toggleDialog();
this.setState({
password: password
});
2019-05-07 14:57:22 +08:00
toaster.success(gettext('Success'));
}).catch((error) => {
let errorMsg = '';
if (error.response) {
if (error.response.data && error.response.data['error_msg']) {
errorMsg = error.response.data['error_msg'];
} else {
errorMsg = gettext('Error');
}
} else {
errorMsg = gettext('Please check the network.');
}
this.toggleDialog();
2019-05-07 14:57:22 +08:00
toaster.danger(errorMsg);
});
}
toggleDialog = () => {
this.setState({
isDialogOpen: !this.state.isDialogOpen
});
2019-05-07 14:57:22 +08:00
}
render() {
const { password, isPasswordVisible } = this.state;
2019-05-07 14:57:22 +08:00
return (
<React.Fragment>
<div id="update-webdav-passwd" className="setting-item">
<h3 className="setting-item-heading">{gettext('WebDav Password')}</h3>
{password ? (
<React.Fragment>
<div className="d-flex align-items-center">
<label className="m-0 mr-2">{gettext('Password:')}</label>
<input className="border-0 mr-1" type="text" value={isPasswordVisible ? password : '**********'} readOnly={true} size={Math.max(password.length, 10)} />
<span onClick={this.togglePasswordVisible} className={`eye-icon fas ${this.state.isPasswordVisible ? 'fa-eye': 'fa-eye-slash'}`}></span>
</div>
<button className="btn btn-outline-primary mt-2" onClick={this.toggleDialog}>{gettext('Update')}</button>
</React.Fragment>
) : (
<button className="btn btn-outline-primary" onClick={this.toggleDialog}>{gettext('Set Password')}</button>
)}
2019-05-07 14:57:22 +08:00
</div>
{this.state.isDialogOpen && (
<ModalPortal>
<UpdateWebdavPassword
password={this.state.password}
updatePassword={this.updatePassword}
toggle={this.toggleDialog}
/>
</ModalPortal>
)}
</React.Fragment>
2019-05-07 14:57:22 +08:00
);
}
}
export default WebdavPassword;