Skip to content

Commit

Permalink
Update store.js
Browse files Browse the repository at this point in the history
  • Loading branch information
hacksparrow committed Feb 28, 2013
1 parent f3c50a9 commit 6f38b87
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions routes/store.js
@@ -1,21 +1,3 @@
// handler for homepage
exports.home = function(req, res) {
// if user is not logged in, ask them to login
if (typeof req.session.username == 'undefined') res.render('home', { title: 'Ninja Store'});
// if user is logged in already, take them straight to the items list
else res.redirect('/items');
};

// handler for form submitted from homepage
exports.home_post_handler = function(req, res) {
// if the username is not submitted, give it a default of "Anonymous"
username = req.body.username || 'Anonymous';
// store the username as a session variable
req.session.username = username;
// redirect the user to homepage
res.redirect('/');
};

// our 'database'
var items = {
SKN:{name:'Shuriken', price:100},
Expand All @@ -25,6 +7,24 @@ var items = {
KTN:{name:'Katana', price:1000}
};

// handler for homepage
exports.home = function(req, res) {
// if user is not logged in, ask them to login
if (typeof req.session.username == 'undefined') res.render('home', { title: 'Ninja Store'});
// if user is logged in already, take them straight to the items list
else res.redirect('/items');
};

// handler for form submitted from homepage
exports.home_post_handler = function(req, res) {
// if the username is not submitted, give it a default of "Anonymous"
username = req.body.username || 'Anonymous';
// store the username as a session variable
req.session.username = username;
// redirect the user to homepage
res.redirect('/');
};

// handler for displaying the items
exports.items = function(req, res) {
// don't let nameless people view the items, redirect them back to the homepage
Expand All @@ -42,7 +42,7 @@ exports.item = function(req, res) {
res.render('item', { title: 'Ninja Store - ' + name, username: req.session.username, name:name, price:price });
}
};


// handler for showing simple pages
exports.page = function(req, res) {
var name = req.query.name;
Expand All @@ -51,4 +51,4 @@ exports.page = function(req, res) {
contact: 'You can contact us at <address><strong>Ninja Store</strong>,<br>1, World Ninja Headquarters,<br>Ninja Avenue,<br>NIN80B7-JP,<br>Nihongo.</address>'
};
res.render('page', { title: 'Ninja Store - ' + name, username: req.session.username, content:contents[name] });
};
};

0 comments on commit 6f38b87

Please sign in to comment.