-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Forgot password feature #15579 #95
base: dev
Are you sure you want to change the base?
Changes from all commits
1c73338
f72f48c
e958c12
63f4d3b
223af2f
2fbee23
c5a6519
463164c
39e02d6
bcce067
9271f3f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<template name="resetpwd"> | ||
{{#if resetPassword}} | ||
<div class="newpwdbox"> | ||
<div class="newpwdnav"> | ||
<a id="navHome" class="link" title="Home"><i class="fa fa-home"></i></a> | ||
</div> | ||
<h1 class="formtitle">Change password</h1> | ||
<div class="newpwdform"> | ||
<input type="password" pattern=".{6,30}" id="newpasswordbox" class="input" placeholder="New password..." autocomplete="off"> | ||
<input type="password" id="newpasswordconfirm" class="input" placeholder="Confirm password..." autocomplete="off"> | ||
<div id="newpwdsubmitbutton"> | ||
Change | ||
</div> | ||
</div> | ||
</div> | ||
<div id="pwdchangemessage">Your password has been changed successfully. Redirecting to homepage...</div> | ||
{{else}} | ||
<div id="darker"> | ||
</div> | ||
<div class="formcontainer"> | ||
{{> close_button}} | ||
<h1 class="formtitle">Forgot Password</h1> | ||
<div class="modaltopmessage"> | ||
Enter your email to receive the password reset link. | ||
</div> | ||
<div class="inputcontainer"> | ||
<input type="text" id="loginemail" spellcheck="false" class="input" placeholder="Email..."> | ||
<p id="mailSentMessage">✔ Check your inbox</p> | ||
<img src="/loading.gif" id="newPwdLoadingSpinner"> | ||
<div id="forgotsubmitbutton"> | ||
Send Email | ||
</div> | ||
</div> | ||
</div> | ||
{{/if}} | ||
|
||
</template> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import $ from 'jquery'; | ||
|
||
Accounts.onResetPasswordLink((token, done) => { | ||
Router.go('resetpwd'); | ||
}); | ||
|
||
if (Accounts._resetPasswordToken) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You shouldn't have code that's sitting outside functions like this. I think this is only getting run when the file is first imported. |
||
Session.set('resetPasswordVar', Accounts._resetPasswordToken); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you want to do it this way, you could set both the token and the done callback as elements in the |
||
} | ||
|
||
function showChangePwdError(reason, parentElement, nextElement) { | ||
if (typeof currentError !== 'undefined') { | ||
Blaze.remove(currentError); | ||
} | ||
const parentNode = $('.' + parentElement)[0]; | ||
const nextNode = $('.' + nextElement)[0]; | ||
currentError = Blaze.renderWithData(Template.form_error, reason, parentNode, nextNode); | ||
} | ||
|
||
Template.resetpwd.onRendered(() => { | ||
$('.formcontainer').hide().fadeIn(400); | ||
$('#darker').hide().fadeIn(400); | ||
}); | ||
|
||
Template.resetpwd.helpers({ | ||
resetPassword() { | ||
return Session.get('resetPasswordVar'); | ||
}, | ||
}); | ||
|
||
Template.resetpwd.events({ | ||
'keypress #newpasswordconfirm': function (event, template) { | ||
event.which = event.which || event.keyCode; | ||
if (event.which === 13) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Set |
||
event.preventDefault(); | ||
$('#newpwdsubmitbutton').click(); | ||
} | ||
}, | ||
'keypress #loginemail': function (event, template) { | ||
event.which = event.which || event.keyCode; | ||
if (event.which === 13) { | ||
event.preventDefault(); | ||
$('#forgotsubmitbutton').click(); | ||
} | ||
}, | ||
'click #forgotsubmitbutton': function (event, template) { | ||
$('#mailSentMessage').css('display', 'none'); | ||
const email = $('#loginemail').val(); | ||
$('#newPwdLoadingSpinner').css('display', 'block'); | ||
Accounts.forgotPassword({ email: email }, function (e) { | ||
$('#newPwdLoadingSpinner').css('display', 'none'); | ||
if (e) { | ||
const errorMessage = [ | ||
{ reason: 'User not found', message: "The email address that you've entered doesn't match any account." }, | ||
{ reason: 'Internal server error', message: 'Please check your internet connection.' }, | ||
]; | ||
const in1 = errorMessage.findIndex(x => x.reason === e.reason); | ||
if (in1 === -1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be more readable as |
||
showChangePwdError(e.reason, 'formcontainer', 'inputcontainer'); | ||
} else { | ||
showChangePwdError(errorMessage[in1].message, 'formcontainer', 'inputcontainer'); | ||
} | ||
} else { | ||
$('#mailSentMessage').css('display', 'block'); | ||
} | ||
}); | ||
}, | ||
'click #newpwdsubmitbutton': function (event, template) { | ||
const newPass = $('#newpasswordbox').val(); | ||
const newPassConfirm = $('#newpasswordconfirm').val(); | ||
if (!$('#newpasswordbox')[0].checkValidity()) { | ||
showChangePwdError('Password must be between 6 and 30 characters', 'newpwdbox', 'newpwdform'); | ||
return false; | ||
} else if (newPass !== newPassConfirm) { | ||
showChangePwdError('Passwords do not match', 'newpwdbox', 'newpwdform'); | ||
return false; | ||
} | ||
Accounts.resetPassword(Session.get('resetPasswordVar'), newPass, function (e) { | ||
if (e) { | ||
const errorMessage = [ | ||
{ reason: 'Token expired', message: 'This link is expired.' }, | ||
{ reason: 'Internal server error', message: 'Please check your internet connection.' }, | ||
]; | ||
const in1 = errorMessage.findIndex(x => x.reason === e.reason); | ||
if (in1 === -1) { | ||
showChangePwdError(e.reason, 'newpwdbox', 'newpwdform'); | ||
} else { | ||
showChangePwdError(errorMessage[in1].message, 'newpwdbox', 'newpwdform'); | ||
} | ||
} else { | ||
$('.newpwdbox').css('display', 'none'); | ||
$('#pwdchangemessage').css('display', 'block'); | ||
setTimeout(() => { | ||
Session.set('resetPasswordVar', null); | ||
Router.go('/'); | ||
}, 3000); | ||
} | ||
}); | ||
}, | ||
'click #navHome': function (event, template) { | ||
Router.go('/'); | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
.newpwdbox { | ||
text-align: center; | ||
} | ||
|
||
.newpwdnav { | ||
height: 50px; | ||
background-color: #293340; | ||
margin-bottom: 50px; | ||
} | ||
|
||
.newpwdnav > #navHome > .fa-home { | ||
font-size: 2em; | ||
padding: 10px; | ||
} | ||
|
||
.input { | ||
width: 300px!important; | ||
} | ||
|
||
#newpwdsubmitbutton { | ||
width: 200px; | ||
display: block; | ||
height: 30px; | ||
margin: 0px auto; | ||
background-color: #2ecc71; | ||
margin-top: 20px; | ||
margin-bottom: 10px; | ||
border-radius: 5px; | ||
cursor: pointer; | ||
text-align: center; | ||
font-weight: 600; | ||
color: white; | ||
padding-top: 5px; | ||
|
||
&:hover { | ||
background-color: #4cd785; | ||
} | ||
} | ||
|
||
#forgotsubmitbutton { | ||
margin-bottom: 10px !important; | ||
} | ||
|
||
.newpwdbox > h1 { | ||
margin-bottom: 20px; | ||
} | ||
|
||
.newpwdbox > .error { | ||
max-width: 420px; | ||
display: inline-block; | ||
} | ||
|
||
#newPwdLoadingSpinner { | ||
width: 12%; | ||
display: inline-block; | ||
margin-left: 44%; | ||
display: none; | ||
} | ||
|
||
#mailSentMessage { | ||
color: #42a1f4; | ||
background-color: #fff; | ||
width: 50%; | ||
margin-left: 25%; | ||
text-align: center; | ||
display: none; | ||
} | ||
|
||
#pwdchangemessage { | ||
display: none; | ||
width: 300px; | ||
text-align: center; | ||
width: 100%; | ||
font-size: 1.5em; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you writing this manually instead of using one of the packages suggested in the Meteor docs?