Blame view

client/controllers/public/login.js 1.34 KB
3b214be5e   Ryan Glover   Convert all Coffe...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
46
47
  /*
  * Controller: Login
  * Template: /client/views/public/login.html
  */
  
  /*
  * Created
  */
  
  Template.login.created = function(){
    // Code to run when template is created goes here.
  }
  
  /*
  * Rendered
  */
  
  Template.login.rendered = function(){
    $('#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...
48
49
50
            Bert.alert(error.reason, 'danger');
          } else {
            Bert.alert('Logged in!', 'success');
3b214be5e   Ryan Glover   Convert all Coffe...
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
          }
        });
      }
    });
  }
  
  /*
  * 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();
    }
  });