簡體   English   中英

如何使用Meteor設置用戶帳戶?

[英]How to set up user accounts with Meteor?

我正在嘗試使用Meteor應用程序設置用戶帳戶。 現在,我已經完成了登錄和注冊表單,但是它們不起作用。 有誰知道如何做到這一點? 這是我的代碼: http : //jsfiddle.net/5AMWE5T/X8aJf/1/

HTML:

<body>
    <div id="topbar">
        <form id="login-form" action="/">
            <div>
                <input type="email" id="login-email" />
                <input type="password" id="login-password" />
                <input type="submit" class="btn btn-info" id="login-button" value="Sign in" />
            </div>
        </form>
    </div>
    <div id="register-box">
        <form id="register-form" action="action">
            <div>
                <input type="username" id="account-username" placeholder=" Username" />
                <input type="email" id="account-email" placeholder="Email" />
                <input type="password" id="account-password" placeholder="Password" />
                <input type="submit" class="btn btn-success" id="create-account" value="Sign up" />
            </div>
        </form>
    </div>

CSS:

#topbar {
    height: 40px;
    width: 100%;
    opacity: 1;
    background-color: #47a7d3;
    box-shadow: 0.1em 0.1em 0.1em;
    position: absolute;
    top: 0;
    left: 0;
    padding: 0;
}
#register-form {
    text-align: center;
    margin-top: 15px;
}
#account-username {
    margin-bottom: 0.75em;
    border-radius: 0.3em;
    border-width: 0.1em;
    border-color: #ffffff;
    width: 15.4em;
    margin-left: 0.1em;
    height: 1.8em;
    box-shadow: 0 0 0.1em #676767;
}
#login-form {
    position: absolute;
    width: 100%;
    top: 0.3em;
    letter-spacing: 0.1em;
    right: 0.33em;
    text-align: right;
}
#login-email {
    width: 180px;
}
#login-password {
    width: 100px;
}
#login-button {
    position: relative;
    top: -5px;
    font-family:'Montserrat Alternates';
    font-size: 12px;
    color: #ffffff;
    letter-spacing: 0.05em;
}

JavaScript的:

Template.login.events({

    'submit #login-form': function (e, t) {
        e.preventDefault();
        // retrieve the input field values
        var email = t.find('#login-email').value,
            password = t.find('#login-password').value;

        // Trim and validate your fields here.... 

        var trimInput = function (val) {
            return val.replace(/^\s*|\s*$/g, "");
        }
        var email = trimInput(email);
        // If validation passes, supply the appropriate fields to the
        // Meteor.loginWithPassword() function.
        Meteor.loginWithPassword(email, password, function (err) {
            if (err)
            // The user might not have been found, or their password
            // could be incorrect. Inform the user that their
            // login attempt has failed.
            console.log("Your email or password are incorrect")
            else
            // The user has been logged in.
            console.log("You have been logged in!")
        });
        return false;
    }
});

你的代碼不能和小提琴一起工作。

有兩件事:

確保已安裝accounts-password ,可以使用meteor add accounts-password來完成此操作

您尚未提供注冊代碼,但假設您使用電子郵件進行注冊,則應使用{email:email}登錄。

Meteor.loginWithPassword({email: email, password, function (err) {

如果您提供了更多有關您認為它不起作用的信息,也將有所幫助。 提交頁面會刷新頁面嗎? 您的控制台中是否存在任何JavaScript錯誤? 您是否收到錯誤消息?

暫無
暫無

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

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