Skip to content

Commit

Permalink
index page and some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyksv committed Sep 9, 2011
1 parent 177a73a commit 61f782e
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 16 deletions.
24 changes: 21 additions & 3 deletions modules/core/lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ var SkilapError = require("./SkilapError");
function Skilap() {
var sessions = {};
var _adb = null;
var tmodules = [{name:"core",require:"./coreapi"},{name:"cash",require:"skilap-cash"}];
var tmodules = [{
name:"core",require:"./coreapi",
description:"Primary system module. Provides system with common functionality and allows to administer it."
},{
name:"cash",require:"skilap-cash",
description:"Cash. Personal and familty finances. Inspired by gnucash."
}];
var self = this;
var modules = {};
var webapp = null;
Expand Down Expand Up @@ -81,7 +87,9 @@ function Skilap() {
);

app.post("/login", function (req,res,next) {
modules['core'].api.loginByPass(req.session.apiToken, req.body.name, req.body.password, function (err, user) {
async.series([
async.apply(modules['core'].api.loginByPass,req.session.apiToken, req.body.name, req.body.password)
], function (err, user) {
if (err)
res.redirect(req.body.success);
else
Expand All @@ -104,7 +112,9 @@ function Skilap() {
function end(err) {
console.timeEnd("startApp");
if (err) cb(err);
require("../pages/users")(self,webapp,modules['core'].api,"");
require("../pages/users")(self,webapp,modules['core'].api,"/core");
require("../pages/index")(self,webapp,modules['core'].api,"/core");

webapp.listen(1337);
console.log("Express server listening on port %d in %s mode", webapp.address().port, webapp.settings.env);
self.emit("WebStarted");
Expand All @@ -121,6 +131,14 @@ function Skilap() {
cb(null, modules[name]);
}

this.getModulesInfo = function (cb) {
var ret = [];
_.forEach(tmodules, function (minfo) {
ret.push({name:minfo.name, description:minfo.description, url:"/"+minfo.name+"/"});
});
cb(null, ret);
}

this.getWebApp = function (cb) {
cb(null, webapp);
}
Expand Down
9 changes: 5 additions & 4 deletions modules/core/lib/coreapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function CoreApi(ctx) {
}

this.loginByPass = function (token, login, password, cb ) {
console.log(arguments);
var won = false;
core_users.scan(function (err, key, user) {
if (err) cb1(err);
if (key) {
Expand All @@ -154,16 +154,17 @@ function CoreApi(ctx) {
s.user = user;
core_clients.put(s.clientId,{uid:s.user.id,date:new Date(),appId:s.appId}, function () {});
cb(null, user);
won = true;
}
} else {
// special case, hardcoded admin user
if (login == "admin" && password == "skilap") {
sessions[token].user = {type:"admin",screenName:"Server Owner"};
cb(null, user);
} else
cb(null, sessions[token].user);
} else if (!won)
cb(new SkilapError("Log-in failed","InvalidData"));
}
});
},true);
}
}

Expand Down
15 changes: 15 additions & 0 deletions modules/core/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var async = require("async");

module.exports = function (ctx, app, api, prefix) {

app.get("/", function(req, res, next) {
var t = [];
async.waterfall([
async.apply(ctx.getModulesInfo),
function render (modules) {
res.render(__dirname+"/../views/index", {prefix:prefix, modules: modules});
}],
next
);
});
}
10 changes: 7 additions & 3 deletions modules/core/pages/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ var async = require("async");

module.exports = function account(ctx, app, api, prefix) {

app.get("/users", function(req, res, next) {
app.get(prefix, function (req, res, next) {
res.redirect(prefix+"/users");
})

app.get(prefix+"/users", function(req, res, next) {
var t = [];
async.waterfall([
async.apply(api.getAllUsers,req.session.apiToken),
Expand All @@ -13,12 +17,12 @@ module.exports = function account(ctx, app, api, prefix) {
);
});

app.post("/users/new", function (req, res, next) {
app.post(prefix+"/users/new", function (req, res, next) {
var user = {screenName:req.body.name,login:req.body.login,password:req.body.password};
async.series([
async.apply(api.saveUser,req.session.apiToken,user),
], function (err) {
res.redirect("/users");
res.redirect(prefix+"/users");
})
});
}
8 changes: 8 additions & 0 deletions modules/core/views/index.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<center><h2>Welcome to SkiLap!<br></h2></center>
Following modules are available:
<ul>
{{#modules}}
<li><a href='{{url}}'><b>{{name}}</b></a><br>{{description}}
{{/modules}}
</ul>
<i>Please note, you might need to log-in to get access to some modules.</i>
3 changes: 0 additions & 3 deletions modules/core/views/layout.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>{{title}}</title>
<style type="text/css" title="currentStyle">
@import "{{prefix}}/stylesheets/demo_page.css";
@import "{{prefix}}/stylesheets/demo_table.css";
@import "{{prefix}}/stylesheets/style.css";
@import "{{prefix}}/stylesheets/jquery-ui.css";
</style>
{{>scripts}}
</head>
Expand Down
2 changes: 1 addition & 1 deletion node_modules/skilap-cash

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion node_modules/skilap-connect

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion node_modules/skilap-core

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 61f782e

Please sign in to comment.