Last active
July 30, 2022 19:34
-
-
Save LeCoupa/9879066 to your computer and use it in GitHub Desktop.
Reset a password with Meteor --> https://github.com/LeCoupa/awesome-cheatsheets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} | |
}); |
link is http://localhost:3000/#/reset-password/3nhpVCHKhkcG_ZyPflg2CasaFXvidU05l480C6af3pX
how can i remove # from link
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
where is the code for send button of id btn-submit (line 5 of reset-password.html)