-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathreset.coffee
More file actions
53 lines (40 loc) · 1.21 KB
/
reset.coffee
File metadata and controls
53 lines (40 loc) · 1.21 KB
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
48
49
50
51
52
53
Serializer = require '../../../components/form/serializer.coffee'
{ track } = require '../../../lib/analytics.coffee'
module.exports = (token) ->
$el = $('.js-authentication')
$form = $el.find '.js-form'
$submit = $el.find '.js-submit'
$errors = $el.find '.js-errors'
label = $submit.text()
$form.on 'submit', (e) ->
e.preventDefault()
serializer = new Serializer $form
$submit
.prop 'disabled', true
.text 'Resetting...'
$.ajax
url: $form.attr 'action'
method: $form.attr 'method'
data: serializer.data()
success: ->
$errors.replaceWith $ """
<div class='Success'>
Password successfully reset.
<a href='/log_in'>Click here to login.</a>
</div>
"""
$submit
.prop 'disabled', true
.text 'Reset'
track.submit 'User successfully reset password'
error: ({ responseJSON: { description }}) ->
$errors.show()
.text description
$submit
.prop 'disabled', false
.text 'Try again'
setTimeout ->
$submit.text label
$errors.empty()
, 5000
track.error 'User reset password error'