Example #1
0
 module.exports.reset = function *() {

  var body = this.request.body;
  var email = body.email;

  // Check if email was passed as param
  if(!email) this.throw(403, 'The email field is required');

  // check for existing user
  var id = yield H.userExists(email);
  if(!id) this.throw(404, 'This account does not exist. Please sign up.');

  // Generate password
  var realPassword = randomstring.generate(7);

  // encrypt pass - concider putting in model pre function
  var salt = yield bcrypt.genSalt(10);
  var password = yield bcrypt.hash(realPassword, salt);

  // Update record
  var record = yield r.db(config.db.db).table(M.User.getTableName()).filter({email: email }).update({ password: password });

  // Send password email with realPassword

  this.body = {message: 'Password has been reset'};
  this.status = 200;

 }
Abstract.prototype.hashPassword = function *() {
  if(this.newPass) {
    this.newPass = false;
    let salt = yield bcrypt.genSalt(10);
    this.pass = yield bcrypt.hash(this.pass, salt);
  };
};
Example #3
0
	hashPassword: function* (password) {

		// encrypt pass - concider putting in model pre function
		var salt = yield bcrypt.genSalt(10);
		var hash = yield bcrypt.hash(password, salt);

		return hash;
	}
exports.create = function *(user) {
  const fillable = [ 'email', 'name', 'passwd', 'status' ]
  if (user.password) {
    const salt = yield bcrypt.genSalt(10)
    user.passwd = yield bcrypt.hash(user.password, salt)
  }
  user.status = 0

  return yield models.users.create(user, { fields: fillable })
}
exports.update = function *(hid, user) {
  const fillable = [ 'name', 'passwd', 'status' ]
  const id = +hashids.decode(hid)
  if (!isFinite(id)) return false
  const salt = yield bcrypt.genSalt(10)
  if (!!user.password) {
    user.passwd = yield bcrypt.hash(user.password, salt)
  }
  const u = yield models.users.findOne({
    where: { id: id }
  })
  return yield u.update(user, { fields: fillable })
}
exports.recreate = function *(unuser) {
  const fillable = [ 'name', 'passwd' ]
  const user = yield models.users.findOne({
    where: { email: unuser.email },
    paranoid: false
  })

  if (user) {
    if (user.password) {
      const salt = yield bcrypt.genSalt(10)
      user.passwd = yield bcrypt.hash(user.password, salt)
    }

    user.setDataValue('deletedAt', null)
    yield user.save({ paranoid: false })
  }

  return yield user.update(unuser, { fields: fillable })
}
Abstract.prototype.setResetPassword = function *() {
  let salt = yield bcrypt.genSalt(10),
      hash = yield bcrypt.hash('restpass', salt);
  this.temporaryPass = hash.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, '');
  this.resetPasswordExpires = 3600 + (Date.now() / 1000 | 0); 
};