1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-08 02:10:24 +00:00

weixin connect (#7184)

* weixin connect

* update
This commit is contained in:
lian
2024-12-16 10:10:40 +08:00
committed by GitHub
parent 13c9525df1
commit f6fb7ce715
9 changed files with 238 additions and 8 deletions

View File

@@ -0,0 +1,45 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Modal, ModalHeader, ModalBody, ModalFooter, Button } from 'reactstrap';
import { gettext } from '../../utils/constants';
const propTypes = {
formActionURL: PropTypes.string.isRequired,
csrfToken: PropTypes.string.isRequired,
toggle: PropTypes.func.isRequired
};
class ConfirmDisconnectWeixin extends Component {
constructor(props) {
super(props);
this.form = React.createRef();
}
disconnect = () => {
this.form.current.submit();
};
render() {
const { formActionURL, csrfToken, toggle } = this.props;
return (
<Modal centered={true} isOpen={true} toggle={toggle}>
<ModalHeader toggle={toggle}>{gettext('Disconnect')}</ModalHeader>
<ModalBody>
<p>{gettext('Are you sure you want to disconnect?')}</p>
<form ref={this.form} className="d-none" method="post" action={formActionURL}>
<input type="hidden" name="csrfmiddlewaretoken" value={csrfToken} />
</form>
</ModalBody>
<ModalFooter>
<Button color="secondary" onClick={toggle}>{gettext('Cancel')}</Button>
<Button color="primary" onClick={this.disconnect}>{gettext('Disconnect')}</Button>
</ModalFooter>
</Modal>
);
}
}
ConfirmDisconnectWeixin.propTypes = propTypes;
export default ConfirmDisconnectWeixin;

View File

@@ -0,0 +1,59 @@
import React from 'react';
import { gettext, siteRoot } from '../../utils/constants';
import ModalPortal from '../modal-portal';
import ConfirmDisconnectWeixin from '../dialog/confirm-disconnect-weixin';
const {
csrfToken,
langCode,
socialConnectedWeixin,
socialNextPage
} = window.app.pageOptions;
class SocialLoginWeixin extends React.Component {
constructor(props) {
super(props);
this.state = {
isConfirmDialogOpen: false
};
}
confirmDisconnect = () => {
this.setState({
isConfirmDialogOpen: true
});
};
toggleDialog = () => {
this.setState({
isConfirmDialogOpen: !this.state.isConfirmDialogOpen
});
};
render() {
return (
<React.Fragment>
<div className="setting-item" id="social-auth">
<h3 className="setting-item-heading">{gettext('Social Login')}</h3>
<p className="mb-2">{langCode == 'zh-cn' ? '微信' : 'Weixin'}</p>
{socialConnectedWeixin ?
<button className="btn btn-outline-primary" onClick={this.confirmDisconnect}>{gettext('Disconnect')}</button> :
<a href={`${siteRoot}weixin/oauth-connect/?next=${encodeURIComponent(socialNextPage)}`} className="btn btn-outline-primary">{gettext('Connect')}</a>
}
</div>
{this.state.isConfirmDialogOpen && (
<ModalPortal>
<ConfirmDisconnectWeixin
formActionURL={`${siteRoot}weixin/oauth-disconnect/?next=${encodeURIComponent(socialNextPage)}`}
csrfToken={csrfToken}
toggle={this.toggleDialog}
/>
</ModalPortal>
)}
</React.Fragment>
);
}
}
export default SocialLoginWeixin;