-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from blank-project/dev
Release Auth #23
- Loading branch information
Showing
41 changed files
with
732 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,7 @@ public/lib | |
npm-debug.log | ||
|
||
public/css/style.css | ||
|
||
data/ | ||
data/uploads/ | ||
data/downloads/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,47 @@ | ||
var express = require('express'), | ||
router = express.Router(); | ||
router = express.Router(), | ||
auth = require('../../config/auth'); | ||
|
||
module.exports = function (app) { | ||
app.use('/', router); | ||
}; | ||
|
||
router.get('/', function (req, res, next) { | ||
res.render('index', { | ||
title : 'Contact Manager' | ||
res.render('home/index', { | ||
title : 'Contacts Manager' | ||
}); | ||
}); | ||
|
||
router.route('/login') | ||
.get(function (req, res, next) { | ||
var data = { | ||
title : 'Contacts Manager - Login' | ||
}, flash = req.flash(); | ||
console.log(flash); | ||
if (flash && flash.error) { | ||
data.message = { | ||
level : 'error', | ||
message : flash.error[0] | ||
} | ||
} | ||
res.render('home/login', data); | ||
}) | ||
.post(auth.authenticate('local', { | ||
successRedirect: '/contacts', | ||
failureRedirect: '/login', | ||
failureFlash: true | ||
})); | ||
|
||
router.get('/logout', function (req, res, next) { | ||
req.logout(); | ||
res.render('home/index', { | ||
title : 'Contacts Manager - Logout' | ||
}); | ||
}); | ||
|
||
router.route('/signup') | ||
.get(function (req, res, next) { | ||
res.render('users/userEdit', { | ||
title : 'Contacts Manager - Sign Up' | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
var express = require('express') | ||
, router = express.Router() | ||
, ensureLoggedIn = require('connect-ensure-login').ensureLoggedIn | ||
, upload = require('multer')({ dest: 'data/uploads/' }) | ||
, conf = require('../../config/config') | ||
, path = require('path') | ||
, db = conf.db | ||
, cwd = conf.root | ||
, execFile = require('child_process').execFile | ||
, scriptDir = path.join(cwd, 'scripts/') | ||
, script = path.join(scriptDir, 'contacts-import.sh'); | ||
|
||
// Exports a function to bind Controller | ||
module.exports = function (app) { | ||
app.use('/import', ensureLoggedIn('/login'), router); | ||
}; | ||
|
||
router.get('/', function (req, res, next) { | ||
res.render('import/contactImport', { title : 'Import de contact' }); | ||
}); | ||
|
||
router.post('/', upload.single('upload'), function (req, res, next) { | ||
if (!req.file) { | ||
res.render('contactImport', { title : 'Import de contact', message : 'Fichier manquant' }); | ||
return; | ||
} | ||
var filename = path.join(cwd, req.file.path) | ||
, options = { | ||
cwd : scriptDir, | ||
env : db | ||
}; | ||
execFile(script, [ filename ], options, (error, stdout, stderr) => { | ||
console.log(stdout); | ||
console.log(stderr); | ||
|
||
if (error) { | ||
next(error); | ||
return; | ||
} | ||
|
||
res.redirect("/contacts"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
var express = require('express') | ||
, co = require('co') | ||
, ensureLoggedIn = require('connect-ensure-login').ensureLoggedIn | ||
, router = express.Router() | ||
, User = require('../models/User') | ||
, Tag = require('../models/Tag'); | ||
|
||
// Exports a function to bind Controller | ||
module.exports = function (app) { | ||
app.use('/users', router); | ||
}; | ||
|
||
function userView(req, res, next, id) { | ||
console.log('Displaying user ' + id); | ||
|
||
co(function* () { | ||
var user, data = {}; | ||
|
||
user = yield User.findById(id).exec(); | ||
|
||
data.user = user; | ||
return data; | ||
}).then(data => { | ||
data.title = 'Profil ' + data.user.username; | ||
res.render('users/userView', data); | ||
}).catch(err => { next(err); }); | ||
} | ||
|
||
router.route('/') | ||
.get(function (req, res, next) { | ||
console.log(req.user); | ||
console.log(req.session.user); | ||
res.redirect('/users/me'); | ||
}) | ||
.post(function (req, res, next) { | ||
console.log('Submitting User '); | ||
var user = new User(); | ||
user.set({ | ||
username : req.body.username, | ||
name : { | ||
first : req.body.firstname, | ||
last : req.body.lastname | ||
}, | ||
email : req.body.email, | ||
phone : req.body.phone, | ||
organization : req.body.organization, | ||
title : req.body.title, | ||
meta : { | ||
// Disable self registration of user for now. | ||
disabled : new Date() | ||
} | ||
}); | ||
User.register(user, req.body.password, function(err) { | ||
var data; | ||
if (err) { | ||
console.log(err); | ||
data = req.body || {}; | ||
data.message = { | ||
level : 'error', | ||
message : err.message | ||
} | ||
res.render('users/userEdit', data); | ||
return; | ||
} | ||
|
||
console.log('user registered!'); | ||
|
||
res.redirect('/'); | ||
}); | ||
}); | ||
|
||
router.get('/me', function (req, res, next) { | ||
var data = { | ||
user : req.user, | ||
title : 'Profil ' + req.user.username | ||
}; | ||
res.render('users/userView', data); | ||
}); | ||
|
||
router.get('/:userId', ensureLoggedIn('/login'), function (req, res, next) { | ||
var id = req.params.userId; | ||
userView(req, res, next, id); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
var mongoose = require('mongoose') | ||
, Schema = mongoose.Schema | ||
, Profile; | ||
|
||
// Base Schema | ||
var schema = new Schema({ | ||
name : { type: String, required : true, trim : true }, | ||
roles : [{ type: String, trim : true }] | ||
}, { | ||
collection : 'profiles', | ||
timestamps: { | ||
createdAt : 'meta.creationDate', | ||
updatedAt : 'meta.modificationDate' | ||
} | ||
}); | ||
|
||
Profile = mongoose.model('Profile', schema); | ||
Profile.schema = schema; | ||
|
||
module.exports = Profile; |
Oops, something went wrong.