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

Remove givenName and surname restrictions to registration data model #512

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: null
type: "text"
middleName:
enabled: false
Expand All @@ -79,7 +79,7 @@ web:
enabled: true
label: "Last Name"
placeholder: "Last Name"
required: true
required: null
type: "text"
username:
enabled: false
Expand Down
36 changes: 0 additions & 36 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 Expand Up @@ -253,8 +219,6 @@ module.exports = function (req, res, next) {
return writeFormError(err);
}

//console.log('Register account status!', account.status);

if (account.status === 'UNVERIFIED') {
return handleResponse(account, defaultUnverifiedHtmlResponse);
}
Expand Down
Loading