Blame view

client/controllers/public/reset-password.coffee 1.42 KB
d1f4dbea8   Ryan Glover   Additional README...
1
  ###
5f6f6fbb0   Ryan Glover   Clean up spacing....
2
3
    Controller: Reset Password
    Template: /client/views/public/reset-password.html
d1f4dbea8   Ryan Glover   Additional README...
4
5
6
7
  ###
  
  # Created
  Template.resetPassword.created = ->
5f6f6fbb0   Ryan Glover   Clean up spacing....
8
    # Code to run when template is created goes here.
d1f4dbea8   Ryan Glover   Additional README...
9
10
11
  
  # Rendered
  Template.resetPassword.rendered = ->
aa2061a70   Ryan Glover   Add jQuery Valida...
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
    $('#application-reset-password').validate(
      rules:
        newPassword:
          required: true
          minlength: 6
        repeatNewPassword:
          required: true
          minlength: 6
          equalTo: "[name='newPassword']"
      messages:
        newPassword:
          required: "Please enter a new password."
          minlength: "Please use at least six characters."
        repeatNewPassword:
          required: "Please repeat your new password."
          equalTo: "Your password do not match. Please try again."
      submitHandler: ->
        # Grab the user's reset token and new password.
        token    = Session.get 'resetPasswordToken'
        password =
          newPassword: $('[name="newPassword"]').val()
          repeatPassword: $('[name="repeatNewPassword"]').val()
  
        # Reset the user's password.
        Accounts.resetPassword(token, password.newPassword, (error)->
          if error
            alert error.reason
          else
            Session.set 'resetPasswordToken', null
        )
    )
d1f4dbea8   Ryan Glover   Additional README...
43
44
45
  
  # Helpers
  Template.resetPassword.helpers(
5f6f6fbb0   Ryan Glover   Clean up spacing....
46
47
    example: ->
      # Code to run for helper function.
d1f4dbea8   Ryan Glover   Additional README...
48
49
50
51
  )
  
  # Events
  Template.resetPassword.events(
aa2061a70   Ryan Glover   Add jQuery Valida...
52
    'submit form': (e) ->
2cfb4bd0e   Ryan Glover   Add password reco...
53
54
      # Prevent form from submitting.
      e.preventDefault()
d1f4dbea8   Ryan Glover   Additional README...
55
  )