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 29, 2016
1 parent 2ece900 commit ae6c1a3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 36 deletions.
4 changes: 2 additions & 2 deletions lib/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ web:
enabled: true
label: "First Name"
placeholder: "First Name"
required: true
required: false
type: "text"
middleName:
enabled: false
Expand All @@ -79,7 +79,7 @@ web:
enabled: true
label: "Last Name"
placeholder: "Last Name"
required: true
required: false
type: "text"
username:
enabled: false
Expand Down
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 ae6c1a3

Please sign in to comment.