Added user login

This commit is contained in:
Mattias Erming 2014-07-18 18:31:00 -07:00
parent 5c10af457f
commit 73b995931b
8 changed files with 126 additions and 72 deletions

View file

@ -144,8 +144,10 @@ button {
color: #7c838d;
line-height: 1.6;
font-size: 12px;
padding: 25px 40px 80px;
text-align: center;
width: 140px;
position: absolute;
top: 0;
}
#sidebar .empty:before {
content: "\f085";

View file

@ -21,10 +21,9 @@
<div id="wrap">
<div id="viewport">
<aside id="sidebar">
<div class="networks">
<div class="empty">
You're not connected to any networks yet.
</div>
<div class="networks"></div>
<div class="empty">
You're not connected to any networks yet.
</div>
<footer id="footer">
<button class="sign-in" data-target="#sign-in" data-title="Sign in" data-placement="top" title="Sign in to Shout"></button>
@ -76,31 +75,31 @@
<div class="col-xs-8">
<label>
Server
<input class="input" name="host" placeholder="<%=defaults.host%>">
<input class="input" name="host" placeholder="irc.freenode.org">
</label>
</div>
<div class="col-xs-4">
<label class="port">
Port
<input class="input" name="port" placeholder="<%=defaults.port%>">
<input class="input" name="port" placeholder="6667">
</label>
</div>
<div class="col-xs-5">
<label>
Nick
<input class="input" name="nick" placeholder="<%=defaults.nick%>">
<input class="input" name="nick" placeholder="shout-user">
</label>
</div>
<div class="col-xs-7">
<label>
Real Name
<input class="input" name="realname" class="input" placeholder="<%=defaults.realname%>">
<input class="input" name="realname" class="input" placeholder="Shout User">
</label>
</div>
<div class="col-xs-12">
<label>
Channels
<input class="input" name="join" class="input" placeholder="<%=defaults.join%>">
<input class="input" name="join" class="input" placeholder="#shout-irc">
</label>
</div>
<div class="col-xs-12">

View file

@ -53,19 +53,28 @@ $(function() {
}
);
socket.on("error", function(e) {
console.log(e);
});
socket.on("auth", function(data) {
$("#footer").find(".sign-in").trigger("click");
$("#sign-in input:first").focus();
$("body").addClass("signed-out");
sidebar.find(".sign-in")
.click()
.end()
.find(".networks")
.html("")
.next()
.show();
});
socket.on("init", function(data) {
if (data.networks.length === 0) {
$("#footer").find(".connect").trigger("click");
$("#connect input:first").focus();
return;
}
sidebar.find(".networks").append(
sidebar.find(".networks").html(
render("networks", {
networks: data.networks
})
@ -79,6 +88,9 @@ $(function() {
})
);
sidebar.find(".chan").eq(0).trigger("click"); sidebar.find(".empty").hide();
$("body").removeClass("signed-out");
var id = $.cookie("target");
var target = sidebar.find("[data-target=" + id + "]").trigger("click");
if (target.length === 0) {
@ -139,7 +151,8 @@ $(function() {
sidebar.find(".chan")
.last()
.trigger("click");
connect.find(".btn")
$("#connect")
.find(".btn")
.prop("disabled", false)
.end()
.find("input")
@ -164,10 +177,13 @@ $(function() {
var id = data.network;
sidebar.find("#network-" + id)
.remove()
.end()
.find(".chan")
.end();
var chan = sidebar.find(".chan")
.eq(0)
.trigger("click");
if (chan.length === 0) {
sidebar.find(".empty").show();
}
});
socket.on("users", function(data) {
@ -359,25 +375,25 @@ $(function() {
}
});
var connect = $("#connect");
connect.on("submit", "form", function(e) {
e.preventDefault();
var form = $(this)
.find(".btn")
.attr("disabled", true)
.end();
var post = {};
var values = form.serializeArray();
$.each(values, function(i, obj) {
$("#sign-in, #connect").on("submit", "form", function(e) {
e.preventDefault()
var event = "auth";
var form = $(this);
if (form.closest(".window").attr("id") == "connect") {
event = "conn";
form.find(".btn")
.attr("disabled", true)
.end();
}
var values = {};
$.each(form.serializeArray(), function(i, obj) {
if (obj.value !== "") {
post[obj.name] = obj.value;
values[obj.name] = obj.value;
}
});
console.log(post);
socket.emit("conn", post);
socket.emit(
event, values
);
});
function complete(word) {

View file

@ -1,12 +0,0 @@
module.exports = {
port: 9000,
theme: "themes/example.css",
public: true,
defaults: {
host: "irc.freenode.net",
port: 6667,
nick: "shout-user",
realname: "Shout User",
join: "#shout-irc"
}
};

5
config.json Normal file
View file

@ -0,0 +1,5 @@
{
"port": 9000,
"theme": "themes/example.css",
"public": false
}

View file

@ -1,5 +1,5 @@
var _ = require("lodash");
var config = require("../config");
var config = require("../config.json");
var net = require("net");
var Network = require("./models/network");
var slate = require("slate-irc");
@ -25,12 +25,20 @@ var events = [
"whois"
];
function Client(sockets) {
function Client(sockets, config) {
_.merge(this, {
networks: [],
config: config,
id: id++,
name: "",
networks: [],
sockets: sockets
});
if (config) {
var client = this;
_.each(config.networks || [], function(n) {
client.connect(n);
});
}
}
Client.prototype.emit = function(event, data) {
@ -62,18 +70,18 @@ Client.prototype.find = function(id) {
Client.prototype.connect = function(args) {
var client = this;
var options = {
host: args.host || config.defaults.host,
port: args.port || config.defaults.port
var server = {
host: args.host || "irc.freenode.org",
port: args.port || 6667
};
var stream = args.tls ? tls.connect(options) : net.connect(options);
var stream = args.tls ? tls.connect(server) : net.connect(server);
stream.on("error", function(e) {
console.log(e);
});
var nick = args.nick || config.defaults.nick;
var realname = args.realname || config.defaults.realname;
var nick = args.nick || "shout-user";
var realname = args.realname || "Shout User";
var irc = slate(stream);
irc.me = nick;
@ -81,7 +89,7 @@ Client.prototype.connect = function(args) {
irc.user(nick, realname);
var network = new Network({
host: options.host,
host: server.host,
irc: irc
});
@ -91,13 +99,14 @@ Client.prototype.connect = function(args) {
});
events.forEach(function(plugin) {
require("./plugins/irc-events/" + plugin).apply(client, [
var path = "./plugins/irc-events/" + plugin;
require(path).apply(client, [
irc,
network
]);
});
var join = (args.join || config.defaults.join).replace(/\,/g, " ").split(/\s+/g);
var join = (args.join || "#shout-irc").replace(/\,/g, " ").split(/\s+/g);
irc.on("welcome", function() {
irc.join(join);
});
@ -107,7 +116,7 @@ Client.prototype.quit = function() {
this.networks.forEach(function(network) {
var irc = network.irc;
if (network.connected) {
irc.quit("");
irc.quit();
} else {
irc.stream.end();
}

View file

@ -1,6 +1,6 @@
var _ = require("lodash");
var Client = require("./client");
var config = require("../config");
var config = require("../config.json");
var fs = require("fs");
var http = require("connect");
var io = require("socket.io");
@ -41,8 +41,37 @@ module.exports = function() {
}
});
console.log("Shout started.");
console.log("Running on port" + port);
console.log("Server started");
console.log("Shout is now running on port " + port);
if (config.public) {
return;
}
fs.readdir("users/", function(err, files) {
if (err) {
console.log(err);
return;
}
_.each(files, function(file) {
fs.readFile("users/" + file + "/user.json", "utf-8", function(err, json) {
if (err) {
console.log(err);
return;
}
try {
json = JSON.parse(json);
} catch(e) {
console.log(e);
return;
}
clients.push(new Client(
sockets,
json
));
});
});
});
};
function index(req, res, next) {
@ -73,6 +102,7 @@ function init(socket, client) {
socket.on(
"conn",
function(data) {
console.log(data);
client.connect(data);
}
);
@ -94,15 +124,15 @@ function auth(data) {
});
init(socket, client);
} else {
if (false) {
// ..
}
_.each(clients, function(client) {
if (client.config.name == data.name && client.config.password == data.password) {
init(socket, client);
}
});
}
}
function input(client, data) {
var target = client.find(data.target);
var text = data.text;
if (text.charAt(0) !== "/") {
text = "/say " + text;
@ -111,17 +141,19 @@ function input(client, data) {
var args = text.split(" ");
var cmd = args.shift().replace("/", "").toLowerCase();
inputs.forEach(function(plugin) {
var target = client.find(data.target);
_.each(inputs, function(plugin) {
try {
var fn = require("./plugins/inputs/" + plugin);
var path = "./plugins/inputs/" + plugin;
var fn = require(path);
fn.apply(client, [
target.network,
target.chan,
cmd,
args
]);
} catch (err) {
// ..
} catch (e) {
console.log(path + ": " + e);
}
});
}

View file

@ -1,7 +1,10 @@
{
"user": "example",
"password": "password",
"servers": [
{}
"networks": [
{
"host": "irc.rizon.net",
"nick": "example"
}
]
}