mirror of
https://github.com/HackPlan/RootPanel.git
synced 2026-04-22 19:03:34 +08:00
Merge branch 'master' of https://github.com/jysperm/RootPanel
This commit is contained in:
60
core/static/script/user/signup.coffee
Normal file
60
core/static/script/user/signup.coffee
Normal file
@@ -0,0 +1,60 @@
|
||||
$ ->
|
||||
username = $('#username').val()
|
||||
email = $('#email').val()
|
||||
passwd = $('#passwd').val()
|
||||
passwd2 = $('#passwd2').val()
|
||||
|
||||
|
||||
checkAndRequest = (tag, obj) ->
|
||||
form = $(tag)
|
||||
data = {}
|
||||
error = false
|
||||
$('#page-alert').show()
|
||||
|
||||
for k, v of obj
|
||||
console.log k
|
||||
item = form.find "##{k}"
|
||||
|
||||
formGroup = item.closest '.form-group'
|
||||
method = v['check']
|
||||
result = switch typeof method
|
||||
when "object" then method.test item.val()
|
||||
when "function" then method()
|
||||
when "string"
|
||||
method is ''
|
||||
else throw "form check >obj >#{k} error"
|
||||
console.log formGroup
|
||||
if result
|
||||
formGroup.addClass 'has-success'
|
||||
data[k] = item.val()
|
||||
else
|
||||
formGroup.addClass 'has-error'
|
||||
$('#page-alert').append "<p>#{v['error']}</p>"
|
||||
error = true
|
||||
if not error
|
||||
$('#page-alert').hide()
|
||||
|
||||
$.ajax
|
||||
url: '/user/signup'
|
||||
method: 'post'
|
||||
data: data
|
||||
success: (reply) ->
|
||||
console.log reply
|
||||
|
||||
|
||||
$('.signup-form').find('button').on 'click',(e)->
|
||||
e.preventDefault()
|
||||
checkAndRequest '.signup-form',
|
||||
username:
|
||||
check: /^[0-9a-z_]+$/
|
||||
error: '用户名必须以数字或小写字母开头'
|
||||
email:
|
||||
check: /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
|
||||
error: '邮箱格式不正确'
|
||||
passwd:
|
||||
check: ->
|
||||
$('#passwd').val() is $('#passwd2').val()
|
||||
error: '两次密码不一致'
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,9 @@ body {
|
||||
font-family: "WenQuanYi Micro Hei", "WenQuanYi Zen Hei", "Microsoft YaHei", arial, sans-serif;
|
||||
font-size: 16px;
|
||||
|
||||
#page-alert {
|
||||
display: none;
|
||||
}
|
||||
>header {
|
||||
background: #563d7c;
|
||||
|
||||
|
||||
@@ -29,6 +29,8 @@ html
|
||||
#content.container
|
||||
.row
|
||||
.col-md-9
|
||||
.alert#page-alert
|
||||
button(type='button',class='close') ×
|
||||
block main
|
||||
|
||||
#sidebar.col-md-3
|
||||
@@ -41,3 +43,5 @@ html
|
||||
script(src='http://cdn.staticfile.org/jquery/2.0.3/jquery.min.js')
|
||||
script(src='http://cdn.staticfile.org/twitter-bootstrap/3.0.0-rc2/js/bootstrap.min.js')
|
||||
script(src='/script/layout.js')
|
||||
|
||||
block script
|
||||
|
||||
@@ -5,7 +5,7 @@ prepend head
|
||||
|
||||
block main
|
||||
header= t('word.signup')
|
||||
form.form-horizontal(method='post', role='form')
|
||||
form.form-horizontal.signup-form(method='post', role='form')
|
||||
.form-group
|
||||
label.col-sm-2.col-md-offset-1.control-label(for='username')= t('word.username')
|
||||
.col-sm-5
|
||||
@@ -30,3 +30,6 @@ prepend sidebar
|
||||
.row
|
||||
header= t('view.signup.alreadySignup')
|
||||
a.btn.btn-lg.btn-success(href='/user/login/')= t('word.login')
|
||||
|
||||
append script
|
||||
script(src='/script/user/signup.js')
|
||||
|
||||
Reference in New Issue
Block a user