-
-
Save Siyfion/b0befb2c6e1ee488d301 to your computer and use it in GitHub Desktop.
This file contains 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
import { Meteor } from 'meteor/meteor'; | |
import { Accounts } from 'meteor/accounts-base'; | |
import { Template } from 'meteor/templating'; | |
import { ReactiveVar } from 'meteor/reactive-var'; | |
Template.login.onCreated(function loginOnCreated() { | |
this.emailSent = new ReactiveVar(false); | |
this.mode = new ReactiveVar('login'); | |
}); | |
Template.login.helpers({ | |
emailSent() { | |
return Template.instance().emailSent.get(); | |
}, | |
isMode(mode) { | |
return Template.instance().mode.get() === mode; | |
}, | |
}); | |
Template.login.events({ | |
'click .forgot-password'(e, template) { | |
e.preventDefault(); | |
template.emailSent.set(false); | |
template.mode.set('reset'); | |
}, | |
'click .js-cancel'(e, template) { | |
e.preventDefault(); | |
template.emailSent.set(false); | |
template.mode.set('login'); | |
}, | |
'submit .js-login-form'(e, template) { | |
e.preventDefault(); | |
if (!template.$('.accept-terms').is(':checked')) { | |
toastr.warning('You must accept the licence agreement before logging in.'); | |
return; | |
} | |
const emailOrUsername = template.$('#inputEmail').val().toLowerCase(); | |
if (template.mode.get() === 'login') { | |
const password = template.$('#inputPassword').val(); | |
Meteor.loginWithPassword(emailOrUsername, password); | |
} | |
}, | |
'submit .js-reset-pw'(e, template) { | |
e.preventDefault(); | |
const emailOrUsername = template.$('#inputEmail').val().toLowerCase(); | |
Accounts.forgotPassword({ email: emailOrUsername }); | |
template.emailSent.set(true); | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment