Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var User = Backbone.Model.extend({
- defaults: {
- login: '',
- password: '',
- authToken: ''
- }
- });
- var UserCollection = Backbone.Collection.extend({
- url: 'http://localhost:3000/users',
- // creates a random token
- setToken: function () {
- var rand = function () {
- return Math.random().toString(36).substr(2)
- }
- var token = rand() + rand();
- this.set({authToken: token});
- }
- });
- var LoginView = Backbone.View.extend({
- initialize: function () {
- this.collection = new UserCollection();
- // template
- }
- // render function omitted
- signIn: function () {
- var login = $('#login').val();
- var password = $('#password').val();
- /**
- finds a user within with the values from input fields
- inside the collection
- */
- if (login && password) {
- this.collection.fetch({
- data: {
- login: login,
- password: password
- }
- });
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement