Being relatively new to backbone.js, I’ve created several small tests from a simple model and collection displayed on a page, to the few dollars worth peepcode screencast about backbone (which is very good actually)
but, I still see everything directly referenced, as:
there is a certain model called User, then you have a view that prints how that user model looks.
lets say a user opens the site, sees a login form, after the submit click, where do I store / how do I handle the connection to the server, for validation and testing if the username / password were correct?
would I need to save things like that in a separate model?
I think I’m still thinking too mutch about really well defined entities in my app, a user, who has contacts. and I get the feeling that I will need to create models for more than just these defined entities.
You are thinking correctly. Login is just a method performed on behalf of the user entity. For me, what seems best is to just append a login method to your user model. It will check this.get(‘username’) and this.get(‘password’) and make an ajax request for validation.
This method should take in two callbacks, loginSuccess and loginError(error). When the login request comes back OK you should set some property on the user model: this.set({ authenticated: true })
Your views could then userModel.bind(‘change:authenticated’, this.update); and update themselves appropriately.