From fc50b5b7f18d02ffa8056dc1edbd3bd43e973493 Mon Sep 17 00:00:00 2001 From: Dennis Eriksen Date: Mon, 29 Apr 2013 03:39:15 +0200 Subject: been cleaning a bit, moving stuff to where it belongs. signup and signin works. --- controllers/users.js | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 controllers/users.js (limited to 'controllers') diff --git a/controllers/users.js b/controllers/users.js new file mode 100644 index 0000000..af454b5 --- /dev/null +++ b/controllers/users.js @@ -0,0 +1,62 @@ + +/** + * Module dependencies + */ + +var mongoose = require('mongoose') + , User = mongoose.model('User'); + +/** + * Login + */ + +exports.login = function(req, res) { + res.render('login', { + title: 'Login' + }); + +} + + +/** + * Logout + */ + +exports.logoug = function(req, res) { + req.logout(); + res.resirect('/test'); +} + + +/** + * Signin + */ + +exports.signin = function(req, res) {} + +/** + * Create users + */ + +exports.create = function(req, res) { + var user = new User(req.body); + user.provider = 'local'; + user.save(function(err) { + if (err) return res.render('/signup', { errors: err.errors, user: user }); + req.logIn(user, function(err) { + if (err) return next(err); + return res.redirect('/dashboard'); + }); + }); +} + + +/** + * AuthCallback + * This is what happends when a user has signed in using facebook/twitter + */ + +exports.authCallback = function(req, res, next) { + res.redirect('/dashboard'); +} + -- cgit v1.2.3 From c1371f712789e97fac6351daee93a048b12db69b Mon Sep 17 00:00:00 2001 From: Dennis Eriksen Date: Mon, 29 Apr 2013 04:13:18 +0200 Subject: cleaned up router.js --- controllers/system.js | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++ controllers/users.js | 15 ++++++++----- 2 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 controllers/system.js (limited to 'controllers') diff --git a/controllers/system.js b/controllers/system.js new file mode 100644 index 0000000..e54fc1c --- /dev/null +++ b/controllers/system.js @@ -0,0 +1,62 @@ + +/** + * Module dependencies + */ + + + + + +/** + * Before the user log in + * =============================================================== +*/ + +exports.index = function(req, res) { + res.render('index', { title: 'DERS' }); + }; + + + +exports.test = function(req, res) { + res.render('test', { + title: 'test', + loggedin: false + }); + }; + + +exports.home = function(req, res) { + res.render('home', { + title: 'home', + loggedin: false + }); + }; + + + + + + + +/** + * After the user has logged in + * =============================================================== +*/ + + + +exports.dashboard = function(req, res) { + console.log('/dashboard - ' + req.user); + res.render('dashboard', { + title: 'kanin', + loggedin: true + }); + }; + + + +exports.project = function(req, res) { + res.render('project', { title: 'Harepus', loggedin: true }); +} + diff --git a/controllers/users.js b/controllers/users.js index af454b5..d465468 100644 --- a/controllers/users.js +++ b/controllers/users.js @@ -9,7 +9,6 @@ var mongoose = require('mongoose') /** * Login */ - exports.login = function(req, res) { res.render('login', { title: 'Login' @@ -21,8 +20,7 @@ exports.login = function(req, res) { /** * Logout */ - -exports.logoug = function(req, res) { +exports.logout = function(req, res) { req.logout(); res.resirect('/test'); } @@ -30,14 +28,21 @@ exports.logoug = function(req, res) { /** * Signin + * This is triggered when the user post to /login */ - exports.signin = function(req, res) {} + /** - * Create users + * Signup */ +exports.signup = function(req, res) { + res.render('signup', { title: 'Registrer deg' }); +} +/** + * Create users + */ exports.create = function(req, res) { var user = new User(req.body); user.provider = 'local'; -- cgit v1.2.3