Advertisement
Guest User

Untitled

a guest
Oct 17th, 2016
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. var User = Backbone.Model.extend({
  2. defaults: {
  3. login: '',
  4. password: '',
  5. authToken: ''
  6. }
  7. });
  8.  
  9. var UserCollection = Backbone.Collection.extend({
  10. url: 'http://localhost:3000/users',
  11.  
  12. // creates a random token
  13. setToken: function () {
  14. var rand = function () {
  15. return Math.random().toString(36).substr(2)
  16. }
  17.  
  18. var token = rand() + rand();
  19. this.set({authToken: token});
  20. }
  21. });
  22.  
  23. var LoginView = Backbone.View.extend({
  24. initialize: function () {
  25. this.collection = new UserCollection();
  26. // template
  27. }
  28. // render function omitted
  29.  
  30. signIn: function () {
  31. var login = $('#login').val();
  32. var password = $('#password').val();
  33.  
  34. /**
  35. finds a user within with the values from input fields
  36. inside the collection
  37. */
  38. if (login && password) {
  39. this.collection.fetch({
  40. data: {
  41. login: login,
  42. password: password
  43. }
  44. });
  45. }
  46. }
  47. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement