Monday, April 16, 2012

is this the right way to do login logic in meteor to display a simple "invalid login" message?

I started this example project to learn meteor:



https://github.com/andrewarrow/question-raven/



I'm trying to duplicated a popular question/answer site functionality just to learn meteor.



Above my login form I have this in the template:



 {{#if invalid }}
<div style="background-color: yellow; padding: 3px 3px 3px 3px;">
login invalid, please try again.
</div>
{{/if}}


and I'm starting the login logic like this:



Template.hello.events = {
'click #login' : function () {
var email = $('#email').val();
var password = $('#password').val();
if (false) {
Session.set('user_id', 1);
} else {
Session.set('invalid', 1);
}
}
};


Then in order for the invalid variable to work in the template I have this function:



Template.hello.invalid = function () {
return Session.get('invalid') != null;
};


Is this the right way to do this? Does every variable the template references have to be a function? Should I use the Session store to record a login was invalid so a function can return true/false?





No comments:

Post a Comment