From ae6c1a3c092c61cffe097747473680711fb97cb1 Mon Sep 17 00:00:00 2001 From: Robin Date: Sun, 28 Aug 2016 19:00:13 +0200 Subject: [PATCH] remove givenName and surname restrictions to registration data model --- lib/config.yml | 4 ++-- lib/controllers/register.js | 34 ---------------------------------- 2 files changed, 2 insertions(+), 36 deletions(-) diff --git a/lib/config.yml b/lib/config.yml index f25ab415..7e4a02e2 100644 --- a/lib/config.yml +++ b/lib/config.yml @@ -67,7 +67,7 @@ web: enabled: true label: "First Name" placeholder: "First Name" - required: true + required: false type: "text" middleName: enabled: false @@ -79,7 +79,7 @@ web: enabled: true label: "Last Name" placeholder: "Last Name" - required: true + required: false type: "text" username: enabled: false diff --git a/lib/controllers/register.js b/lib/controllers/register.js index 625ba354..da8b5f35 100644 --- a/lib/controllers/register.js +++ b/lib/controllers/register.js @@ -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. * @@ -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); @@ -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) {