#77 Fixed 500 after setting password, updated packages
parent
0f338b0d6f
commit
6758d0a7a1
|
@ -44,6 +44,9 @@ Tracman will be updated according to [this branching model](http://nvie.com/post
|
|||
|
||||
#### v0.6.1
|
||||
|
||||
* [#77](https://github.com/Tracman-org/Server/issues/77) Fixed 500 after password change, swapped `bcrypt` for `bcrypt-nodejs`
|
||||
* Removed extraneous packages
|
||||
|
||||
#### v0.6.0
|
||||
|
||||
* [#32](https://github.com/Tracman-org/Server/issues/32), [#57](https://github.com/Tracman-org/Server/issues/57), [#58](https://github.com/Tracman-org/Server/issues/58), [#60](https://github.com/Tracman-org/Server/issues/60) Added more login options
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
const mongoose = require('mongoose'),
|
||||
unique = require('mongoose-unique-validator'),
|
||||
bcrypt = require('bcrypt-nodejs'),
|
||||
bcrypt = require('bcrypt'),
|
||||
crypto = require('crypto');
|
||||
|
||||
const userSchema = new mongoose.Schema({
|
||||
|
@ -111,18 +111,31 @@ const userSchema = new mongoose.Schema({
|
|||
|
||||
};
|
||||
|
||||
// Generate hash for new password
|
||||
userSchema.methods.generateHash = function(password,next){
|
||||
// next(err,hash);
|
||||
bcrypt.genSalt(8)
|
||||
.then( (salt)=>{
|
||||
bcrypt.hash(password, salt, null, next);
|
||||
})
|
||||
.catch( (err)=>{ return next(err,null); });
|
||||
// Generate hash for new password and save it to the database
|
||||
userSchema.methods.generateHashedPassword = function(password,next){
|
||||
// next(err);
|
||||
|
||||
// Delete token
|
||||
this.auth.passToken = undefined;
|
||||
this.auth.passTokenExpires = undefined;
|
||||
|
||||
// Generate hash
|
||||
bcrypt.genSalt(8, (err,salt)=>{
|
||||
if (err){ return next(err); }
|
||||
bcrypt.hash(password, salt, (err,hash)=>{
|
||||
if (err){ return next(err); }
|
||||
this.auth.password = hash;
|
||||
this.save();
|
||||
next();
|
||||
});
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
// Check for valid password
|
||||
userSchema.methods.validPassword = function(password,next){
|
||||
// next(err,res);
|
||||
// res = true/false
|
||||
bcrypt.compare(password, this.auth.password, next);
|
||||
};
|
||||
|
||||
|
|
|
@ -301,31 +301,24 @@ router.route('/password/:token')
|
|||
|
||||
else {
|
||||
|
||||
// Delete token
|
||||
res.locals.passwordUser.auth.passToken = undefined;
|
||||
res.locals.passwordUser.auth.passTokenExpires = undefined;
|
||||
|
||||
// Create hash
|
||||
res.locals.passwordUser.generateHash( req.body.password, (err,hash)=>{
|
||||
// Create hashed password and save to db
|
||||
res.locals.passwordUser.generateHashedPassword( req.body.password, (err)=>{
|
||||
if (err){
|
||||
mw.throwErr(err,req);
|
||||
res.redirect(`/password/${req.params.token}`);
|
||||
}
|
||||
else {
|
||||
|
||||
// Save new password to db
|
||||
res.locals.passwordUser.auth.password = hash;
|
||||
res.locals.passwordUser.save()
|
||||
.then( ()=>{
|
||||
req.flash('success', 'Password set. You can use it to log in now. ');
|
||||
res.redirect('/login#login');
|
||||
})
|
||||
.catch( (err)=>{
|
||||
mw.throwErr(err,req);
|
||||
res.redirect('/login#signup');
|
||||
});
|
||||
|
||||
|
||||
// User changed password
|
||||
else if (req.user) {
|
||||
req.flash('success', 'Your password has been changed. ');
|
||||
res.redirect('/settings');
|
||||
}
|
||||
// New user created password
|
||||
else {
|
||||
req.flash('success', 'Password set. You can use it to log in now. ');
|
||||
res.redirect('/login#login');
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
}
|
||||
|
|
|
@ -4,22 +4,19 @@
|
|||
"description": "Tracks user's GPS location",
|
||||
"main": "server.js",
|
||||
"dependencies": {
|
||||
"bcrypt-nodejs": "0.0.3",
|
||||
"bcrypt": "^1.0.2",
|
||||
"body-parser": "^1.17.1",
|
||||
"connect-flash": "^0.1.1",
|
||||
"connect-flash-plus": "^0.2.1",
|
||||
"cookie-parser": "^1.4.1",
|
||||
"cookie-session": "^2.0.0-alpha.1",
|
||||
"express": "^4.15.2",
|
||||
"express-validator": "^3.1.3",
|
||||
"firebase": "^3.7.2",
|
||||
"kerberos": "0.0.17",
|
||||
"mellt": "^1.0.0",
|
||||
"moment": "^2.12.0",
|
||||
"mongodb": "^2.1.4",
|
||||
"mongodb": "^2.2.26",
|
||||
"mongoose": "^4.9.0",
|
||||
"mongoose-unique-validator": "^1.0.5",
|
||||
"node-jose": "^0.8.0",
|
||||
"nodemailer": "^3.1.8",
|
||||
"nunjucks": "^2.3.0",
|
||||
"passport": "^0.3.2",
|
||||
|
|
|
@ -143,9 +143,7 @@ const
|
|||
// Development handlers
|
||||
else {
|
||||
app.use( (err,req,res,next)=>{
|
||||
if (err.status!==404) {
|
||||
console.error(`❌ ${err.stack}`);
|
||||
}
|
||||
if (err.status!==404) { console.error(`❌ ${err.stack}`); }
|
||||
if (res.headersSent) { return next(err); }
|
||||
res.status(err.status||500);
|
||||
res.render('error', {
|
||||
|
|
Loading…
Reference in New Issue