无法从 AngularJS + Stormpath 中的注册表单添加自定义字段
Can't add custom field from registration form in AngularJS + Stormpath
我想在新用户注册期间添加自定义字段,但显示错误消息:
is not a configured registration field.
但第 https://docs.stormpath.com/angularjs/sdk/#/api/stormpath.spRegistrationForm:spRegistrationForm 页上的文档指出:
Any form fields you supply that are not one of the default fields (first name, last name) will be automatically placed into the new account's customa data object.
我使用的代码:
<form ng-submit="submit()">
<div class="form-group">
<input type="text" class="form-control" placeholder="First Name" ng-model="formModel.givenName" required="" ng-disabled="creating">
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Last Name" ng-model="formModel.surname" required="" ng-disabled="creating">
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Email" ng-model="formModel.email" required="" ng-disabled="creating">
</div>
<div class="form-group">
<input type="password" class="form-control" placeholder="Password" ng-model="formModel.password" required="" ng-disabled="creating">
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Custom field" ng-model="formModel.customfield" required="" ng-disabled="creating">
</div>
<p class="alert alert-danger" ng-show="error>
<button type="submit" class="btn btn-primary" ng-disabled="creating">Register</button>
</form>
如何在注册表单上添加自定义字段?
从错误消息来看,您似乎在后端使用我们的 Express-Stormpath 库(如果这不正确,请告诉我)。
您还需要在 Express 服务器中配置您的字段。我们还需要服务器端表单配置,以防止对用户自定义数据对象的任意请求。
可以在此处找到有关表单配置的文档:
http://docs.stormpath.com/nodejs/express/latest/registration.html#creating-custom-fields
希望对您有所帮助! P.S。我在 Stormpath 工作 :)
我想为现在遇到此问题的任何人提交更新的答案。在深入研究 node_modules/express-stormpath/lib/helpers/get-required-registration-fields.j
之后,我注意到第 26 行代码引用了 config.web.register.fields
而文档引用了 web.register.form.fields。通过删除 form
键并提升字段键,一切正常!
在服务器端,stormpath init 应该是这样的
web: {
produces:
['application/json'],
register: {
enabled: true,
uri: '',
form: {
fields:
{ organization_id: { enabled: true, required: true, } }
}
}
======
我想在新用户注册期间添加自定义字段,但显示错误消息:
is not a configured registration field.
但第 https://docs.stormpath.com/angularjs/sdk/#/api/stormpath.spRegistrationForm:spRegistrationForm 页上的文档指出:
Any form fields you supply that are not one of the default fields (first name, last name) will be automatically placed into the new account's customa data object.
我使用的代码:
<form ng-submit="submit()">
<div class="form-group">
<input type="text" class="form-control" placeholder="First Name" ng-model="formModel.givenName" required="" ng-disabled="creating">
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Last Name" ng-model="formModel.surname" required="" ng-disabled="creating">
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Email" ng-model="formModel.email" required="" ng-disabled="creating">
</div>
<div class="form-group">
<input type="password" class="form-control" placeholder="Password" ng-model="formModel.password" required="" ng-disabled="creating">
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Custom field" ng-model="formModel.customfield" required="" ng-disabled="creating">
</div>
<p class="alert alert-danger" ng-show="error>
<button type="submit" class="btn btn-primary" ng-disabled="creating">Register</button>
</form>
如何在注册表单上添加自定义字段?
从错误消息来看,您似乎在后端使用我们的 Express-Stormpath 库(如果这不正确,请告诉我)。
您还需要在 Express 服务器中配置您的字段。我们还需要服务器端表单配置,以防止对用户自定义数据对象的任意请求。
可以在此处找到有关表单配置的文档:
http://docs.stormpath.com/nodejs/express/latest/registration.html#creating-custom-fields
希望对您有所帮助! P.S。我在 Stormpath 工作 :)
我想为现在遇到此问题的任何人提交更新的答案。在深入研究 node_modules/express-stormpath/lib/helpers/get-required-registration-fields.j
之后,我注意到第 26 行代码引用了 config.web.register.fields
而文档引用了 web.register.form.fields。通过删除 form
键并提升字段键,一切正常!
在服务器端,stormpath init 应该是这样的
web: {
produces:
['application/json'],
register: {
enabled: true,
uri: '',
form: {
fields:
{ organization_id: { enabled: true, required: true, } }
}
}
======