2018-11-29 13:47:49 +00:00
|
|
|
# libs
|
|
|
|
window.$ = require('jquery')
|
|
|
|
|
|
|
|
# on load
|
|
|
|
$ ->
|
|
|
|
# style sheet
|
|
|
|
require './style/custom.scss'
|
|
|
|
|
2018-12-16 01:38:43 +00:00
|
|
|
# reset forms
|
|
|
|
$('form').each ->
|
|
|
|
that = @
|
2018-12-16 02:19:27 +00:00
|
|
|
|
2018-12-16 01:38:43 +00:00
|
|
|
@fullReset = ->
|
|
|
|
$('input', that).each ->
|
|
|
|
$(that).removeClass 'is-invalid'
|
|
|
|
$(that).removeClass 'is-valid'
|
|
|
|
that.reset()
|
2018-12-13 16:07:58 +00:00
|
|
|
|
|
|
|
# login form
|
2018-12-16 02:19:27 +00:00
|
|
|
$('form[name="login"]').submit (event) ->
|
2018-12-16 01:38:43 +00:00
|
|
|
# inhibit normal form submission
|
|
|
|
event.preventDefault()
|
|
|
|
|
2018-12-13 16:07:58 +00:00
|
|
|
# gather form data
|
2018-12-16 01:38:43 +00:00
|
|
|
login = $('input[name="login"]', @)
|
2018-12-13 16:07:58 +00:00
|
|
|
password = $('input[name="password"]', @)
|
|
|
|
|
|
|
|
# transmit form data
|
2018-12-16 01:40:01 +00:00
|
|
|
$.post '/login',
|
|
|
|
login: login.val()
|
|
|
|
password: password.val()
|
|
|
|
.done (data) ->
|
|
|
|
alert "#{data.status}, #{data.uid}, #{data.text}"
|
2018-12-13 16:07:58 +00:00
|
|
|
|
|
|
|
# reset form
|
2018-12-16 01:38:43 +00:00
|
|
|
@fullReset()
|
2018-12-13 16:07:58 +00:00
|
|
|
|
2018-12-16 02:19:27 +00:00
|
|
|
# registration form
|
2018-12-16 01:38:43 +00:00
|
|
|
$('form[name="register"]').submit (event) ->
|
|
|
|
# inhibit normal form submission
|
|
|
|
event.preventDefault()
|
|
|
|
|
2018-12-13 16:07:58 +00:00
|
|
|
# gather form data
|
2018-12-16 01:38:43 +00:00
|
|
|
login = $('input[name="login"]', @)
|
2018-12-13 16:07:58 +00:00
|
|
|
password = $('input[name="password"]', @)
|
|
|
|
confirm = $('input[name="confirm"]', @)
|
|
|
|
|
|
|
|
# check form data
|
|
|
|
if password.val() == confirm.val()
|
|
|
|
|
|
|
|
# transmit form data
|
2018-12-16 01:40:01 +00:00
|
|
|
$.post '/register',
|
|
|
|
login: login.val()
|
|
|
|
password: password.val()
|
|
|
|
.done (data) ->
|
|
|
|
alert "#{data.status}, #{data.uid}, #{data.text}"
|
2018-12-13 16:07:58 +00:00
|
|
|
|
|
|
|
# reset form
|
2018-12-16 01:38:43 +00:00
|
|
|
@fullReset()
|
2018-12-13 16:07:58 +00:00
|
|
|
|
|
|
|
else
|
|
|
|
confirm.val ''
|
|
|
|
confirm.addClass 'is-invalid'
|
|
|
|
confirm.focus()
|