I'm trying to reset a password with the accounts packages.
recover.html :
<template name="recoverPassword">
<div class="main-page">
<div class="profile-container">
<center>
<div id="warning"></div>
<div id="success"></div>
{{#if resetPassword}}
<form id="resetPasswordForm" method="post">
<input id="resetPasswordPassword" name="password" placeholder="New Password" type="password" >
<input id="resetPasswordPasswordConfirm" name="password-confirm" placeholder="Confirm" type="password" >
<input class="btn-submit" type="submit" value="Reset">
</form>
{{else}}
<form id="sendEmail">
<div class="log-classic">
<div class="show-no-error">
<input class="log-upper-box" type="email" id="recover-email" placeholder='{{_ "global.emailHolder"}}' required>
</div>
<div class="bt-act-in">
<input type="submit" class="btn bt-signin" value="{{_ "recover.sendMail"}}"/>
</div>
</div>
</form>
{{/if}}
</center>
</div>
</div>
</template>
recover.js :
if(Meteor.isClient){
Template.recoverPassword.rendered = function(){
if (Accounts._resetPasswordToken){
Session.set('resetPassword', Accounts._resetPasswordToken);
}
}
Template.recoverPassword.helpers({
resetPassword: function(){
return Session.get('resetPassword') || false;
}
});
Template.recoverPassword.events({
'submit #sendEmail': function(event, template){
event.preventDefault();
template.find('#warning').innerHTML = "";
template.find('#success').innerHTML = "";
var email = template.find('#recover-email').value.trim();
Accounts.forgotPassword({email: email}, function(err) {
if (err){
if (err.message === 'User not found [403]') {
template.find('#warning').innerHTML = "There is no account registered with this email!";
}else{
console.log(err.message);
template.find('#warning').innerHTML = "We are sorry but something went wrong.";
}
}else{
template.find('#success').innerHTML = "An email has been sent";
}
});
},
'submit #resetPassword': function(e, t) {
e.preventDefault();
var password = t.find('#resetPasswordPassword').value;
var passwordConfirm = t.find('#resetPasswordPasswordConfirm').value;
console.log("pwd : " + password);
if (true){
Accounts.resetPassword(Session.get('resetPassword'), password, function(err) {
if (err) {
console.log(err.message);
template.find('warning').innerHTML = "We are sorry but something went wrong.";
} else {
console.log("wesh");
template.find('success').innerHTML = "Your password as been updated!";
Session.set('resetPassword', null);
}
});
}
}
});
}
The recoverPassword template is included in my /splash page. When I enter an unvalid email, I do well have the message indicating the email doesnt exists. Otherwise, a mail is sent with this message :
Hello,
To reset your password, simply click the link below.
http://mywebsite.herokuapp.com/#/reset-password/a7jr8WgGNRSJYHQg5x4vQhUn_qZSZEDxeJEtBgdjugD
Thanks.
Then I click on the link, and get to the splash page. Then the url change from the one I clicked on to /splash (in other ords, the token disapear from the url bar of the browser).
The template correctly change, I type the new password, and then I had to disable Adblock to make it works. So did I, the adblock related erreor get out, but now, when I submit the form with the new password, nothings happens, and the accounts password keep unchanged :/
Of course, I've looked for some tips / documentation on the web, but nothing helped me to get further.
Could someone helps me as soon as possible ?
Thanks a lot,
David
答案 0 :(得分:0)
用户喜欢的功能
Accounts.changePassword(OldPass, NewPass,function (err) {});