summaryrefslogtreecommitdiff
path: root/users/app/assets/javascripts/users.js.coffee
blob: ab437f6aef0585fa53d3cca20be1503a9ffcdf35 (plain)
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
preventDefault = (event) ->
  event.preventDefault()

validOrAbort = (event) ->
  errors = {}
  
  abortIfErrors = ->
    return if $.isEmptyObject(errors)
    # we're relying on client_side_validations here instead of printing
    # our own errors. This gets us translatable error messages.
    $('.control-group.error input, .control-group.error select, control-group.error textarea').first().focus()
    event.stopImmediatePropagation()
    
  validatePassword = ->
    password = $('#srp_password').val()
    confirmation = $('#srp_password_confirmation').val()
    login = $('#srp_username').val()
  
    if password != confirmation
      errors.password_confirmation = "Confirmation does not match!"
    if password == login
      errors.password = "Password and Login may not match!"
    if password.length < 8
      errors.password = "Password needs to be at least 8 characters long!"

  validatePassword()
  abortIfErrors()
  
  
signup = (event) ->
  srp = new SRP(jqueryRest())
  srp.register ->
    window.location = '/'

login = (event) ->
  srp = new SRP(jqueryRest())
  srp.identify ->
    window.location = '/'


$(document).ready ->
  $('#new_user').submit preventDefault
  $('#new_user').submit validOrAbort
  $('#new_user').submit signup
  $('#new_session').submit preventDefault
  $('#new_session').submit login