如何通过 react.js 在 meteor.js 中创建用户
How to create a user in a meteor.js through the react.js
我正在尝试根据组件的反应创建用户:
import React, { Component, PropTypes } from 'react';
import ReactDOM from 'react-dom';
import { Accounts } from 'meteor/accounts-base'
import { createContainer } from 'meteor/react-meteor-data';
import { FlowRouter } from 'meteor/kadira:flow-router';
import { mount } from 'react-mounter';
FlowRouter.route('/signup', { name: 'signup', action(){ mount( SignUp ); } });
AccountsTemplates.configure({
forbidClientAccountCreation: false
});
class SignUp extends Component {
constructor(props) {
super(props);
this.state = { mail:'', pass:''};
}
handleMailChange(e){ this.setState({mail: e.target.value}); }
handlePassChange(e){ this.setState({pass: e.target.value}); }
eSignup(e){
e.preventDefault();
console.log("Sign Up Form submitted.");
Accounts.createUser({ email:'mail', password:'passwd'}, (err)=> {
if (err) console.error(err.reason);
else {
console.info('Create user success !');
FlowRouter.go('/');
}
});
}
render(){
return (
<div className="row">
<div className="container">
<form name="login">
<input type="email" name="mail" onChange={this.hMailChange.bind(this)}/>
<input type="password" name="Pass" onChange={this.hPassChange.bind(this)}/>
<input type="submit" value="Signup" onClick={this.Signup.bind(this)}/>
</form>
</div>
</div>
);
}
}
但是我得到一个错误:403 Signups forbidden
。
我查看了流星组件的源代码。也许我在那里找到了产生错误的行:
https://github.com/meteor/accounts/blob/master/packages/accounts-password/password_server.js#L1014
if (Accounts._options.forbidClientAccountCreation)
return { error: new Meteor.Error(403, "Signups forbidden") };
而且我不明白如果我将 Accounts._options.forbidClientAccountCreation
设置为 false
为什么这个测试会起作用
account-ui
和其他与 ui
和 users
一起使用的包我删除了。
我的package.json
:
"dependencies": {
"babel-runtime": "^6.18.0",
"bcrypt": "^1.0.1",
"classnames": "^2.2.5",
"lib": "^1.0.5",
"meteor-node-stubs": "~0.2.0",
"particles.js": "^2.0.0",
"react": "^15.4.1",
"react-addons-pure-render-mixin": "^15.4.1",
"react-dom": "^15.4.1",
"react-mounter": "^1.2.0"
}
我做错了什么?
您的代码必须在某处将 forbidClientAccountCreation
设置为 true
。您需要将该选项设置为 false
才能在客户端中创建用户。
import { AccountsCommon } from 'meteor/accounts-base'
AccountsCommon.config({
forbidClientAccountCreation: false
});
我正在尝试根据组件的反应创建用户:
import React, { Component, PropTypes } from 'react';
import ReactDOM from 'react-dom';
import { Accounts } from 'meteor/accounts-base'
import { createContainer } from 'meteor/react-meteor-data';
import { FlowRouter } from 'meteor/kadira:flow-router';
import { mount } from 'react-mounter';
FlowRouter.route('/signup', { name: 'signup', action(){ mount( SignUp ); } });
AccountsTemplates.configure({
forbidClientAccountCreation: false
});
class SignUp extends Component {
constructor(props) {
super(props);
this.state = { mail:'', pass:''};
}
handleMailChange(e){ this.setState({mail: e.target.value}); }
handlePassChange(e){ this.setState({pass: e.target.value}); }
eSignup(e){
e.preventDefault();
console.log("Sign Up Form submitted.");
Accounts.createUser({ email:'mail', password:'passwd'}, (err)=> {
if (err) console.error(err.reason);
else {
console.info('Create user success !');
FlowRouter.go('/');
}
});
}
render(){
return (
<div className="row">
<div className="container">
<form name="login">
<input type="email" name="mail" onChange={this.hMailChange.bind(this)}/>
<input type="password" name="Pass" onChange={this.hPassChange.bind(this)}/>
<input type="submit" value="Signup" onClick={this.Signup.bind(this)}/>
</form>
</div>
</div>
);
}
}
但是我得到一个错误:403 Signups forbidden
。
我查看了流星组件的源代码。也许我在那里找到了产生错误的行:
https://github.com/meteor/accounts/blob/master/packages/accounts-password/password_server.js#L1014
if (Accounts._options.forbidClientAccountCreation)
return { error: new Meteor.Error(403, "Signups forbidden") };
而且我不明白如果我将 Accounts._options.forbidClientAccountCreation
设置为 false
account-ui
和其他与 ui
和 users
一起使用的包我删除了。
我的package.json
:
"dependencies": {
"babel-runtime": "^6.18.0",
"bcrypt": "^1.0.1",
"classnames": "^2.2.5",
"lib": "^1.0.5",
"meteor-node-stubs": "~0.2.0",
"particles.js": "^2.0.0",
"react": "^15.4.1",
"react-addons-pure-render-mixin": "^15.4.1",
"react-dom": "^15.4.1",
"react-mounter": "^1.2.0"
}
我做错了什么?
您的代码必须在某处将 forbidClientAccountCreation
设置为 true
。您需要将该选项设置为 false
才能在客户端中创建用户。
import { AccountsCommon } from 'meteor/accounts-base'
AccountsCommon.config({
forbidClientAccountCreation: false
});