mirror of
https://github.com/ENSL/ensl_gathers.git
synced 2025-01-31 13:30:37 +00:00
Merge branch 'disconnect_user'
merge user disconnect
This commit is contained in:
commit
1f6118b633
3 changed files with 45 additions and 6 deletions
|
@ -22,8 +22,10 @@ var App = React.createClass({
|
|||
users: [],
|
||||
messages: [],
|
||||
maps: [],
|
||||
user: null,
|
||||
servers: [],
|
||||
archive: [],
|
||||
socket: null,
|
||||
soundController: null
|
||||
};
|
||||
},
|
||||
|
@ -168,7 +170,7 @@ var App = React.createClass({
|
|||
<div className="row">
|
||||
<div className="col-md-2 hidden-xs">
|
||||
<ul className="nav" id="side-menu">
|
||||
<UserMenu users={this.props.users} />
|
||||
<UserMenu users={this.props.users} user={this.props.user} />
|
||||
</ul>
|
||||
</div>
|
||||
<div className="col-md-4" id="chatroom">
|
||||
|
|
|
@ -38,9 +38,31 @@ var UserLogin = React.createClass({
|
|||
}
|
||||
});
|
||||
|
||||
var DisconnectUserButton = React.createClass({
|
||||
getDefaultProps() {
|
||||
return {
|
||||
id: null
|
||||
};
|
||||
},
|
||||
|
||||
disconnectUser() {
|
||||
socket.emit("users:disconnect", {
|
||||
id: this.props.id
|
||||
});
|
||||
},
|
||||
|
||||
render() {
|
||||
return <button
|
||||
className="btn btn-danger"
|
||||
onClick={this.disconnectUser}>
|
||||
Disconnect User</button>
|
||||
}
|
||||
});
|
||||
|
||||
var UserModal = React.createClass({
|
||||
render() {
|
||||
let user = this.props.user;
|
||||
const currentUser = this.props.currentUser;
|
||||
const user = this.props.user;
|
||||
let hiveStats;
|
||||
if (user.hive.id) {
|
||||
hiveStats = [
|
||||
|
@ -75,6 +97,10 @@ var UserModal = React.createClass({
|
|||
</tr>
|
||||
]
|
||||
}
|
||||
let adminOptions;
|
||||
if (currentUser.admin) {
|
||||
adminOptions = <DisconnectUserButton id={user.id} />;
|
||||
}
|
||||
return (
|
||||
<div className="modal fade" id={modalId(user)}>
|
||||
<div className="modal-dialog">
|
||||
|
@ -120,6 +146,7 @@ var UserModal = React.createClass({
|
|||
</table>
|
||||
</div>
|
||||
<div className="modal-footer">
|
||||
{adminOptions}
|
||||
<button type="button"
|
||||
className="btn btn-default"
|
||||
data-dismiss="modal">Close</button>
|
||||
|
@ -133,12 +160,13 @@ var UserModal = React.createClass({
|
|||
|
||||
var UserItem = React.createClass({
|
||||
render() {
|
||||
let user = this.props.user;
|
||||
const user = this.props.user;
|
||||
const currentUser = this.props.currentUser;
|
||||
return (
|
||||
<li className="list-group-item">
|
||||
<a href="#" data-toggle="modal"
|
||||
data-target={`#${modalId(user)}`}>{user.username}</a>
|
||||
<UserModal user={user} />
|
||||
<UserModal user={user} currentUser={currentUser} />
|
||||
</li>
|
||||
);
|
||||
}
|
||||
|
@ -146,10 +174,11 @@ var UserItem = React.createClass({
|
|||
|
||||
var UserMenu = React.createClass({
|
||||
render() {
|
||||
let users = this.props.users
|
||||
const users = this.props.users
|
||||
.sort((a, b) => (a.username.toLowerCase() > b.username.toLowerCase()) ? 1 : -1)
|
||||
.map(user => {
|
||||
return <UserItem user={user} key={user.id} />
|
||||
return <UserItem user={user} key={user.id}
|
||||
currentUser={this.props.user} />
|
||||
});
|
||||
return (
|
||||
<div>
|
||||
|
|
|
@ -66,6 +66,14 @@ module.exports = namespace => {
|
|||
});
|
||||
});
|
||||
|
||||
socket.on('users:disconnect', data => {
|
||||
const id = data.id;
|
||||
if (typeof id !== 'number') return;
|
||||
namespace.sockets
|
||||
.filter(socket => socket._user.id === id)
|
||||
.forEach(socket => socket.disconnect());
|
||||
});
|
||||
|
||||
socket.on("users:authorize", data => {
|
||||
if (!socket._user.isUserAdmin()) return;
|
||||
var id = parseInt(data.id, 10);
|
||||
|
|
Loading…
Reference in a new issue