Skip to content

Instantly share code, notes, and snippets.

@Siyfion

Siyfion/login.js Secret

Created March 29, 2016 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Siyfion/b0befb2c6e1ee488d301 to your computer and use it in GitHub Desktop.
Save Siyfion/b0befb2c6e1ee488d301 to your computer and use it in GitHub Desktop.
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