0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Duplicate user, error handling, password in fixture

This commit is contained in:
Gabor Javorszky 2013-05-27 22:03:13 +01:00
parent 18166337b8
commit 29bfcd3a3f
4 changed files with 35 additions and 21 deletions

View file

@ -68,7 +68,8 @@
connection: { connection: {
filename: './core/shared/data/testdb.db' filename: './core/shared/data/testdb.db'
}, },
debug: true debug: false
// debug: true
}, },
staging: {}, staging: {},

View file

@ -64,9 +64,9 @@
console.log('user found: ', user); console.log('user found: ', user);
req.session.user = "ghostadmin"; req.session.user = "ghostadmin";
res.redirect(req.query.redirect || '/ghost/'); res.redirect(req.query.redirect || '/ghost/');
}, function (err) { }, function (error) {
// Do something here to signal the reason for an error // Do something here to signal the reason for an error
console.log(err.stack); req.flash('error', error.message);
res.redirect('/ghost/login/'); res.redirect('/ghost/login/');
}); });
}, },
@ -78,16 +78,19 @@
}); });
}, },
'doRegister': function (req, res) { 'doRegister': function (req, res) {
// console.log(req.body); var email = req.body.email_address,
if (req.body.email_address !== '' && req.body.password.length > 5) { password = req.body.password;
if (email !== '' && password.length > 5) {
api.users.add({ api.users.add({
email_address: req.body.email_address, email_address: email,
password: req.body.password password: password
}).then(function (user) { }).then(function (user) {
console.log('user added', user); console.log('user added', user);
res.redirect('/ghost/login/'); res.redirect('/ghost/login/');
}, function (error) { }, function (error) {
console.log('there was an error', error); req.flash('error', error.message);
res.redirect('/ghost/register/');
}); });
} else { } else {
req.flash('error', "The password is too short. Have at least 6 characters in there"); req.flash('error', "The password is too short. Have at least 6 characters in there");

View file

@ -54,6 +54,7 @@ module.exports = {
"username": "johnonolan", "username": "johnonolan",
"first_name": "John", "first_name": "John",
"last_name": "O'Nolan", "last_name": "O'Nolan",
"password": "$2a$10$.pb3wOEhbEPvArvOBB.iyuKslBjC7lSXCUzp29civDTvCg3M1j0XO",
"email_address": "john@onolan.org", "email_address": "john@onolan.org",
"profile_picture": "logo.png", "profile_picture": "logo.png",
"cover_picture": "", "cover_picture": "",

View file

@ -30,11 +30,17 @@
// Clone the _user so we don't expose the hashed password unnecessarily // Clone the _user so we don't expose the hashed password unnecessarily
userData = _.extend({}, _user); userData = _.extend({}, _user);
return self.model.forge({email_address: userData.email_address}).fetch().then(function (user) {
if (!!user.attributes.email_address) {
return when.reject(new Error('A user with that email address already exists.'));
}
return nodefn.call(bcrypt.hash, _user.password, null, null).then(function (hash) { return nodefn.call(bcrypt.hash, _user.password, null, null).then(function (hash) {
userData.password = hash; userData.password = hash;
return BaseProvider.prototype.add.call(self, userData); return BaseProvider.prototype.add.call(self, userData);
}); });
});
}; };
/** /**
@ -47,12 +53,15 @@
return this.model.forge({ return this.model.forge({
email_address: _userdata.email email_address: _userdata.email
}).fetch().then(function (user) { }).fetch().then(function (user) {
if (!!user.attributes.email_address) {
return nodefn.call(bcrypt.compare, _userdata.pw, user.get('password')).then(function (matched) { return nodefn.call(bcrypt.compare, _userdata.pw, user.get('password')).then(function (matched) {
if (!matched) { if (!matched) {
return when.reject(new Error('Password does not match')); return when.reject(new Error('Passwords do not match'));
} }
return user; return user;
}); });
}
return when.reject(new Error('We do not have a record for such user.'));
}); });
}; };