Browse Source

Worked on fixing auth.

KrisVos130 8 years ago
parent
commit
ac97160e55

+ 1 - 0
.gitignore

@@ -7,6 +7,7 @@ Thumbs.db
 startRedis.cmd
 startMongo.cmd
 .database
+dump.rdb
 
 # Back End
 backend/node_modules/

+ 1 - 0
backend/index.js

@@ -16,6 +16,7 @@ async.waterfall([
 	(next) => {
 		cache.init(config.get('redis').url, () => {
 			// load some test stations into the cache
+			console.log(next);
 			async.waterfall([
 				(next) => cache.hset('stations', '7dbf25fd-b10d-6863-2f48-637f6014b162', cache.schemas.station({
 					name: 'edm',

+ 9 - 2
backend/logic/actions/users.js

@@ -65,7 +65,7 @@ module.exports = {
 					url: 'https://www.google.com/recaptcha/api/siteverify',
 					method: 'POST',
 					form: {
-						'secret': config.get("apis.recaptcha.secret"),
+						//'secret': config.get("apis.recaptcha.secret"),
 						'response': recaptcha
 					}
 				}, next);
@@ -74,15 +74,17 @@ module.exports = {
 			// check if the response from Google recaptcha is successful
 			// if it is, we check if a user with the requested username already exists
 			(response, body, next) => {
+				console.log(456);
 				let json = JSON.parse(body);
 				console.log(json);
-				if (json.success !== true) return next('Response from recaptcha was not successful');
+				//if (json.success !== true) return next('Response from recaptcha was not successful');
 				db.models.user.findOne({ 'username': username }, next);
 			},
 
 			// if the user already exists, respond with that
 			// otherwise check if a user with the requested email already exists
 			(user, next) => {
+				console.log(234);
 				if (user) return next(true, { status: 'failure', message: 'A user with that username already exists' });
 				db.models.user.findOne({ 'email.address': email }, next);
 			},
@@ -90,17 +92,20 @@ module.exports = {
 			// if the user already exists, respond with that
 			// otherwise, generate a salt to use with hashing the new users password
 			(user, next) => {
+				console.log(853);
 				if (user) return next(true, { status: 'failure', message: 'A user with that email already exists' });
 				bcrypt.genSalt(10, next);
 			},
 
 			// hash the password
 			(salt, next) => {
+				console.log(4682);
 				bcrypt.hash(password, salt, next)
 			},
 
 			// save the new user to the database
 			(hash, next) => {
+				console.log(6842);
 				db.models.user.create({
 					username: username,
 					email: {
@@ -117,10 +122,12 @@ module.exports = {
 
 			// respond with the new user
 			(newUser, next) => {
+				console.log(21465);
 				next(null, { status: 'success', user: newUser })
 			}
 
 		], (err, payload) => {
+			console.log(476123123);
 			// log this error somewhere
 			if (err && err !== true) {
 				console.error(err);

+ 4 - 2
backend/logic/cache/index.js

@@ -55,8 +55,10 @@ const lib = {
 		if (stringifyJson && ['object', 'array'].includes(typeof value)) value = JSON.stringify(value);
 
 		lib.client.hset(table, key, value, (err) => {
-			if (err) return cb(err);
-			cb(null);
+			if (cb !== undefined) {
+				if (err) return cb(err);
+				cb(null);
+			}
 		});
 	},
 

+ 2 - 2
backend/logic/utils.js

@@ -92,11 +92,11 @@ function convertTime (duration) {
 
 module.exports = {
 	htmlEntities: str => String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;'),
-	generateRandomString: len => {
+	generateRandomString: function(len) {
 		let chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".split("");
 		let result = [];
 		for (let i = 0; i < len; i++) {
-			result.push(chars[globals.utils.getRandomNumber(0, chars.length - 1)]);
+			result.push(chars[this.getRandomNumber(0, chars.length - 1)]);
 		}
 		return result.join("");
 	},

+ 8 - 6
frontend/App.vue

@@ -20,7 +20,7 @@
 				},
 				likes: [],
 				dislikes: [],
-				loggedIn: true,
+				loggedIn: false,
 				stations: []
 			}
 		},
@@ -31,16 +31,18 @@
 			}
 		},
 		ready: function () {
-			let socket = this.socket = io(window.location.protocol + '//' + window.location.hostname + ':8081');
-			socket.on("ready", status => this.loggedIn = status);
-			socket.emit("stations.index", data => this.stations = data);
+			lofig.folder = 'config/default.json';
+			lofig.get('socket.url', res => {
+				let socket = this.socket = io(window.location.protocol + '//' + res);
+				socket.on("ready", status => this.loggedIn = status);
+				socket.emit("stations.index", data => this.stations = data);
+			});
 		},
 		events: {
 			'register': function () {
 
 				let { register: { email, username, password } } = this;
-
-				this.socket.emit('users.login', email, username, password, grecaptcha.getResponse(), (result) => {
+				this.socket.emit('users.register', email, username, password, grecaptcha.getResponse(), (result) => {
 					console.log(result);
 					location.reload();
 				});

+ 5 - 0
frontend/build/config/default.json

@@ -0,0 +1,5 @@
+{
+  "socket": {
+	"url": "localhost"
+  }
+}

+ 1 - 0
frontend/build/index.html

@@ -14,6 +14,7 @@
 	<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.0/moment.min.js"></script>
 	<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.4.8/socket.io.min.js"></script>
 	<script src='https://www.google.com/recaptcha/api.js'></script>
+	<script src='https://cdn.rawgit.com/atjonathan/lofig/master/lofig.js'></script>
 </head>
 <body>
 	<script src="/bundle.js"></script>