Save users in ~/.shout/

This commit is contained in:
Mattias Erming 2014-08-26 11:00:12 -07:00
parent fb6ac7168e
commit 752c4c491b
6 changed files with 26 additions and 10 deletions

View File

@ -168,6 +168,7 @@
<script src="js/libs/string.contains.js"></script>
<script src="js/libs/uri.js"></script>
<script src="js/shout.js"></script>
<script src="js/shout.templates.js"></script>
<% } else { %>
<script src="dist/build.js"></script>
<% } %>

View File

@ -1,7 +1,7 @@
{
"name": "shout",
"description": "A web IRC client",
"version": "0.11.0",
"version": "0.12.0",
"author": "Mattias Erming",
"preferGlobal": true,
"bin": {
@ -12,7 +12,7 @@
"url": "https://github.com/erming/shout.git"
},
"scripts": {
"start": "node index start"
"start": "node index"
},
"keywords": [
"browser",

View File

@ -1,6 +1,9 @@
var _ = require("lodash");
var fs = require("fs");
var Client = require("./client");
var mkdirp = require("mkdirp");
const HOME = process.env.HOME + "/.shout";
module.exports = ClientManager;
@ -37,7 +40,10 @@ ClientManager.prototype.loadUsers = function(sockets) {
ClientManager.prototype.loadUser = function(name) {
try {
var json = fs.readFileSync("users/" + name + "/user.json", "utf-8");
var json = fs.readFileSync(
HOME + "/users/" + name + "/user.json",
"utf-8"
);
json = JSON.parse(json);
} catch(e) {
console.log(e);
@ -48,8 +54,10 @@ ClientManager.prototype.loadUser = function(name) {
ClientManager.prototype.getUsers = function() {
var users = [];
var path = HOME + "/users/";
mkdirp.sync(path);
try {
users = fs.readdirSync("users/");
users = fs.readdirSync(path);
} catch(e) {
console.log(e);
return;
@ -67,7 +75,7 @@ ClientManager.prototype.addUser = function(name, password) {
return false;
}
try {
var path = "users/" + name;
var path = HOME + "/users/" + name;
var user = {
user: name,
password: password || "",
@ -91,7 +99,7 @@ ClientManager.prototype.removeUser = function(name) {
return false;
}
try {
var path = "users/" + name;
var path = HOME + "/users/" + name;
fs.unlinkSync(path + "/user.json");
fs.rmdirSync(path);
} catch(e) {

View File

@ -2,12 +2,14 @@ var ClientManager = new require("../clientManager");
var fs = require("fs");
var program = require("commander");
const HOME = process.env.HOME + "/.shout";
program
.command("add <name>")
.description("Add a new user")
.action(function(name) {
try {
var path = process.cwd() + "/users";
var path = HOME + "/users";
var test = path + "/.test";
fs.mkdirSync(test);
fs.rmdirSync(test);

View File

@ -2,6 +2,8 @@ var ClientManager = new require("../clientManager");
var program = require("commander");
var child = require("child_process");
const HOME = process.env.HOME + "/.shout";
program
.command("edit <name>")
.description("Edit an existing user")
@ -13,9 +15,10 @@ program
console.log("");
return;
}
var path = HOME + "/users/";
child.spawn(
"sudo",
["vi", process.cwd() + "/users/" + name + "/user.json"],
"vi",
[path + name + "/user.json"],
{stdio: "inherit"}
);
});

View File

@ -2,12 +2,14 @@ var ClientManager = new require("../clientManager");
var fs = require("fs");
var program = require("commander");
const HOME = process.env.HOME + "/.shout";
program
.command("remove <name>")
.description("Remove an existing user")
.action(function(name) {
try {
var path = process.cwd() + "/users";
var path = HOME + "/users";
var test = path + "/.test";
fs.mkdirSync(test);
fs.rmdirSync(test);