gpt4 book ai didi

javascript - 如何使用 Meteor 设置用户帐户?

转载 作者:行者123 更新时间:2023-11-28 01:32:16 25 4
gpt4 key购买 nike

我正在尝试使用我的 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;
}
});

最佳答案

顺便说一句,你的代码无法使用 fiddle 。

有几件事:

确保您已安装accounts-password,您可以使用meteor add account-password来执行此操作

您尚未提供注册代码,但假设您使用电子邮件进行注册,则应使用 {email: email} 以这种方式登录。

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

如果您提供更多有关您认为它不起作用的信息,也会更有帮助。提交页面会刷新页面吗?您的控制台中是否有任何 JavaScript 错误?您收到错误消息了吗?

关于javascript - 如何使用 Meteor 设置用户帐户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21978575/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com