如何创建一个登录系统与流星

How to create a log in system with meteor?

本文关键字:登录 系统 流星 一个 何创建 创建      更新时间:2023-09-26

我正在努力掌握流星,但我是一个一定的初学者。我要在这里寻求帮助,做一件非常基本的事情。

如何创建2个表单(用于登录和密码输入)和一个按钮,将使用Accounts.createUser(options, [callback])注册帐户

我需要了解如何将两种形式与函数联系起来的最基本的事情。

编辑:我试了一件事。完全瞎了眼。
    if (Meteor.isClient) {
  Template.login.account = function () {
    if (Meteor.user() == null) {
        return 
            <form id="login">
                <input type="email" id="email" />
                <input type="text" id="logintext" />
                <input type="password" id="password" />
            </form>
        };
    };
  Template.login.events({
    'click input' : Sumbit();
    })
  }
function Sumbit(){
    var login, password, email;
    document.getElementById('email').value = email; 
    document.getElementById('logintext').value = login; 
    document.getElementById('password').value = password; 
    Accounts.createUser(login, email, password)
}

Meteor已经提供了一个相当不错的用户系统:accounts-api

对于登录表单:只需添加accounts-ui包(meteor add accounts-ui)并将函数添加到模板中:

<template name="main">
    {{loginButtons}} <!--These are your login-buttons -->
</template>

更多信息:这里是accounts-ui包的文档

也有手动的方法。查看本的这篇文章:http://blog.benmcmahen.com/post/41741539120/building-a-customized-accounts-ui-for-meteor

诀窍是创建一个表单,在提交时从表单中获取值并将它们传递给Accounts.createUser()。

传递这些值,比如电子邮件和密码,让Meteor完成创建帐户的繁重工作。

Accounts.createUser()在文档中:
http://docs.meteor.com/accounts_createuser

对于您的注册页面,使用独特的字段,如年龄或名字,将这些作为嵌套的详细信息放在配置文件中。

登录用户的过程非常相似。除了"Account"。createUser'你将使用'Meteor.loginWithPassword'。您将用户类型的详细信息从您创建的登录表单传递给它,然后Meteor将检查用户是否存在,然后为他们创建会话。

这是我所有的初学者开发/流星的理解。但我相信这是基本流程。