Jax Node.js UG Message Board › Tomorrow's meeting will be on Passport

Tomorrow's meeting will be on Passport

David F.
Davidfekke
Group Organizer
Jacksonville, FL
Tomorrow's presentation will be on the Passport authentication library. Here are some details from the Passport.js website;
Passport is authentication middleware for Node.js. Extremely flexible and modular, Passport can be unobtrusively dropped in to any Express-based web application. A comprehensive set of strategies support authentication using a username and password, Facebook, Twitter, and more.

• 140+ authentication strategies
• Single sign-on with OpenID and OAuth
• Easily handle success and failureSupports persistent sessions
• Dynamic scope and permissions
• Pick and choose required strategies
• Implement custom strategies
• Does not mount routes in application
• Lightweight code base
We will be having a giveaway at the end of tomorrow's meeting.
The meeting will be at Payspan. Here is the address;
Payspan
7751 Belfort Pkwy
Jacksonville FL
A former member
Post #: 1
Some helpful controllers:

/**
* AccountController
*
* @module :: Controller
* @description :: Contains logic for handling requests.
*/

module.exports = {

index: function(req, res) {
var moment = require('moment');
Account.find().exec(function(err, rows) {
return res.view({
acccounts: rows,
pageTitle: 'Accounts',
layout: 'layout_in',
moment: moment,
timezone: (req.session.user.timezone ? req.session.user.timezone : "Europe/London"),
username: req.session.user.username,
fullname: req.session.user.fullname ? req.session.user.fullname : req.session.user.username
});
});
},
giveTrial: function(req, res) {
var id = req.param('id');
var subscr = new Date();
subscr.setMonth(subscr.getMonth() + 1);
Account.update({_id:id},{
trial: subscr,
active: 1
}).done(function(err, rows) {
if (err) console.log(err);
res.redirect('/accounts');
});
},
accountDelete: function(req, res) {
var id = req.param('id');
if (id) {
Account.destroy({_id:id}).done(function(­err,x) {
if (err) console.log(err);
res.redirect('/accounts');
});
} else {
res.redirect('/accounts');
}
},
profile: function(req, res) {
var pch = req.param('pass', false);
if (pch && pch == 'ok') {
var notice = 'Password changed';
} else {
var notice = '';
}
var username = req.session.user.username;

var fullname = req.param('fullname', false);
if (fullname != false) {
var usernameIn = req.param('username');
var phone = req.param('phone');
var paypalDetails = req.param('paypalDetails');
var timezone = req.param('timezone');
otherPaypal = req.session.user.paypalDetails;

otherPaypal["address_street"] = paypalDetails["address_street"­];
otherPaypal["address_country"]­ = paypalDetails["address_country"­];
otherPaypal["address_city"] = paypalDetails["address_city"];­
otherPaypal["address_zip"] = paypalDetails["address_zip"];

Account.update({
username: username
}, {
username: usernameIn,
fullname: fullname,
phone: phone,
timezone: timezone,
paypalDetails: otherPaypal
}).done(function(errx, usrx) {
if (errx) console.log(errx);
console.log('Updated details', usrx);
if (usrx[0]) {
req.session.user = usrx[0];
return res.view({
pageTitle: 'Profile',
layout: 'layout_in',
user: req.session.user,
profile: usrx[0],
notice: notice,
timezone: (req.session.user.timezone ? req.session.user.timezone : "Europe/London"),
username: req.session.user.username,
fullname: req.session.user.fullname ? req.session.user.fullname : req.session.user.username
});
} else {
res.redirect('/');
}
});
} else {
Account.findByUsername(username).done(fu­nction(err, usr) {
if (err) {
res.send(500, {
error: "DB Error"
});
} else {
if (usr[0]) {
return res.view({
pageTitle: 'Profile',
layout: 'layout_in',
timezone: (req.session.user.timezone ? req.session.user.timezone : "Europe/London"),
user: req.session.user,
profile: usr[0],
notice: notice,
username: req.session.user.username,
fullname: req.session.user.fullname ? req.session.user.fullname : req.session.user.username
});
} else {
res.redirect('/');
}
}
});
}
},
changePass: function(req, res) {
var password = req.param('password');
var repeat = req.param('repeat');

console.log('Trying to change pass');

if (req.session.user && password) {

var hasher = require("password-hash");
password = hasher.generate(password);

Account.update({
username: req.session.user.username
}, {
password: password
}).done(function(err, user) {
if (err) console.log(err);
console.log('pass changed..');
res.redirect('/profile?pass=ok');
});
} else {
res.redirect('/profile');
}
}
};
Powered by mvnForum

Our Sponsors

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy