aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDennis Eriksen <dennis.se@gmail.com>2013-03-26 11:25:57 +0100
committerDennis Eriksen <dennis.se@gmail.com>2013-03-26 11:25:57 +0100
commitb2f37bdcb03d93a80254f58694f8047d3c35b9bb (patch)
treedcb79d880376490de8074d249bb67ed471b60629
parentold commit (diff)
downloadDivid-b2f37bdcb03d93a80254f58694f8047d3c35b9bb.tar.gz
changed the way the app handles routes. now everything goes straight to
router.js, insted of being partially handled in app.js
-rw-r--r--app.js11
-rw-r--r--routes/index.js22
-rw-r--r--routes/router.js43
-rw-r--r--routes/user.js8
4 files changed, 46 insertions, 38 deletions
diff --git a/app.js b/app.js
index cf0d724..e498b14 100644
--- a/app.js
+++ b/app.js
@@ -4,8 +4,6 @@
*/
var express = require('express')
- , routes = require('./routes')
- , user = require('./routes/user')
, http = require('http')
, path = require('path');
@@ -27,6 +25,8 @@ app.configure(function(){
app.use(express.favicon()); // sets favicon
app.use(express.logger('dev'));
app.use(express.bodyParser());
+ app.use(express.cookieParser());
+ app.use(express.session({ secret: 'lsdrghoi4hgqio42nqf2uqi32f3bilu23fl23b' }));
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
@@ -41,12 +41,7 @@ app.configure('development', function(){
* Routes
*/
-app.get('/', routes.index);
-app.get('/login', routes.login);
-app.get('/users', user.list);
-
-
-
+require('./routes/router')(app);
diff --git a/routes/index.js b/routes/index.js
deleted file mode 100644
index 9e1f66e..0000000
--- a/routes/index.js
+++ /dev/null
@@ -1,22 +0,0 @@
-
-/*
- * GET home page.
- *
- * '/'
- */
-
-exports.index = function(req, res){
- // res.render(TEMPLATE, OBJECT WITH VARIABLES)
- res.render('index', { title: 'DERS' });
-};
-
-
-/*
- * GET login page
- *
- * '/login'
- */
-
-exports.login = function(req, res) {
- res.render('login', { title: 'Logg inn' });
-}
diff --git a/routes/router.js b/routes/router.js
new file mode 100644
index 0000000..11d45bb
--- /dev/null
+++ b/routes/router.js
@@ -0,0 +1,43 @@
+
+
+
+
+
+
+
+module.exports = function(app) {
+ /*
+ * GET home page.
+ *
+ * '/'
+ */
+
+ app.get('/', function(req, res){
+ // check if the user's credentials are saved in a cookie
+ if (req.cookies.user == undefined || req.cookies.pass == undefined) {
+ res.render('index', { title: 'DERS' });
+ } else { // appempt automatic login
+ AM.autoLogin(req.cookies.user, req.cookies.pass, function(o) {
+ if (o != null) {
+ req.session.user = o;
+ res.redirect('/account');
+ } else {
+ res.render('index', { title: 'DERS' });
+ }
+ });
+ }
+ });
+
+
+ /*
+ * GET login page
+ *
+ * '/login'
+ */
+
+ app.get('/login', function(req, res) {
+ res.render('login', { title: 'Logg inn' });
+ });
+
+
+}
diff --git a/routes/user.js b/routes/user.js
deleted file mode 100644
index d5b34aa..0000000
--- a/routes/user.js
+++ /dev/null
@@ -1,8 +0,0 @@
-
-/*
- * GET users listing.
- */
-
-exports.list = function(req, res){
- res.send("respond with a resource");
-}; \ No newline at end of file