Blame view

client/templates/public/login.js 1.35 KB
3b214be5e   Ryan Glover   Convert all Coffe...
1
2
3
4
5
6
7
8
  /*
  * Controller: Login
  * Template: /client/views/public/login.html
  */
  
  /*
  * Created
  */
76b8987a6   Ryan Glover   Update created an...
9
  Template.login.onCreated(function(){
3b214be5e   Ryan Glover   Convert all Coffe...
10
    // Code to run when template is created goes here.
76b8987a6   Ryan Glover   Update created an...
11
  });
3b214be5e   Ryan Glover   Convert all Coffe...
12
13
14
15
  
  /*
  * Rendered
  */
76b8987a6   Ryan Glover   Update created an...
16
  Template.login.onRendered(function(){
3b214be5e   Ryan Glover   Convert all Coffe...
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
    $('#application-login').validate({
      rules: {
        emailAddress: {
          required: true,
          email: true
        },
        password: {
          required: true
        }
      },
      messages: {
        emailAddress: {
          required: "Please enter your email address to login.",
          email: "Please enter a valid email address."
        },
        password: {
          required: "Please enter your password to login."
        }
      },
      submitHandler: function(){
        // Grab the user's details.
        user = {
          email: $('[name="emailAddress"]').val(),
          password: $('[name="password"]').val()
        }
  
        // Log the user in.
        Meteor.loginWithPassword(user.email, user.password, function(error){
          if(error){
c8b07469e   Ryan Glover   Add themeteorchef...
46
47
48
            Bert.alert(error.reason, 'danger');
          } else {
            Bert.alert('Logged in!', 'success');
3b214be5e   Ryan Glover   Convert all Coffe...
49
50
51
52
          }
        });
      }
    });
76b8987a6   Ryan Glover   Update created an...
53
  });
3b214be5e   Ryan Glover   Convert all Coffe...
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
  
  /*
  * Helpers
  */
  
  Template.login.helpers({
    example: function(){
      // Code to run for helper function.
    }
  });
  
  /*
  * Events
  */
  
  Template.login.events({
    'submit form': function(e){
      // Prevent form from submitting.
      e.preventDefault();
    }
  });