Added signing into different users

This commit is contained in:
Chris Blanchard 2015-07-22 16:35:40 +01:00
parent 58a87b3a3d
commit fb2ca2a4f3
4 changed files with 61 additions and 22 deletions

View file

@ -4,12 +4,14 @@ var fs = require("fs");
var path = require("path"); var path = require("path");
var enslClient = require(path.join(__dirname, "../lib/ensl/client"))(); var enslClient = require(path.join(__dirname, "../lib/ensl/client"))();
var chatController = require(path.join(__dirname, "../lib/chat/controller")); var chatController = require(path.join(__dirname, "../lib/chat/controller"));
var winston = require("winston");
module.exports = function (io) { module.exports = function (io) {
var root = io.of("/"); var root = io.of("/");
var authorised = io.of("/authorised"); var authorised = io.of("/authorised");
var id = 2131; var id = 2131;
// Authorisation // Authorisation
@ -17,9 +19,11 @@ module.exports = function (io) {
enslClient.getUserById({ enslClient.getUserById({
id: id id: id
}, function (error, response, body) { }, function (error, response, body) {
if (error) return next(error); if (error) {
winston.error(error);
return next(error)
};
socket._user = body; socket._user = body;
socket._user.avatar = enslClient.getFullAvatarUri(socket._user.avatar);
next(); next();
}); });
}); });
@ -43,6 +47,20 @@ module.exports = function (io) {
socket.on('refreshGathers', refreshGatherers.bind(null, socket)); socket.on('refreshGathers', refreshGatherers.bind(null, socket));
socket.on("authorize:id", function (data) {
var id = parseInt(data.id, 10);
if (isNaN(id)) return;
enslClient.getUserById({
id: id
}, function (error, response, body) {
if (error) {
return winston.error(error);
}
socket._user = body;
refreshGatherers();
});
});
socket.on('disconnect', function (socket) { socket.on('disconnect', function (socket) {
refreshGatherers(); refreshGatherers();
}); });

View file

@ -16,8 +16,19 @@ var GatherCounter = React.createClass({
}); });
var UserLogin = React.createClass({ var UserLogin = React.createClass({
handleSubmit: function () { authorizeId: function (id) {
id = parseInt(id, 10);
socket.emit("authorize:id", {
id: id
});
},
handleSubmit: function (e) {
e.preventDefault();
var id = React.findDOMNode(this.refs.authorize_id).value.trim();
if (!id) return;
React.findDOMNode(this.refs.authorize_id).value = '';
this.authorizeId(id);
return;
}, },
render: function () { render: function () {
return ( return (
@ -27,6 +38,7 @@ var UserLogin = React.createClass({
id="btn-input" id="btn-input"
type="text" type="text"
className="form-control" className="form-control"
ref="authorize_id"
placeholder="Choose an ID..." /> placeholder="Choose an ID..." />
<span className="input-group-btn"> <span className="input-group-btn">
<input <input
@ -152,6 +164,10 @@ var ChatMessage = React.createClass({
timeAgo: $.timeago(this.props.createdAt) timeAgo: $.timeago(this.props.createdAt)
} }
}, },
imageUrl: function () {
var BASE_URL = "http://www.ensl.org/"
return BASE_URL + this.props.avatar;
},
refreshTime: function () { refreshTime: function () {
var self = this; var self = this;
self.setState({ self.setState({
@ -163,9 +179,10 @@ var ChatMessage = React.createClass({
<li className="left clearfix"> <li className="left clearfix">
<span className="chat-img pull-left"> <span className="chat-img pull-left">
<img <img
src={this.props.avatar} src={this.imageUrl()}
alt="User Avatar" alt="User Avatar"
height="40" height="40"
width="40"
className="img-circle" /> className="img-circle" />
</span> </span>
<div className="chat-body clearfix"> <div className="chat-body clearfix">

File diff suppressed because one or more lines are too long

View file

@ -60,19 +60,7 @@
<div class="navbar-default sidebar" role="navigation"> <div class="navbar-default sidebar" role="navigation">
<div class="sidebar-nav navbar-collapse"> <div class="sidebar-nav navbar-collapse">
<ul class="nav" id="side-menu"> <ul class="nav" id="side-menu"></ul>
<li class="">
<a href="#"><i class="fa fa-users-o fa-fw"></i> You</a>
</li>
<li class="">
<a href="#"><i class="fa fa-users-o fa-fw"></i> Gatherer #1</a>
</li>
<li class="">
<a href="#"><i class="fa fa-users-o fa-fw"></i> Gatherer #2</a>
</li>
</ul>
</div> </div>
</div> </div>
</nav> </nav>