Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Commit

Permalink
remove givenName and surname restrictions to registration data model
Browse files Browse the repository at this point in the history
  • Loading branch information
typerandom committed Aug 28, 2016
1 parent 2ece900 commit 174e449
Showing 1 changed file with 0 additions and 34 deletions.
34 changes: 0 additions & 34 deletions lib/controllers/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,29 +69,6 @@ function defaultJsonResponse(req, res) {
helpers.strippedAccountResponse(req.user, res);
}

/**
* The Stormpath API requires the `givenName` and `surname` fields to be
* provided, but as a convenience our framework integrations allow you to
* omit this data and fill those fields with the string `UNKNOWN` - but only
* if the field is not explicitly required.
*
* @function
*
* @param {Object} stormpathConfig - The express-stormpath configuration object
* @param {Object} req - The http request.
*/
function applyDefaultAccountFields(stormpathConfig, req) {
var registerFields = stormpathConfig.web.register.form.fields;

if ((!registerFields.givenName || !registerFields.givenName.required || !registerFields.givenName.enabled) && !req.body.givenName) {
req.body.givenName = 'UNKNOWN';
}

if ((!registerFields.surname || !registerFields.surname.required || !registerFields.surname.enabled) && !req.body.surname) {
req.body.surname = 'UNKNOWN';
}
}

/**
* Register a new user -- either via a JSON API, or via a browser.
*
Expand Down Expand Up @@ -140,8 +117,6 @@ module.exports = function (req, res, next) {
break;

case 'POST':
applyDefaultAccountFields(config, req);

handlePreRegistration(req.body, function (err) {
if (err) {
return helpers.writeJsonError(res, err);
Expand Down Expand Up @@ -210,15 +185,6 @@ module.exports = function (req, res, next) {
// to validate the user's data and create their account.
case 'POST':
async.waterfall([
// What we'll do here is simply set default values for `givenName` and
// `surname`, because these value are annoying to set if you don't
// care about them. Eventually Stormpath is going to remove these
// required fields, but for now this is a decent workaround to ensure
// people don't have to deal with that stuff.
function (callback) {
applyDefaultAccountFields(config, req);
callback();
},
function (callback) {
handlePreRegistration(req.body, function (err) {
if (err) {
Expand Down

0 comments on commit 174e449

Please sign in to comment.