Commits

Harrison Shoebridge committed 34d68e2

Basics

Comments (0)

Files changed (3)

+node_modules/*
+module.exports =  function() {
+	var mongoose = require('mongoose');	
+	var DB_URL = "mongodb://localhost/users";
+	var COLLECTION = "users";
+	var schema = mongoose.Schema({
+		username: String,
+		password: String
+	});
+
+	var User = mongoose.model(COLLECTION, schema);
+	return {
+		setup: function() {
+			console.log('[ELOGIN] init.');
+
+			mongoose.connect(DB_URL);
+			var db = mongoose.connection;
+			db.on('error', console.error.bind(console, '[ELOGIN] connection error: '));
+
+			return this;
+		},
+		
+		addUser: function($username, $password, callback) {
+			User.findOne({username: $username}, function(err, user) {
+				if(!err) {
+					if(user == (void 0)) {
+						console.log('user can be added.')
+					}else {
+						console.log('user exists')
+					}
+				}else {
+					//TODO: error reporting.
+				}
+			});
+		}, 
+		
+		checkUser: function() {
+
+		},
+		
+		config: function(options) {
+			if(options.url != void(0)) {
+				DB_URL = options.url;
+			}
+
+			if(options.collection != void(0)) {
+				COLLECTION = options.collection;
+			}
+			//console.log(options);
+			console.log('[ELOGIN] SETTINGS: ' + DB_URL + ' : ' + COLLECTION);
+			this.setup();
+		}
+	}
+}().setup();
+{
+  "name": "elogin",
+  "version": "0.0.1",
+  "description": "A simple open (but secure) login system for mongoose and express",
+  "main": "main.js",
+  "scripts": {
+    "test": "echo \"Error: no test specified\" && exit 1"
+  },
+  "repository": "",
+  "author": "Harrison Shoebridge",
+  "license": "MIT",
+  "dependencies": {
+    "mongoose": "~3.8.1"
+  }
+}