Skip to content

Instantly share code, notes, and snippets.

@alessioalex
Forked from tj/callbacks.js
Created January 18, 2014 06:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alessioalex/8487030 to your computer and use it in GitHub Desktop.
Save alessioalex/8487030 to your computer and use it in GitHub Desktop.
/**
* POST to create a new user.
*/
exports.create = function *(){
var body = yield parse(this);
// password
var pass = body.password;
assert(pass, 400, 'password is required');
delete body.password;
let {salt, hash} = yield password(pass);
body.password_salt = salt;
body.password_hash = hash;
// validate
users.schema.validate(body);
// see if the user exists
var exists = yield users.findOne({ username: body.username }, 'name');
assert(!exists, 400, 'username is taken');
// save
yield users.insert(body);
this.status = 201;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment