我是meteor的新手,我正在尝试恢复密码并在Meteor中更改密码。我将在下面发布我用来执行此操作的代码。我确实渲染了模板,但密码不会改变。有人可以帮我这个吗?我正在使用包accounts-password
。
自定义-useraccounts.html:
<template name="RecoverPassword">
<form id="set-new-password">
<label for="new-password">New Password</label>
<input type="password" id="new-password" placeholder="Try not to forget this one.">
<input type="submit" value="Set New Password">
<p id="form-messages"></p>
</form>
<form id="forgot-password">
<label for="user-email">Email</label>
<input type="text" id="user-email" placeholder="Email">
<input type="submit" value="Get Reset Password Instructions">
<p id="form-messages"></p>
</form>
</template>
<template name="ChangePassword">
<form id="change-password">
<label for="current-password">Current Password</label>
<input type="password" id="current-password" placeholder="Current Password">
<label for="new-password">New Password</label>
<input type="password" id="new-password" placeholder="New Password">
<label for="new-password-repeated">Repeat New Password</label>
<input type="password" id="new-password-repeated" placeholder="Repeat New Password">
<input type="submit" value="Update Password">
<p id="form-messages"></p>
</form>
</template>
自定义用户帐户.js:
if (Meteor.isServer) {
Template.RecoverPassword.events({
'submit #change-password': function(event, template) {
var currentPassword,
newPassword,
newPasswordRepeated;
currentPassword = template.find('#current-password');
newPassword = template.find('#new-password');
newPasswordRepeated = template.find('#new-password-repeated');
if (newPassword !== newPasswordRepeated) {
template.find('#form-messages').html("The new passwords don't match!");
return false;
}
if (Meteor.isServer) {
if (Accounts._resetPasswordToken) {
Session.set('resetPasswordToken', Accounts._resetPasswordToken);
}
Template.RecoverPassword.helpers({
resetPassword: function() {
return Session.get('resetPasswordToken');
}
});
Template.RecoverPassword.events({
'submit #forgot-password': function(event, template) {
event.preventDefault();
var email = template.find('#user-email'),
message;
alert(email);
if (email) {
Accounts.forgotPassword(email);
message = 'Sent a reset password link to ' + email + '.';
} else {
message = 'Please enter a valid email address.'
}
template.find('#form-messages').html(message);
return false;
},
'submit #set-new-password': function(event, template) {
event.preventDefault();
// Proper decoupled validation would be much nicer than this
var password = template.find('#new-password').value,
passwordTest = new RegExp("(?=.{6,}).*", "g");
if (passwordTest.test(password)) {
Accounts.resetPassword(
Session.get('resetPasswordToken'),
password,
function(error) {
if (err) {
template.find('#form-messages').html('There was a problem resetting your password.');
} else {
Session.set('resetPasswordToken', null);
}
});
} else {
template.find('#form-messages').html('Your password is too weak!');
}
return false;
}
});
}
我已删除了insecure
和autopublish
选项,并且我已发布了userdata。我只是无法理解为什么模板更改密码不起作用。
答案 0 :(得分:0)
嗯,问题是你在if (Meteor.isServer)
您的所有客户端代码都必须位于if (Meteor.isClient)
,这是任何模板级别。如果它位于名为client
的文件夹中,您也可以免费获得。