异步验证注册字段合法
This commit is contained in:
parent
4d8701220b
commit
19ddb38e1b
|
@ -172,6 +172,33 @@ class AccountController < ApplicationController
|
|||
redirect_to signin_path
|
||||
end
|
||||
|
||||
def valid_ajax
|
||||
req = Hash.new(false)
|
||||
req[:message] = ''
|
||||
|
||||
valid_attr = params[:valid]
|
||||
valid_value = params[:value]
|
||||
|
||||
faker = User.new
|
||||
|
||||
if valid_attr.eql?('login')
|
||||
faker.login = valid_value
|
||||
faker.valid?
|
||||
req[:valid] = faker.errors[:login].blank?
|
||||
req[:message] = faker.errors[:login]
|
||||
end
|
||||
|
||||
if valid_attr.eql?('mail')
|
||||
faker.mail = valid_value
|
||||
faker.valid?
|
||||
req[:valid] = faker.errors[:mail].blank?
|
||||
req[:message] = faker.errors[:mail]
|
||||
end
|
||||
|
||||
req[:message] = l(:modal_valid_passing) if req[:message].blank?
|
||||
render :json => req
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def authenticate_user
|
||||
|
|
|
@ -278,7 +278,7 @@
|
|||
|
||||
|
||||
<% if @user.auth_source_id.nil? %>
|
||||
<p><%= f.text_field :login, :size => 25, :required => true %>
|
||||
<p><%= f.text_field :login, :size => 25, :required => true %><span id="valid_user_login"></span>
|
||||
<em class="info"><%= l(:label_max_number) %></em></p>
|
||||
<p><%= f.password_field :password, :size => 25, :required => true %>
|
||||
<em class="info"><%= l(:text_caracters_minimum, :count => Setting.password_min_length) %></em></p>
|
||||
|
@ -294,7 +294,7 @@
|
|||
<td class="info" style="width: 10px">
|
||||
<%= text_field_tag :enterprise_name %></td></tr></table></p>
|
||||
</span>
|
||||
<p><%= f.text_field :mail, :required => true %></p>
|
||||
<p><%= f.text_field :mail, :required => true %><span id="valid_user_mail"></span></p>
|
||||
<p>
|
||||
<em class="info"><%="#{l(:label_mail_attention)} "%></em></p>
|
||||
<p><%= f.select :language, lang_options_for_select , :required => true %></p>
|
||||
|
@ -368,3 +368,36 @@
|
|||
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
var $login = $('#user_login')
|
||||
var $mail = $('#user_mail')
|
||||
|
||||
jQuery(document).ready(function() {
|
||||
$login.blur(function(event) {
|
||||
var $parent = $(this).parent();
|
||||
if ( $(this).is('#user_login')) {
|
||||
$.get('<%=account_valid_ajax_path%>?valid=login&value='+this.value, function(data) {
|
||||
if (data.valid) {
|
||||
$('#valid_user_login').html('<span class="green">'+data.message+"</span>");
|
||||
}else{
|
||||
$('#valid_user_login').html('<span class="red">'+data.message+"</span>");
|
||||
}
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
$mail.blur(function(event) {
|
||||
var $parent = $(this).parent();
|
||||
if ( $(this).is('#user_mail')) {
|
||||
$.get('<%=account_valid_ajax_path%>?valid=mail&value='+this.value, function(data) {
|
||||
if (data.valid) {
|
||||
$('#valid_user_mail').html('<span class="green">'+data.message+"</span>");
|
||||
}else{
|
||||
$('#valid_user_mail').html('<span class="red">'+data.message+"</span>");
|
||||
}
|
||||
});
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
|
@ -1603,3 +1603,5 @@ en:
|
|||
label_activity_time: publish date
|
||||
|
||||
|
||||
# ajax异步验证
|
||||
modal_valid_passing: can be used.
|
|
@ -1886,3 +1886,6 @@ zh:
|
|||
label_contest_settings: 配置竞赛
|
||||
label_contest_delete: 删除竞赛
|
||||
|
||||
# ajax异步验证
|
||||
modal_valid_passing: 可以使用
|
||||
|
|
@ -126,6 +126,7 @@ RedmineApp::Application.routes.draw do
|
|||
match 'account/register', :to => 'account#register', :via => [:get, :post], :as => 'register'
|
||||
match 'account/lost_password', :to => 'account#lost_password', :via => [:get, :post], :as => 'lost_password'
|
||||
match 'account/activate', :to => 'account#activate', :via => :get
|
||||
match 'account/valid_ajax', :to => 'account#valid_ajax', :via => :get
|
||||
|
||||
match '/news/preview', :controller => 'previews', :action => 'news', :as => 'preview_news', :via => [:get, :post, :put]
|
||||
match '/issues/preview/new/:project_id', :to => 'previews#issue', :as => 'preview_new_issue', :via => [:get, :post, :put]
|
||||
|
|
|
@ -1,5 +1,14 @@
|
|||
/* TODO: base/common/page 准备封装一些基本样式组合调用 参考YUI
|
||||
*******************************************************************************/
|
||||
span[id^=valid_user]{
|
||||
padding-left: 10px;
|
||||
}
|
||||
.red{
|
||||
color: red;
|
||||
}
|
||||
.green{
|
||||
color: green;
|
||||
}
|
||||
.border_box {
|
||||
-webkit-box-sizing: border-box;
|
||||
-moz-box-sizing: border-box;
|
||||
|
|
Loading…
Reference in New Issue