aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDennis Eriksen <dennis.se@gmail.com>2013-04-29 09:46:39 +0200
committerDennis Eriksen <dennis.se@gmail.com>2013-04-29 09:46:39 +0200
commitda5a55760d49961fefa649579ac0b5ed9d54b50b (patch)
treed03b7619248036fb2e74ab2408aed6a877ea326a
parentfixed small typo-bug (diff)
downloadDivid-da5a55760d49961fefa649579ac0b5ed9d54b50b.tar.gz
deleted old files
-rw-r--r--modules/account-manager.js.old196
-rw-r--r--modules/email-dispatcher.js36
-rw-r--r--modules/passport-local.js91
3 files changed, 0 insertions, 323 deletions
diff --git a/modules/account-manager.js.old b/modules/account-manager.js.old
deleted file mode 100644
index b9cb1f9..0000000
--- a/modules/account-manager.js.old
+++ /dev/null
@@ -1,196 +0,0 @@
-
-var crypto = require('crypto')
-var MongoDB = require('mongodb').Db;
-var Server = require('mongodb').Server;
-var moment = require('moment');
-
-var dbPort = 27017;
-var dbHost = 'localhost';
-var dbName = 'DERStest';
-
-/* establish the database connection */
-
-var db = new MongoDB(dbName, new Server(dbHost, dbPort, {auto_reconnect: true}), {w: 1});
- db.open(function(e, d){
- if (e) {
- console.log(e);
- } else{
- console.log('connected to database :: ' + dbName);
- }
-});
-var accounts = db.collection('accounts');
-
-/* login validation methods */
-
-exports.autoLogin = function(user, pass, callback)
-{
- accounts.findOne({user:user}, function(e, o) {
- if (o){
- o.pass == pass ? callback(o) : callback(null);
- } else{
- callback(null);
- }
- });
-}
-
-exports.manualLogin = function(user, pass, callback)
-{
- accounts.findOne({user:user}, function(e, o) {
- if (o == null){
- callback('user-not-found');
- } else{
- validatePassword(pass, o.pass, function(err, res) {
- if (res){
- callback(null, o);
- } else{
- callback('invalid-password');
- }
- });
- }
- });
-}
-
-/* record insertion, update & deletion methods */
-
-exports.addNewAccount = function(newData, callback)
-{
- accounts.findOne({user:newData.user}, function(e, o) {
- if (o){
- callback('username-taken');
- } else{
- accounts.findOne({email:newData.email}, function(e, o) {
- if (o){
- callback('email-taken');
- } else{
- saltAndHash(newData.pass, function(hash){
- newData.pass = hash;
- // append date stamp when record was created //
- newData.date = moment().format('MMMM Do YYYY, h:mm:ss a');
- accounts.insert(newData, {safe: true}, callback);
- });
- }
- });
- }
- });
-}
-
-exports.updateAccount = function(newData, callback)
-{
- accounts.findOne({user:newData.user}, function(e, o){
- o.name = newData.name;
- o.email = newData.email;
- o.country = newData.country;
- if (newData.pass == ''){
- accounts.save(o, {safe: true}, callback);
- } else{
- saltAndHash(newData.pass, function(hash){
- o.pass = hash;
- accounts.save(o, {safe: true}, callback);
- });
- }
- });
-}
-
-exports.updatePassword = function(email, newPass, callback)
-{
- accounts.findOne({email:email}, function(e, o){
- if (e){
- callback(e, null);
- } else{
- saltAndHash(newPass, function(hash){
- o.pass = hash;
- accounts.save(o, {safe: true}, callback);
- });
- }
- });
-}
-
-/* account lookup methods */
-
-exports.deleteAccount = function(id, callback)
-{
- accounts.remove({_id: getObjectId(id)}, callback);
-}
-
-exports.getAccountByEmail = function(email, callback)
-{
- accounts.findOne({email:email}, function(e, o){ callback(o); });
-}
-
-exports.validateResetLink = function(email, passHash, callback)
-{
- accounts.find({ $and: [{email:email, pass:passHash}] }, function(e, o){
- callback(o ? 'ok' : null);
- });
-}
-
-exports.getAllRecords = function(callback)
-{
- accounts.find().toArray(
- function(e, res) {
- if (e) callback(e)
- else callback(null, res)
- });
-};
-
-exports.delAllRecords = function(callback)
-{
- accounts.remove({}, callback); // reset accounts collection for testing //
-}
-
-/* private encryption & validation methods */
-
-var generateSalt = function()
-{
- var set = '0123456789abcdefghijklmnopqurstuvwxyzABCDEFGHIJKLMNOPQURSTUVWXYZ';
- var salt = '';
- for (var i = 0; i < 10; i++) {
- var p = Math.floor(Math.random() * set.length);
- salt += set[p];
- }
- return salt;
-}
-
-var md5 = function(str) {
- return crypto.createHash('md5').update(str).digest('hex');
-}
-
-var saltAndHash = function(pass, callback)
-{
- var salt = generateSalt();
- callback(salt + md5(pass + salt));
-}
-
-var validatePassword = function(plainPass, hashedPass, callback)
-{
- var salt = hashedPass.substr(0, 10);
- var validHash = salt + md5(plainPass + salt);
- callback(null, hashedPass === validHash);
-}
-
-/* auxiliary methods */
-
-var getObjectId = function(id)
-{
- return accounts.db.bson_serializer.ObjectID.createFromHexString(id)
-}
-
-var findById = function(id, callback)
-{
- accounts.findOne({_id: getObjectId(id)},
- function(e, res) {
- if (e) callback(e)
- else callback(null, res)
- });
-};
-
-
-var findByMultipleFields = function(a, callback)
-{
-// this takes an array of name/val pairs to search against {fieldName : 'value'} //
- accounts.find( { $or : a } ).toArray(
- function(e, results) {
- if (e) callback(e)
- else callback(null, results)
- });
-}
diff --git a/modules/email-dispatcher.js b/modules/email-dispatcher.js
deleted file mode 100644
index b0c40a2..0000000
--- a/modules/email-dispatcher.js
+++ /dev/null
@@ -1,36 +0,0 @@
-
-var ES = require('../config/email-settings');
-var EM = {};
-module.exports = EM;
-
-EM.server = require("emailjs/email").server.connect({
-
- host : ES.host,
- user : ES.user,
- password : ES.password,
- ssl : true
-
-});
-
-EM.dispatchResetPasswordLink = function(account, callback)
-{
- EM.server.send({
- from : ES.sender,
- to : account.email,
- subject : 'Password Reset',
- text : 'something went wrong... :(',
- attachment : EM.composeEmail(account)
- }, callback );
-}
-
-EM.composeEmail = function(o)
-{
- var link = 'https://divid.no/reset-password?e='+o.email+'&p='+o.pass;
- var html = "<html><body>";
- html += "Hi "+o.name+",<br><br>";
- html += "Your username is :: <b>"+o.user+"</b><br><br>";
- html += "<a href='"+link+"'>Please click here to reset your password</a><br><br>";
- html += "Cheers<br>";
- html += "</body></html>";
- return [{data:html, alternative:true}];
-}
diff --git a/modules/passport-local.js b/modules/passport-local.js
deleted file mode 100644
index b269707..0000000
--- a/modules/passport-local.js
+++ /dev/null
@@ -1,91 +0,0 @@
-var mongoose = require('mongoose')
- , passport = require('passport')
- , LocalStrategy = require('passport-local').Strategy
- , SALT_WORK_FACTOR = 10;
-
-
-mongoose.connect('localhost', 'test');
-
-var db = mongoose.connection;
-db.on('error', console.error.bind(console, 'connection error:'));
-db.once('open', function callback() {
- console.log('Connected to MongoDB');
-})
-
-
-// User schema
-var userSchema = mongoose.Schema({
- username: { type: String, required: true, unique: true },
- email: { type: String, required: true, unique: true },
- password: { type: String, required: true, unique: true},
-});
-
-// Bcrypt middleware
-userSchema.pre('save', function(next) {
- var user = this;
-
- if (!user.isModified('password')) return next();
-
- bcrypt.genSalt(SALT_WORK_FACTOR, function(err, salt) {
- if (err) return next(err);
-
- bcrypt.hash(user.password, salt, function(err, hash) {
- if (err) return next(err);
- user.password = hash;
- next();
- });
- });
-});
-
-// Password verification
-userSchema.methods.comparePassword = function(candidatePassword, callback) {
- bcrypt.compare(candidatePassword, this.password, function(err, isMatch) {
- if (err) return callback(err);
- callback(null, isMatch);
- });
-};
-
-
-
-
-// Passport session setup.
-// To support persistent login sessions, Passport needs to be able to
-// serialize users into and deserialize users out of the session. Typically,
-// this will be as simple as storing the user ID when serializing, and finding
-// the user by ID when deserializing.
-passport.serializeUser(function(user, done) {
- done(null, user.id);
-});
-
-passport.deserializeUser(function(id, done) {
- User.findById(id, function (err, user) {
- done(err, user);
- });
-});
-
-
-// Use the LocalStrategy within Passport.
-// Strategies in passport require a `verify` function, which accept
-// credentials (in this case, a username and password), and invoke a callback
-// with a user object. In the real world, this would query a database;
-// however, in this example we are using a baked-in set of users.
-passport.use(new LocalStrategy(function(username, password, done) {
- User.findOne({ username: username }, function(err, user) {
- if (err) return done(err);
- if (!user) { return done(null, false, { message: 'Unknown user ' + username }); }
- user.comparePassword(password, function(err, isMatch) {
- if (err) return done(err);
- if(isMatch) {
- return done(null, user);
- } else {
- return done(null, false, { message: 'Invalid password' });
- }
- });
- });
-}));
-
-
-
-
-
-