ソースを参照

Changed things for old db compatibility.

KrisVos130 8 年 前
コミット
0551431f24

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

@@ -9,6 +9,7 @@ const db = require('../db');
 const cache = require('../cache');
 const utils = require('../utils');
 const hooks = require('./hooks');
+const sha256 = require('sha256');
 
 module.exports = {
 
@@ -27,7 +28,7 @@ module.exports = {
 			// otherwise compare the requested password and the actual users password
 			(user, next) => {
 				if (!user) return next(true, { status: 'failure', message: 'User not found' });
-				bcrypt.compare(password, user.services.password.password, (err, match) => {
+				bcrypt.compare(sha256(password), user.services.password.password, (err, match) => {
 
 					if (err) return next(err);
 
@@ -104,12 +105,13 @@ module.exports = {
 
 			// hash the password
 			(salt, next) => {
-				bcrypt.hash(password, salt, next)
+				bcrypt.hash(sha256(password), salt, next)
 			},
 
 			// save the new user to the database
 			(hash, next) => {
 				db.models.user.create({
+					_id: utils.generateRandomString(12),//TODO Check if exists
 					username,
 					email: {
 						address: email,

+ 1 - 0
backend/logic/app.js

@@ -100,6 +100,7 @@ const lib = {
 											if (err) return redirectOnErr(res, err.message);
 											if (user) return redirectOnErr(res, 'An account with that email address already exists.');
 											else db.models.user.create({
+												_id: utils.generateRandomString(12),//TODO Check if exists
 												username: body.login,
 												email: {
 													address,

+ 1 - 1
backend/logic/db/schemas/playlist.js

@@ -1,5 +1,5 @@
 module.exports = {
-	name: { type: String, lowercase: true, max: 16, min: 2 },
+	_id: { type: String, lowercase: true, max: 16, min: 2 },
 	displayName: { type: String, min: 2, max: 32, required: true },
 	songs: { type: Array },
 	createdBy: { type: String, required: true },

+ 1 - 0
backend/logic/db/schemas/user.js

@@ -1,4 +1,5 @@
 module.exports = {
+	_id: { type: String, required: true, index: true, unique: true, min: 12, max: 12 },
 	username: { type: String, required: true },
 	role: { type: String, default: 'default', required: true },
 	email: {

+ 1 - 0
backend/package.json

@@ -30,6 +30,7 @@
     "passport.socketio": "^3.7.0",
     "redis": "^2.6.3",
     "request": "^2.74.0",
+    "sha256": "^0.2.0",
     "socket.io": "^1.5.0"
   }
 }