簡體   English   中英

如何通過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
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM