Skip to content

Instantly share code, notes, and snippets.

@LeCoupa
Last active July 30, 2022 19:34
Show Gist options
  • Save LeCoupa/9879066 to your computer and use it in GitHub Desktop.
Save LeCoupa/9879066 to your computer and use it in GitHub Desktop.
Reset a password with Meteor --> https://github.com/LeCoupa/awesome-cheatsheets
<template name="ForgotPassword">
<form action="/forgot" id="forgotPasswordForm" method="post">
<input id="forgotPasswordEmail" type="text" name="email" placeholder="Email Address">
<input class="btn-submit" type="submit" value="Send">
</form>
<!-- end #forgot-password-form -->
</template>
<template name="ResetPassword">
{{#if resetPassword}}
<form action="/reset-password" 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>
<!-- end #reset-password-form -->
{{/if}}
</template>
// Do not forget to add the email package: $ meteor add email
// and to configure the SMTP: https://gist.github.com/LeCoupa/9879221
Template.ForgotPassword.events({
'submit #forgotPasswordForm': function(e, t) {
e.preventDefault();
var forgotPasswordForm = $(e.currentTarget),
email = trimInput(forgotPasswordForm.find('#forgotPasswordEmail').val().toLowerCase());
if (isNotEmpty(email) && isEmail(email)) {
Accounts.forgotPassword({email: email}, function(err) {
if (err) {
if (err.message === 'User not found [403]') {
console.log('This email does not exist.');
} else {
console.log('We are sorry but something went wrong.');
}
} else {
console.log('Email Sent. Check your mailbox.');
}
});
}
return false;
},
});
if (Accounts._resetPasswordToken) {
Session.set('resetPassword', Accounts._resetPasswordToken);
}
Template.ResetPassword.helpers({
resetPassword: function(){
return Session.get('resetPassword');
}
});
Template.ResetPassword.events({
'submit #resetPasswordForm': function(e, t) {
e.preventDefault();
var resetPasswordForm = $(e.currentTarget),
password = resetPasswordForm.find('#resetPasswordPassword').val(),
passwordConfirm = resetPasswordForm.find('#resetPasswordPasswordConfirm').val();
if (isNotEmpty(password) && areValidPasswords(password, passwordConfirm)) {
Accounts.resetPassword(Session.get('resetPassword'), password, function(err) {
if (err) {
console.log('We are sorry but something went wrong.');
} else {
console.log('Your password has been changed. Welcome back!');
Session.set('resetPassword', null);
}
});
}
return false;
}
});
@GauravPanwar100
Copy link

where is the code for send button of id btn-submit (line 5 of reset-password.html)

@devanghire
Copy link

@55
Copy link

55 commented Dec 12, 2020

@devanghire

You can override URL this way:

Accounts.urls.resetPassword = function (token) {
  return Meteor.absoluteUrl('reset-password/' + token);
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment