diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index 27a6f564..7be3e8e3 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -436,7 +436,15 @@ class AccountController < ApplicationController # 注册完/绑定邮箱 后完善资料 def user_info @user = User.current + + #是否是Oschina过来的 + @is_ecoder_user = @user.ecoder_user_id.to_i>0 + + #是否没设置过密码 + @is_set_password = @user.hashed_password.present? + if request.get? + # 如果是登录的请求进来,则需要判断登录名是否合法 if (@user.login =~ /(^(?=.*?[a-zA-Z]).*$)/).nil? || !(@user.login =~ /[@#\$%\^&\*\.]+/).nil? @login_error = true @@ -454,6 +462,22 @@ class AccountController < ApplicationController apply_user.update_all(:status => 2) unless apply_user.blank? end + + if @is_ecoder_user && !@is_set_password + @user.password = params[:new_password] + @user.password_confirmation = params[:new_password_confirmation] + + if @user.password.size<8 + @password_len_error = true + render :user_info and return + end + + if @user.password != @user.password_confirmation + @password_match_error = true + render :user_info and return + end + end + @user.lastname = params[:lastname] @user.firstname = "" @user.show_realname = params[:hide_realname] ? 0 : 1 @@ -525,6 +549,7 @@ class AccountController < ApplicationController return else @user.login = lg + logger.info "save user: #{@user.errors}" end end end diff --git a/app/controllers/ecloud_controller.rb b/app/controllers/ecloud_controller.rb index 216df8df..a64fce66 100644 --- a/app/controllers/ecloud_controller.rb +++ b/app/controllers/ecloud_controller.rb @@ -38,8 +38,6 @@ class EcloudController < ApplicationController ROOT_URl = 'http://localhost:3000' SERVER_URL = "https://221.176.54.92:9081/restful/services/" - - ## 签名 def sign(timestamp) Digest::MD5.hexdigest("client_id=#{CLIENT_ID}client_key=#{CLIENT_SECRET}timestamp=#{timestamp}").upcase @@ -174,39 +172,53 @@ class EcloudController < ApplicationController end def ecloud_login_callback - #获取code - logger.info "oauth2 login_callback: #{params}" - raise "没有code" unless params[:code] + unless params["test"] == 'true' + #获取code + logger.info "oauth2 login_callback: #{params}" - url = "#{SERVER_URL}/oauth2/authorization?grant_type=authorization_code" + - "&client_id=#{CLIENT_ID}&scope=&redirect_uri=&code=#{params[:code]}" + raise "没有code" unless params[:code] - res = post(url) - logger.info "oauth2 authorization resp: #{res}" + url = "#{SERVER_URL}/oauth2/authorization?grant_type=authorization_code" + + "&client_id=#{CLIENT_ID}&scope=&redirect_uri=&code=#{params[:code]}" - body = decode(res) - #{"access_token":"21a80f20ff736b54aecd002b60210943","token_type":"bearer","expires_in":86400,"refresh_token":"be92e2c137a8c6dd22f0d8c4a622b3aeceb054087a95d293130f04ec60fd3e3f","scope":"user_info","created_at":1542684088} + res = post(url) + logger.info "oauth2 authorization resp: #{res}" + # {"access_token":"ae673b2d-88b4-46cc-aa74-0b031f24b76f","expires":6,"refresh_token":"7380cc67-a59c-4c21-9000-70e12a58d175","username":"15111030087@QW_er","uid":2147} - raise '登录失败' unless body["access_token"] + body = decode(res) - #获取此用户信息 + raise '登录失败' unless body["access_token"] + + #获取此用户信息 + res = get("#{SERVER_URL}/user/info?access_token=#{body['access_token']}&userid=#{body['uid']}") + logger.info "oauth2 get user info: #{res}" + # {"userid":2147,"custid":2104,"custcode":"E0002018042810010054","custtype":2,"status":2,"username":"15111030087@QW_er","useralias":"15111030087","isadmin":true,"entprise":"04**004","departments":"","departmentnames":"","mobile":"15365386520","email":"15111030087@139.com"} + else + res = '{"userid":2147,"custid":2104,"custcode":"E0002018042810010054","custtype":2,"status":2,"username":"15111030087@QW_er","useralias":"15111030087","isadmin":true,"entprise":"04**004","departments":"","departmentnames":"","mobile":"15365386520","email":"15111030087@139.com"}' + end - # res = get("https://gitee.com/api/v5/user?access_token=#{body["access_token"]}") - res = get("#{SERVER_URL}/user/info?access_token=#{body['access_token']}&userid=#{body['uid']}") - logger.info "oauth2 get user info: #{res}" # 同步用户 - # info = decode(res) - # - # user = User.find_by_oschina_user_id(info["id"]) - # unless user - # user = User.create_with_oschina!(info) - # end - # - # @current_user = user - - render :index + info = decode(res) + + user = User.find_by_ecoder_user_id(info["userid"]) + unless user + #新建用户 + user = User.create_with_ecoder!(info) + end + + self.logged_user = user + + user = UserExtensions.where(:user_id => User.current.id).first + if user.gender.nil? || user.school_id.nil? || User.current.lastname.nil? + redirect_to my_account_path + elsif user.identity == 3 && user.school_id.nil? + redirect_to my_account_path + else + redirect_to User.current + end + end diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index ecb62c18..54cd15d6 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -141,6 +141,10 @@ class MyController < ApplicationController # Edit user's account def account @user = params[:user_id].nil? ? User.current : User.find(params[:user_id]) + + + + ue = @user.user_extensions if @user.lastname.blank? || ue.try(:identity).nil? || (ue.try(:identity) == 1 && ue.try(:student_id).blank?) || (ue.try(:identity) != 1 && ue.try(:technical_title).blank?) || ue.try(:gender).blank? || ue.try(:school_id).blank? redirect_to user_info_path @@ -152,7 +156,8 @@ class MyController < ApplicationController applied_message = AppliedMessage.where(:id => params[:applied_message_id]).first applied_message.update_attribute(:viewed, true) end - # @user = User.current + + # 认证 @trail_authentication = ApplyAction.where(:user_id => User.current.id, :container_type => "TrialAuthorization").order("created_at desc").first if @trail_authentication && (@trail_authentication.status == 1 || @trail_authentication.status == 2) && !@trail_authentication.noticed diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index e44a170b..2a4402b7 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -2592,6 +2592,7 @@ class UsersController < ApplicationController def user_info + end # 连续签到六天则每天累加10个金币 diff --git a/app/models/user.rb b/app/models/user.rb index af689317..fdb9566a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1692,6 +1692,36 @@ class User < Principal end end + def self.create_with_ecoder!(info) + user = User.new + user.admin = false + user.login = "ecoder_" + info["mobile"] + + user.phone = info["mobile"] + + unless User.find_by_mail(info["email"]) + user.mail = info["email"] + end + user.nickname = info["username"] + + + user.activate + user.last_login_on = Time.now + + user.ecoder_user_id = info["userid"] + + user.save!(:validate => false) + + + UserStatus.create!(:user_id => user.id, :changsets_count => 0, :watchers_count => 0) + + ue = user.user_extensions ||= UserExtensions.new + ue.user_id = user.id + ue.save! + + user + end + end class AnonymousUser < User diff --git a/app/services/games_service.rb b/app/services/games_service.rb index 039d90c8..c87c0e0e 100644 --- a/app/services/games_service.rb +++ b/app/services/games_service.rb @@ -88,15 +88,20 @@ class GamesService # tpm_script_modified = (shixun.reset_time > myshixun.reset_time ? true : false) # 新结构脚本是实时传送的,所以不会影响 # 区分评测过未评测过,未评测过按需求取数据 - if max_query_index > 0 - qurey_test_sets = TestSet.find_by_sql("SELECT o.actual_output, o.out_put, o.result, o.test_set_position, o.query_index,t.is_public,t.input, t.output, g.id as game_id, c.id as challenge_id FROM outputs o,games g ,challenges c,test_sets t where - g.id=#{game.id} and o.query_index=#{max_query_index} and g.id = o.game_id and c.id= g.challenge_id and t.challenge_id = c.id and t.position =o.test_set_position order by o.query_index - ") - else - qurey_test_sets = TestSet.find_by_sql("SELECT t.is_public,t.input, t.output,t.position FROM games g ,challenges c,test_sets t where - g.id=#{game.id} and c.id= g.challenge_id and t.challenge_id = c.id - ") - end + sql = + if max_query_index > 0 + "SELECT o.actual_output, o.out_put, o.result, o.test_set_position, o.query_index,t.is_public,t.input, + t.output, g.id as game_id, c.id as challenge_id + FROM test_sets t, outputs o,games g ,challenges c + WHERE g.id=#{game.id} and o.query_index=#{max_query_index} and g.id = o.game_id and c.id= g.challenge_id + and t.challenge_id = c.id and t.position =o.test_set_position + ORDER BY o.query_index" + else + "SELECT t.is_public,t.input, t.output, t.position + FROM games g ,challenges c,test_sets t + WHERE g.id=#{game.id} and c.id= g.challenge_id and t.challenge_id = c.id" + end + qurey_test_sets = TestSet.find_by_sql(sql) # 测试集统计及处理 unless qurey_test_sets.blank? diff --git a/app/views/account/user_info.html.erb b/app/views/account/user_info.html.erb index 5bc5fa6b..0987f8c3 100644 --- a/app/views/account/user_info.html.erb +++ b/app/views/account/user_info.html.erb @@ -39,6 +39,20 @@ <% end %> + + <% if @is_ecoder_user && !@is_set_password %> +
  • + + +

    密码最小长度为8位

    +
  • +
  • + + +

    两次密码不匹配

    +
  • + <% end %> +
  • diff --git a/db/migrate/20190313090911_add_ecoder_user_id_to_users.rb b/db/migrate/20190313090911_add_ecoder_user_id_to_users.rb new file mode 100644 index 00000000..0145ebe8 --- /dev/null +++ b/db/migrate/20190313090911_add_ecoder_user_id_to_users.rb @@ -0,0 +1,6 @@ +class AddEcoderUserIdToUsers < ActiveRecord::Migration + def change + add_column :users, :ecoder_user_id, :integer, default: 0 + add_index :users, :ecoder_user_id + end +end diff --git a/db/migrate/20190314025104_migration_shixun_student_work.rb b/db/migrate/20190314025104_migration_shixun_student_work.rb index c74b7379..c6bd65a4 100644 --- a/db/migrate/20190314025104_migration_shixun_student_work.rb +++ b/db/migrate/20190314025104_migration_shixun_student_work.rb @@ -1,26 +1,71 @@ class MigrationShixunStudentWork < ActiveRecord::Migration def up - works = StudentWork.where("myshixun_id != 0 and myshixun_id not in (select id from myshixuns) and (work_score is null or work_score = 0)") - works.update_all(:myshixun_id => 0, :work_status => 0, :work_score => nil, :final_score => nil, - :cost_time => 0, :update_time => nil, :compelete_status => 0, :commit_time => nil) + ActiveRecord::Base.transaction do + begin + works = StudentWork.where("myshixun_id != 0 and myshixun_id not in (select id from myshixuns) and (work_score is null or work_score = 0)") + works.update_all(:myshixun_id => 0, :work_status => 0, :work_score => nil, :final_score => nil, + :cost_time => 0, :update_time => nil, :compelete_status => 0, :commit_time => nil) - shixun_works = StudentWork.where("myshixun_id != 0 and myshixun_id not in (select id from myshixuns) and work_score > 0") - shixun_works.each do |work| - if work.homework_common && work.homework_common.homework_commons_shixuns.try(:shixun) - shixun = work.homework_common.homework_commons_shixuns.try(:shixun) + shixun_works = StudentWork.where("myshixun_id != 0 and myshixun_id not in (select id from myshixuns) and work_score > 0") + shixun_works.each do |work| + shixun = work.homework_common.try(:homework_commons_shixuns).try(:shixun) + user = work.user + if shixun.present? && user.present? + # 创建新的myshixun和games + # fork版本库,如果用户没有同步,则先同步用户 + g = Gitlab.client + if user.gid.nil? + s = Trustie::Gitlab::Sync.new + s.sync_user(user) + end + gshixun = g.fork(shixun.gpid, user.gid) + shixun_tomcat = Redmine::Configuration['shixun_tomcat'] + code = down_generate_identifier("myshixun") + # 一般通过默认分支是否存在来判断一个项目是否fork成功 + if gshixun.try(:id).present? + commit_id = g.commits(shixun.gpid).first.try(:id) + # educoder 加入到myshixun中 + myshixun_admin_gid = User.where(:login => "educoder").first.try(:gid) + g.add_team_member(gshixun.id, myshixun_admin_gid, 40) # 40代表角色master - # 创建新的myshixun和games - myshixun = nil + myshixun = Myshixun.create!(:shixun_id => shixun.id, :user_id => user.id, :identifier => code, + :modify_time => shixun.modify_time, :reset_time => shixun.reset_time, + :onclick_time => Time.now, :gpid => gshixun.id, + :git_url => gshixun.try(:path_with_namespace), :commit_id => commit_id) - work_score = work.final_score - work.homework_common.homework_challenge_settings.each do |setting| - if work_score > 1 - myshixun.games.where(:challenge_id => setting.challenge_id).first.update_attributes(:status => 2) - work_score -= setting.score + rep_url = Base64.urlsafe_encode64(gitlab_url shixun) # 注意:educoder为默认给实训创建版本库的用户,如果换成别的用户,名字要相应的修改 + uri = "#{shixun_tomcat}/bridge/game/openGameInstance" + params = {tpiID: "#{myshixun.id}", tpmGitURL:rep_url, tpiRepoName: gshixun.try(:name)} + logger.info("openGameInstance params is #{params}") + res = uri_exec uri, params + if (res && res['code'].to_i != 0) + raise("实训云平台繁忙(繁忙等级:83)") + end + # 其它创建关卡等操作 + challenges = shixun.challenges + # 之所以增加user_id是为了方便统计查询性能 + challenges.each_with_index do |challenge, index| + status = (index == 0 ? 0 : 3) + code = down_generate_identifier("game") + Game.create!(:challenge_id => challenge.id, :myshixun_id => myshixun.id, :status => status, :user_id => myshixun.user_id, + :open_time => Time.now, :identifier => code, :modify_time => challenge.modify_time) + end + work_score = work.final_score + work.homework_common.homework_challenge_settings.each do |setting| + if work_score > 1 + games = myshixun.games.where(:challenge_id => setting.challenge_id).first + games.update_attributes(:status => 2, :end_time => Time.now, :final_score => setting.challenge.score) + work_score -= setting.score + end + end + work.update_column("myshixun_id", myshixun.id) + end end end - - work.update_column("myshixun_id", myshixun.id) + rescue Exception => e + puts ("###failed to exec shixun: current task id is #{e}") + g.delete_project(gshixun.id) if gshixun.try(:id).present? + raise ActiveRecord::Rollback end end end diff --git a/nano.save b/nano.save deleted file mode 100644 index 6fb66a5e..00000000 --- a/nano.save +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/public/javascripts/edu/account.js b/public/javascripts/edu/account.js index 53d8e24e..a3abf432 100644 --- a/public/javascripts/edu/account.js +++ b/public/javascripts/edu/account.js @@ -152,7 +152,7 @@ function changeDepValue(value, data) { // 基本资料页面提交表单时,判断身份与单位是否合法 function my_account_form_submit() { - if ($("#nickname").val().trim() == '') { + if ($("#nickname").val().trim() === "") { $("#nickname").focus(); $("#nickname_hint").show(); e.stopImmediatePropagation(); @@ -161,6 +161,8 @@ function my_account_form_submit() { $("#nickname_hint").hide(); } + + //姓名不能为空 if ($("#lastname").val().trim() == '') { $("#lastname").focus(); diff --git a/public/javascripts/educoder/edu_account.js b/public/javascripts/educoder/edu_account.js index 36ac832c..89086802 100644 --- a/public/javascripts/educoder/edu_account.js +++ b/public/javascripts/educoder/edu_account.js @@ -1,1998 +1,2009 @@ -$(function(){ - //注册系页面 - resizeReg(); - //登录切换方式 - $(".log_nav li").click(function(){ - $(".log_nav li").removeClass("active"); - $(this).addClass("active"); - var index=parseInt($(this).index())+1; - $(".login-panel").hide(); - $("#login-panel-"+index).show(); - if(index == 2 && IsPC()){ - $("#quick-drag").drag(); - }else{ - $("#quick-drag").empty(); - } - }); - - //注册--初始化滑动验证 - if($("#reg-drag").length>0 && IsPC()){ - $("#reg-drag").drag(); - }else{ - $("#reg-drag").empty(); - } - - //找回密码--初始化滑动验证 - if($("#lost-drag").length>0 && IsPC()){ - $("#lost-drag").drag(); - }else{ - $("#lost-drag").empty(); - } - - $("#findType").click(function(){ - var type=$(this).attr("type"); - if(type == "email"){ - $(this).attr("type","phone"); - $("#lost_phone").addClass("none"); - $("#lost_email").removeClass("none"); - $(this).html("通过手机号码找回"); - }else{ - $(this).attr("type","email"); - $("#lost_phone").removeClass("none"); - $("#lost_email").addClass("none"); - $(this).html("通过邮箱找回"); - } - $("#lost_phone").val(""); - $("#lost_email").val(""); - $('#lost-drag').empty(); - $('#lost-drag').drag(); - $("#find_phone_testcode").hide(); - $("#user_reg_verification_notice").hide(); - $("#lost_psd_input_testcode").hide(); - $("#lost_psd_ver_code").val(""); - $("#lost_psd_get_code").html("获取验证码"); - $("#lost_psd_get_code").removeClass("edu-back-blue").attr("disabled", "disabled"); - $("#lost_psd_next_a").removeClass("edu-back-blue").attr("disabled", "disabled"); - wait = 60; - clearTimeout(timer); - }); - - if(IsPC() == false){$(".drag_certi_block").hide();}//非web端打开,隐藏滚动条 - - loadProvince(); - - if($("#name_loggin_input").length > 0 && $("#name_loggin_input").val().trim() != ""){ - $("#psd_login_btn").addClass("edu-back-blue"); - $("#psd_login_btn").attr("disabled", false); - } - -}); -$(window).resize(function(){ - resizeReg(); -}) - -function resizeReg(){ - if($(".reg_pass").length>0){ - var height1=$("body").height(); - $(".reg_pass").height(height1); - } -} - -//昵称修改提交 -function submitRename(){ - if($("#newnickname").val().trim()==""){ - $("#nickname_empty_notice").removeClass("none"); - $("#newnickname").addClass("bor-red"); - }else{ - $("#nickname_empty_notice").addClass("none"); - $("#newnickname").removeClass("bor-red"); - $("#update_user_nickname_form").submit(); - hideModal(); - } -} - -//登录页面 -$(window).load(function(){ - if($("#login-panel-1").length == 0)return; - //页面加载后,输入框里面已经显示保存的用户账号和密码!有账号必定有密码(谷歌默认填充内容只能获得账号,密码为空),所以账号不为空后,密码删除按钮也要显示出来 - if($("#name_loggin_input").val().trim() != ""){ - $("#psd_login_btn").addClass("edu-back-blue"); - $("#psd_login_btn").attr("disabled", false); - } -}); -$(function() { - if($("#login-panel-1").length == 0)return; - if($("#password_loggin_input").val().trim() != ""){ - $("#psd_login_btn").addClass("edu-back-blue"); - $("#psd_login_btn").attr("disabled", false); - } - - // $("#name_loggin_input").on("input", function () { - // $("#password_error_notice").hide(); - // }); - - $("#pass_name_input").on("input", function () { - $("#send_code_notice").hide(); - }); - - $("#name_loggin_input").on("blur", function(){ - if ($(this).val().trim().length == 0){ - $(this).next().find("p").html("请输入有效的手机号/邮箱号/用户名").show(); - } else{ - $.get( - '/account/valid_ajax', - { valid: "", - value: $("#name_loggin_input").val().trim() }, - function (data) { - console.log("valid:"+data.valid); - if (data.valid) { - $("#name_loggin_input").next().find("p").html("该用户尚未注册,您可以去注册").show(); - } else { - $("#name_loggin_input").next().find("p").hide(); - } - }); - } - }); - - $("#pass_name_input").on("blur", function(){ - if (!/^1\d{10}$/.test($(this).val()) && !/^[a-zA-Z0-9]+([.\-_\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/.test($(this).val())){ - $(this).next().find("p").html("请输入有效的手机号/邮箱号").show(); - $("#get_verification_code").removeClass("edu-back-blue"); - $("#get_verification_code").attr("disabled", "disabled"); - } else{ - $(this).next().find("p").hide(); - $("#get_verification_code").addClass("edu-back-blue"); - $("#get_verification_code").attr("disabled", false); - } - }); - - $("#password_loggin_input").on('input', function(){ - // $("#password_error_notice").hide(); - if($(this).val().trim().length > 0){ - $("#psd_login_btn").addClass("edu-back-blue"); - $("#psd_login_btn").attr("disabled", false); - // $("#password_error_notice").hide(); - $("#login_error_notice").hide(); - } else{ - $("#psd_login_btn").removeClass("edu-back-blue"); - $("#psd_login_btn").attr("disabled", "disabled"); - } - }); - - $("#login_verification_code").on('input', function(){ - $("#send_code_notice").hide(); - if($(this).val().trim().length > 0){ - $("#code_login_btn").addClass("edu-back-blue"); - $("#code_login_btn").attr("disabled", false); - $("#send_code_notice").hide(); - $("#login_code_error_notice").hide(); - } else{ - $("#code_login_btn").removeClass("edu-back-blue"); - $("#code_login_btn").attr("disabled", "disabled"); - } - }); - - $("#psd_login_btn").on("click", function(){ - if($(this).attr("disabled")){ - return false; - } else{ - var result = true; - if ($("#name_loggin_input").val().trim().length == 0){ - $("#name_loggin_input").next().find("p").show(); - result = false; - } else { - $("#name_loggin_input").next().find("p").hide(); - } - if($("#password_loggin_input").val().trim().length == 0){ - $("#password_error_notice").show(); - $("#login_error_notice").hide(); - result = false; - } else{ - $("#password_error_notice").hide(); - $("#login_error_notice").hide(); - } - if(result){ - $("#main_login_form").submit(); - - /*if (/^1\d{10}$/.test($("#name_loggin_input").val())){ - $.get( - '/account/valid_ajax', - { valid: "phone", - value: $("#name_loggin_input").val().trim() }, - function (data) { - if (data.valid) { - $("#psd_none_reg").find("span").html("该手机号尚未注册,你可以去注册"); - $("#psd_none_reg").show(); - } else { - $("#psd_none_reg").hide(); - $("#main_login_form").submit(); - } - }); - } else if(/^[a-zA-Z0-9]+([.\-_\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/.test($("#name_loggin_input").val())){ - $.get( - '/account/valid_ajax', - { valid: "mail", - value: $("#name_loggin_input").val().trim() }, - function (data) { - if (data.valid) { - $("#psd_none_reg").find("span").html("该邮箱尚未绑定,你可以登录后去绑定"); - $("#psd_none_reg").show(); - } else { - $("#psd_none_reg").hide(); - $("#main_login_form").submit(); - } - }); - } else{ - $("#psd_none_reg").hide(); - $("#main_login_form").submit(); - }*/ - } - } - }); - - $("#code_login_btn").on("click", function(){ - if($(this).attr("disabled")){ - return false; - } else{ - var result = true; - if ($("#pass_name_input").val().trim().length == 0){ - $("#pass_name_input").next().find("p").html("请输入有效的手机号/邮箱号").show(); - result = false; - } else { - $("#pass_name_input").next().find("p").hide(); - } - if($("#login_verification_code").val().trim().length == 0){ - $("#send_code_notice").html("请输入验证码").show(); - result = false; - } else{ - $("#send_code_notice").hide(); - } - if(result){ - if (/^1\d{10}$/.test($("#pass_name_input").val())){ - $.get( - '/account/valid_ajax', - { valid: "phone", - value: $("#pass_name_input").val().trim() }, - function (data) { - if (data.valid) { - $("#pass_name_input").next().find("p").html("该手机号尚未注册,你可以去注册").show(); - } else { - $("#pass_name_input").next().find("p").hide(); - $("#code_login_form").submit(); - } - }); - } else if(/^[a-zA-Z0-9]+([.\-_\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/.test($("#pass_name_input").val())){ - $.get( - '/account/valid_ajax', - { valid: "mail", - value: $("#pass_name_input").val().trim() }, - function (data) { - if (data.valid) { - $("#pass_name_input").next().find("p").html("该邮箱尚未绑定,你可以登录后去绑定").show(); - } else { - $("#pass_name_input").next().find("p").hide(); - $("#code_login_form").submit(); - } - }); - } - } - } - }); -}); - -function user_login_keypress(e){ - if (e.keyCode == '13') { - $('#main_login_form').submit(); - } -} - -function user_login_code_keypress(e){ - if (e.keyCode == '13') { - $('#code_login_form').submit(); - } -} - -function get_login_verification_code(btn) { - if($(btn).attr("disabled")) { - return false; - } else { - if (/^1\d{10}$/.test($("#pass_name_input").val()) || /^[a-zA-Z0-9]+([.\-_\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/.test($("#pass_name_input").val())){ - if(!IsPC() || $('#quick-drag .drag_text').html() == "验证通过") { - $("#passlogin_error_notice").hide(); - btn.setAttribute("disabled", "disabled"); - var val = ''; - var type = 6; - if(/^1\d{10}$/.test($("#pass_name_input").val())){ - type = 6; - } else if(/^[a-zA-Z0-9]+([.\-_\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/.test($("#pass_name_input").val())){ - type = 7; - } - $.get( - '/account/get_verification_code', - { value: $('#pass_name_input').val().trim(), - type: type}, - function (data) { - if (data.status == "2") { - if(type == 6){ - $("#pass_name_input").next().find("p").html("该手机号尚未注册,你可以去注册").show(); - } else{ - $("#pass_name_input").next().find("p").html("该邮箱尚未绑定,你可以登录后去绑定").show(); - } - } else { - $("#pass_name_input").next().find("p").hide(); - $('#send_code_notice').removeClass("color-orange"); - if(type == 6){ - if(data.msg != "验证码已经发送到您的手机,请注意查收"){ - $('#send_code_notice').addClass("color-orange"); - } - $("#send_code_notice").html(data.msg).show(); - } else{ - var uurl = gotoEmail(data.link); - $("#send_code_notice").html("验证码已经发送到您的邮箱,去查收").show(); - } - time(btn); - } - }); - } else{ - $("#passlogin_error_notice").show(); - } - } - } -} - -//注册页面 -$(function(){ - $("#phone_verification_code").on('input', function(){ - if($(this).val().trim().length > 0){ - $("#regist_btn_phone").addClass("edu-back-blue"); - $("#regist_btn_phone").attr("disabled", false); - } else{ - $("#regist_btn_phone").removeClass("edu-back-blue"); - $("#regist_btn_phone").attr("disabled", "disabled"); - } - }); -}); - -$("#phone_verification_code_notice").onkeydown=function(event){ - e = event ? event :(window.event ? window.event : null); - if(e.keyCode==13){ - phone_register(); - } -}; - -function get_phone_reg_verification_code(btn) { - if($(btn).attr("disabled")) { - return false; - } else { - if ($phone_correct){ - if(!IsPC() || $('#reg-drag .drag_text').html() == "验证通过") { - var valid_type = /^1\d{10}$/.test($('#user_phone_num').val()) ? 1 : 8; - $.get( - '/account/get_verification_code', - { value: $('#user_phone_num').val().trim(), - type: valid_type}, - function (data) { - if (data.status == "2") { - $('#user_phone_notice').html('该手机号/邮箱已被注册').show(); - } else { - $('#phone_verification_code_notice').removeClass("color-orange"); - if(valid_type == 1){ - if(data.msg != "验证码已经发送到您的手机,请注意查收"){ - $('#phone_verification_code_notice').addClass("color-orange"); - } - $('#phone_verification_code_notice').html(data.msg).show(); - } else{ - var uurl = gotoEmail(data.msg); - $("#phone_verification_code_notice").html("验证码已经发送到您的邮箱,去查收").show(); - } - time(btn); - } - }); - } else{ - $("#user_verification_notice").html("请先拖动滑块完成验证").show(); - } - } - } -} - -var $phone_correct = false; -var $passwd_1_correct = false; -jQuery(document).ready(function () { - var $phone_num = $('#user_phone_num'); - var $password1 = $('#user_password_1'); - $phone_num.blur(function (event) { - if ($(this).is('#user_phone_num')) { - if($("#phone_verification_code").length > 0){ - if (!/^1\d{10}$/.test($(this).val()) && !/^[a-zA-Z0-9]+([.\-_\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/.test($(this).val())){ - $('#user_phone_notice').html('请输入正确的手机号或邮箱').show(); - return false; - } else{ - var valid_type = /^1\d{10}$/.test($(this).val()) ? "phone" : "mail"; - $.get( - '/account/valid_ajax', - { valid: valid_type, - value: this.value }, - function (data) { - if (data.valid) { - $('#user_phone_notice').html('').hide(); - $("#get_verification_code").addClass("edu-back-blue"); - $("#get_verification_code").attr("disabled", false); - $phone_correct = true; - } else { - $('#user_phone_notice').html('该手机号或邮箱已被注册').show(); - $("#get_verification_code").removeClass("edu-back-blue"); - $("#get_verification_code").attr("disabled", "disabled"); - $phone_correct = false; - } - }); - } - } else { - if (!/^[a-zA-Z0-9]+([.\-_\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/.test($(this).val())){ - $('#user_phone_notice').html('请输入正确的邮箱').show(); - return false; - } else{ - var valid_type = "mail"; - $.get( - '/account/valid_ajax', - { valid: valid_type, - value: this.value }, - function (data) { - if (data.valid) { - $('#user_phone_notice').html('').hide(); - $("#regist_btn_phone").addClass("edu-back-blue"); - $("#regist_btn_phone").attr("disabled", false); - $phone_correct = true; - } else { - $('#user_phone_notice').html('该邮箱已被注册').show(); - $("#regist_btn_phone").removeClass("edu-back-blue"); - $("#regist_btn_phone").attr("disabled", "disabled"); - $phone_correct = false; - } - }); - } - } - } - }); - - $password1.blur(function () { - var pas1 = document.getElementById("user_password_1").value; - var password_min_length = 8; - var password_max_length = 16; - if (pas1.length >= password_min_length && pas1.length <= password_max_length) { - $('#user_password_1_notice').html('').hide(); - $passwd_1_correct = true; - } else { - $('#user_password_1_notice').html('请输入8-16位密码,区分大小写字母').show(); - $passwd_1_correct = false; - } - }); -}); - -function phone_register(){ - if($phone_correct && $passwd_1_correct){ - if($("#phone_verification_code").length > 0){ - if($("#phone_verification_code").val().trim() == ""){ - $("#phone_verification_code_notice").html("请输入手机/邮箱验证码").show(); - } else{ - $("#phone_verification_code_notice").html("").hide(); - if($("#read_and_confirm_1").attr("checked") == 'checked'){ - $("#user_aggre_1_notice").html("").hide(); - $("#user_aggre_1_notice").parent(); - var valid_type = /^1\d{10}$/.test($("#user_phone_num").val().trim()) ? 1 : 8; - $.get( - '/account/valid_verification_code', - { phone: $("#user_phone_num").val().trim(), - code: $("#phone_verification_code").val().trim(), - type: valid_type}, - function (data) { - if (data.valid) { - $("#phone_verification_code_notice").html("").hide(); - $("#main_reg_form").submit(); - $("#regist_btn_phone").attr("disabled", "disabled"); - } else { - $("#phone_verification_code_notice").html("验证码错误或过期").addClass("color-orange").show(); - } - }); - } else{ - $("#user_aggre_1_notice").html("如果要继续请选中此框").show(); - } - } - } else{ - if($("#read_and_confirm_1").attr("checked") == 'checked'){ - $("#user_aggre_1_notice").html("").hide(); - $("#user_aggre_1_notice").parent(); - $("#main_reg_form").submit(); - $("#regist_btn_phone").attr("disabled", "disabled"); - } else{ - $("#user_aggre_1_notice").html("如果要继续请选中此框").show(); - } - } - }else{ - } -} - -var bind_email_status = false; - -// 新注册用户绑定邮箱 -$(function(){ - $("#user_new_email_addr").on('input', function(){ - if($(this).val().trim().length > 0){ - $("#regist_bind_email").addClass("edu-back-blue"); - $("#regist_bind_email").attr("disabled", false); - } else{ - $("#regist_bind_email").removeClass("edu-back-blue"); - $("#regist_bind_email").attr("disabled", "disabled"); - } - }); - - $("#user_new_email_addr").on('blur', function(){ - if (/^[a-zA-Z0-9]+([.\-_\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/.test($(this).val().trim()) == false){ - $('#user_email_addr_notice').html('请输入有效的邮箱地址').show(); - bind_email_status = false; - } else{ - $.get( - '/account/valid_ajax', - { valid: "mail", - value: $(this).val().trim() }, - function (data) { - if (data.valid) { - bind_email_status = true; - $('#user_email_addr_notice').html('').hide(); - } else { - bind_email_status = false; - $('#user_email_addr_notice').html('该邮箱无效或已被注册').show(); - } - }); - } - }); -}); - -function register_bind_email(){ - if(bind_email_status){ - $("#main_bind_email_form").submit(); - } -} - -var wait = 60; - -function time(btn){ - if (wait==0) { - $(btn).addClass("edu-back-blue"); - btn.removeAttribute("disabled"); - btn.innerHTML = "获取验证码"; - wait = 60; - return; - }else{ - $(btn).removeClass("edu-back-blue"); - btn.setAttribute("disabled", "disabled"); - btn.innerHTML = wait + "s后重试"; - wait--; - } - timer = setTimeout(function(){ - time(btn); - },1000); -} - -// 邮箱验证 -//功能:根据用户输入的Email跳转到相应的电子邮箱首页 -function gotoEmail($mail) { - $t = $mail; - $t = $t.toLowerCase(); - if ($t == '163.com') { - return 'mail.163.com'; - } else if ($t == 'vip.163.com') { - return 'vip.163.com'; - } else if ($t == '126.com') { - return 'mail.126.com'; - } else if ($t == 'qq.com' || $t == 'vip.qq.com' || $t == 'foxmail.com') { - return 'mail.qq.com'; - } else if ($t == 'gmail.com') { - return 'mail.google.com'; - } else if ($t == 'sohu.com') { - return 'mail.sohu.com'; - } else if ($t == 'tom.com') { - return 'mail.tom.com'; - } else if ($t == 'vip.sina.com') { - return 'vip.sina.com'; - } else if ($t == 'sina.com.cn' || $t == 'sina.com') { - return 'mail.sina.com.cn'; - } else if ($t == 'tom.com') { - return 'mail.tom.com'; - } else if ($t == 'yahoo.com.cn' || $t == 'yahoo.cn') { - return 'mail.cn.yahoo.com'; - } else if ($t == 'tom.com') { - return 'mail.tom.com'; - } else if ($t == 'yeah.net') { - return 'www.yeah.net'; - } else if ($t == '21cn.com') { - return 'mail.21cn.com'; - } else if ($t == 'hotmail.com') { - return 'www.hotmail.com'; - } else if ($t == 'sogou.com') { - return 'mail.sogou.com'; - } else if ($t == '188.com') { - return 'www.188.com'; - } else if ($t == '139.com') { - return 'mail.10086.cn'; - } else if ($t == '189.cn') { - return 'webmail15.189.cn/webmail'; - } else if ($t == 'wo.com.cn') { - return 'mail.wo.com.cn/smsmail'; - } else if ($t == '139.com') { - return 'mail.10086.cn'; - } else if ($t == 'educoder.net'){ - return 'qiye.aliyun.com' - } else { - return 'qiye.aliyun.com'; - } -} - -// 找回密码 -$(function(){ - $("#lost_phone").on("blur", function(){ - if($("#lost_phone").is(":visible")){ - if (/^1\d{10}$/.test($("#lost_phone").val().trim()) == false){ - $('#find_phone_testcode').html('请输入正确的手机号码').show(); - $("#lost_psd_get_code").removeClass("edu-back-blue").attr("disabled", "disabled"); - } else{ - $('#find_phone_testcode').hide(); - $("#lost_psd_get_code").addClass("edu-back-blue").attr("disabled", false); - } - } - }); - - $("#lost_email").on("blur", function(){ - if($("#lost_email").is(":visible")){ - if (/^[a-zA-Z0-9]+([.\-_\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/.test($("#lost_email").val().trim()) == false){ - $('#find_phone_testcode').html('请输入正确的邮箱地址').show(); - $("#lost_psd_get_code").removeClass("edu-back-blue").attr("disabled", "disabled"); - } else{ - $('#find_phone_testcode').hide(); - $("#lost_psd_get_code").addClass("edu-back-blue").attr("disabled", false); - } - } - }); - - $("#lost_psd_ver_code").on("input", function(){ - if ($(this).val().trim().length > 0) { - $("#lost_psd_next_a").addClass("edu-back-blue").attr("disabled", false); - $("#lost_psd_input_testcode").hide(); - } else { - $("#lost_psd_next_a").removeClass("edu-back-blue").attr("disabled", "disabled"); - } - }); - - $("#lost_psd_next_a").on("click", function(){ - if($(this).attr("disabled")){ - return false; - } else{ - if($("#reset_password").val().trim().length < 8 || $("#reset_password").val().trim().length > 16){ - $('#reset_password_notice').show(); - } else{ - $('#reset_password_notice').hide(); - if($("#reset_password").val() != $("#reset_password_confirmation").val()) { - $('#reset_password_confirmation_notice').show(); - } else{ - $('#reset_password_confirmation_notice').hide(); - if($("#lost_phone").is(":visible")) { - if($("#lost_phone").val().trim() != ""){ - $("#find_phone_testcode").hide(); - if($("#lost_psd_ver_code").val().trim() != ""){ - $.get( - '/account/valid_verification_code', - { phone: $("#lost_phone").val().trim(), - code: $("#lost_psd_ver_code").val().trim(), - type: 2}, - function (data) { - if (data.valid) { - $("#lost_psd_input_testcode").hide(); - $("#lost_psd_next_a").attr("disabled", "disabled"); - $("#lost_password_form").submit(); - } else { - $("#lost_psd_input_testcode").html("手机验证码错误或过期").addClass("color-orange").show(); - } - }); - } else{ - $("#lost_psd_input_testcode").html("请输入验证码").show(); - $("#lost_psd_next_a").removeClass("edu-back-blue").attr("disabled", "disabled"); - } - } else{ - $("#find_phone_testcode").html("请输入正确的手机号码").show(); - } - } else if($("#lost_email").is(":visible")){ - if($("#lost_email").val().trim() != ""){ - $("#find_phone_testcode").hide(); - if($("#lost_psd_ver_code").val().trim() != ""){ - $.get( - '/account/valid_verification_code', - { phone: $("#lost_email").val().trim(), - code: $("#lost_psd_ver_code").val().trim(), - type: 3}, - function (data) { - if (data.valid) { - $("#lost_psd_input_testcode").hide(); - $("#lost_psd_next_a").attr("disabled", "disabled"); - $("#lost_password_form").submit(); - } else { - $("#lost_psd_input_testcode").html("邮箱验证码错误或过期").addClass("color-orange").show(); - } - }); - } else{ - $("#lost_psd_input_testcode").html("请输入验证码").show(); - $("#lost_psd_next_a").removeClass("edu-back-blue").attr("disabled", "disabled"); - } - } else{ - $("#find_phone_testcode").html("请输入正确的邮箱地址").show(); - } - } - } - } - } - }); -}); - -function get_lost_psd_code(btn){ - if($(btn).attr("disabled")) { - return false; - } else { - $("#lost_psd_input_testcode").hide(); - if($("#lost_phone").is(":visible")){ - if (/^1\d{10}$/.test($("#lost_phone").val().trim())){ - if(!IsPC() || $('#lost-drag .drag_text').html() == "验证通过") { - $("#user_reg_verification_notice").hide(); - $(btn).attr("disabled", "disabled"); - $.get( - '/account/get_verification_code', - { value: $('#lost_phone').val().trim(), - type: 2}, - function (data) { - if (data.status == "2") { - $("#find_phone_testcode").html("该手机号尚未注册").show(); - } else { - $("#find_phone_testcode").hide(); - $('#lost_psd_input_testcode').removeClass("color-orange"); - if(data.msg != "验证码已经发送到您的手机,请注意查收"){ - $('#lost_psd_input_testcode').addClass("color-orange"); - } - $("#lost_psd_input_testcode").html(data.msg).show(); - time(btn); - } - }); - } else{ - $("#user_reg_verification_notice").html("请先拖动滑块完成验证").show(); - } - } else{ - $('#find_phone_testcode').html('请输入正确的手机号码').show(); - } - } else if($("#lost_email").is(":visible")){ - if (/^[a-zA-Z0-9]+([.\-_\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/.test($("#lost_email").val().trim())){ - if(!IsPC() || $('#lost-drag .drag_text').html() == "验证通过") { - $("#user_reg_verification_notice").hide(); - $(btn).attr("disabled", "disabled"); - $.get( - '/account/get_verification_code', - { value: $('#lost_email').val().trim(), - type: 3}, - function (data) { - if (data.status == "2") { - $("#find_phone_testcode").html("该邮箱尚未注册").show(); - } else { - $("#find_phone_testcode").hide(); - var uurl = gotoEmail(data.link); - $('#lost_psd_input_testcode').removeClass("color-orange"); - $("#lost_psd_input_testcode").html("验证码已经发送到您的邮箱,去查收").show(); - time(btn); - } - }); - } else{ - $("#user_reg_verification_notice").html("请先拖动滑块完成验证").show(); - } - } else{ - $('#find_phone_testcode').html('请输入正确的邮箱地址').show(); - } - } - } -} - -// 重置密码 -$(function(){ - $("#reset_password").on("blur", function(){ - if($(this).val().trim().length < 8 || $(this).val().trim().length > 16){ - $('#reset_password_notice').show(); - } else{ - $('#reset_password_notice').hide(); - } - }); - - $("#reset_password_confirmation").on("input", function(){ - if($(this).val().trim().length > 0){ - $("#new_psd_submit").addClass("edu-back-blue").attr("disabled", false); - } else{ - $("#new_psd_submit").removeClass("edu-back-blue").attr("disabled", "disabled"); - } - }); - - $("#new_psd_submit").on("click", function(){ - if($(this).attr("disabled")){ - return false; - } else{ - if($("#reset_password").val().trim().length < 8 || $("#reset_password").val().trim().length > 16){ - $('#reset_password_notice').show(); - } else{ - $('#reset_password_notice').hide(); - if($("#reset_password").val() != $("#reset_password_confirmation").val()) { - $('#reset_password_confirmation_notice').show(); - } else{ - $('#reset_password_confirmation_notice').hide(); - $("#new_psd_submit").parent().parent().submit(); - } - } - } - }); -}); - -// 实名认证 -$(function(){ - var image = $("#ren_zheng_image"); - var element = $("").attr("href", image.attr('src')+".png"); - image.wrap(element); - image.parent().colorbox({rel: 'nofollow', close: "关闭", returnFocus: false}); - - var auth_image = $("#upload_id_image"); - var auth_element = $("").attr("href", auth_image.attr('src')+".png"); - auth_image.wrap(auth_element); - auth_image.parent().colorbox({rel: 'nofollow', close: "关闭", returnFocus: false}); - - $("#user_auth_submit_a").one("click", function(){ - user_auth_submit(1); - }); - - $("#user_auth_save_a").one("click", function(){ - user_auth_submit(0); - }); - - $("#pro_certification_submit_a").one('click',function(){ - submit_pro_certification(1); - }); - - $("#pro_certification_save_a").one('click',function(){ - submit_pro_certification(0); - }); -}); - -function user_auth_submit(type){ - var flagname=true;//判断姓名 - var flagno=true;//判断身份证号码 - var flagimg= type == 1 ? false : true;//判断上传图片 - var inputname=$("#lastname").val().trim(); - var inputNo=$("#ID_number").val().trim(); - var notip=""; - if(inputname==""){ - flagname=false; - $("#lastname").siblings(".notice").find(".falseInfo").show(); - }else{ - flagname=true; - $("#lastname").siblings(".notice").find(".falseInfo").hide(); - } - var regIdCard=/^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/; - if(inputNo==""){ - flagno=false; - notip="身份证号码不能为空"; - $("#ID_number").siblings(".notice").find(".falseInfo").html(notip).show(); - } else if(regIdCard.test(inputNo)==false){ - flagno=false; - notip="身份证号码格式错误"; - $("#ID_number").siblings(".notice").find(".falseInfo").html(notip).show(); - }else{ - flagno=true; - $("#ID_number").siblings(".notice").find(".falseInfo").hide(); - } - - if(type == 1){ - if($("#upload_img_id_sign").val() == 1){ - flagimg = true; - $("#upload_img_id_sign_notice").hide(); - } else{ - $("#upload_img_id_sign_notice").show(); - } - } - - $("#save_or_submit").val(type); - - if(flagname && flagno && flagimg){ - $.ajax({ - url: '/account/check_id_number', - type: 'post', - data: {id_number:inputNo}, - success: function(data){ - if(data.result == 0){ - $("#user_auth_submit_a").removeAttr("disabled"); - notice_box("该证件号码已被另一个账号(" + data.account + ")用于认证"); - if(type == 1){ - $("#user_auth_submit_a").one("click", function(){ - user_auth_submit(1); - }); - } else{ - $("#user_auth_save_a").one("click", function(){ - user_auth_submit(0); - }); - } - } - else if (data.result == 1){ - if($("#user_certi_real_name").length == 1 && $("#user_certi_real_name").val() != inputname){ - var htmlvalue = '

    提示

    '+ - '

    修改真实姓名后需要重新申请试用授权

    '; - pop_box_new(htmlvalue, 480, 160); - } else{ - $('#my_user_auth_form').submit(); - } - } else{ - if(type == 1){ - $("#user_auth_submit_a").one("click", function(){ - user_auth_submit(1); - }); - } else{ - $("#user_auth_save_a").one("click", function(){ - user_auth_submit(0); - }); - } - } - } - }); - } else{ - if(type == 1){ - $("#user_auth_submit_a").one("click", function(){ - user_auth_submit(1); - }); - } else{ - $("#user_auth_save_a").one("click", function(){ - user_auth_submit(0); - }); - } - } -} - -function submit_pro_certification(type){ - var check = true; - if ($("#userIdentity").val() == "-1") { - $("#identity_hint").show(); - check = false; - } else{ - $("#identity_hint").hide(); - } - - if ($("#userIdentity").val() == 0 && $("#teacher").val() == "0") { - $("#te_technical_hint").show(); - check = false; - } else{ - $("#te_technical_hint").hide(); - } - - if ($("#userIdentity").val() == 2 && $("#profession").val() == "0") { - $("#pro_technical_hint").show(); - check = false; - } else{ - $("#pro_technical_hint").hide(); - } - - if ($("#userIdentity").val() == 1 && ($("#user_student_id").val().trim() == "" || !/^[0-9A-Za-z]+$/.test($("#user_student_id").val().trim()))) { - $("#user_student_id").focus(); - if($("#user_student_id").val() == ""){ - $("#student_id_hint").html('学号不能为空').show(); - } else{ - $("#student_id_hint").html('学号只能由数字和字母组成').show(); - } - check = false; - } else{ - $("#student_id_hint").hide(); - } - - // 单位或高校必须从下拉列表中选择 - if ($("input[name='school']").val().trim() == '' || ($("input[name='school']").val().trim() != '' && $("input[name='occupation']").val().trim() == '')) { //学校名字和id不对的话 - $("#no_school_hint").html('请从下拉列表中选择你的学校/公司').show(); - check = false; - } else{ - $("#no_school_hint").hide(); - } - - if($("#department").val().trim() == "" || ($("input[name='department']").val().trim() != '' && $("input[name='department_id']").val().trim() == '')){ - $("#no_department_hint").html('请从下拉列表中选择你的院系/部门').show(); - check=false; - }else{ - $("#no_department_hint").hide(); - } - - if(type == 1){ - if($("#upload_img_pro_sign").val() != 1){ - check = false; - notice_box("请上传职业证的正面照"); - } - } - - $("#save_or_submit").val(type); - - if(check){ - if ($("#userIdentity").val() == 1 && $("#user_student_id").val().trim() != ""){ - $.ajax({ - url: '/account/check_student_id', - type: 'post', - data: {student_id:$("#user_student_id").val(), school_id:$("input[name='occupation']").val()}, - success: function(data){ - if(data.result == 0){ - notice_box("该学号已被另一个账号(" + data.account + ")使用"); - if(type == 1){ - $("#pro_certification_submit_a").one("click", function(){ - submit_pro_certification(1); - }); - } else{ - $("#pro_certification_save_a").one("click", function(){ - submit_pro_certification(0); - }); - } - } - else if (data.result == 1){ - if($("#user_certi_school_id").length == 1 && $("#user_certi_school_id").val() != $("input[name='occupation']").val().trim()){ - var htmlvalue = '
    提示
    '+ - '

    修改单位名称后需要重新申请试用授权

    '; - pop_box_new(htmlvalue, 480, 160); - } else{ - $('#my_pro_certification_form').submit(); - } - } else{ - if(type == 1){ - $("#pro_certification_submit_a").one("click", function(){ - submit_pro_certification(1); - }); - } else{ - $("#pro_certification_save_a").one("click", function(){ - submit_pro_certification(0); - }); - } - } - } - }); - } else{ - if($("#user_certi_school_id").length == 1 && $("#user_certi_school_id").val() != $("input[name='occupation']").val().trim()){ - var htmlvalue = '
    提示
    '+ - '

    修改单位名称后需要重新申请试用授权

    '; - pop_box_new(htmlvalue, 480, 160); - } else{ - $('#my_pro_certification_form').submit(); - } - } - } else{ - if(type == 1){ - $("#pro_certification_submit_a").one("click", function(){ - submit_pro_certification(1); - }); - } else{ - $("#pro_certification_save_a").one("click", function(){ - submit_pro_certification(0); - }); - } - } -} - -function cancel_submit_pro(type){ - hideModal(); - if(type == 1){ - $("#pro_certification_submit_a").one("click", function(){ - submit_pro_certification(1); - }); - } else{ - $("#pro_certification_save_a").one("click", function(){ - submit_pro_certification(0); - }); - } -} - -var d_lastSearchCondition = ''; -var d_page = 1; //唯一控制页码 变量 -var d_count = 0; //查询结果的总量 -var d_maxPage = 0;//最大页面值 - - -var lastSearchCondition = ''; -var page = 1; //唯一控制页码 变量 -var count = 0; //查询结果的总量 -var maxPage = 0;//最大页面值 -var email_valid = true; - -//---------------------------基本资料-----------------------------// -$(function(){ - var testName = /^([a-zA-z]|[\\u4e00-\\u9eff])+([\\s·]([a-zA-z]|[\\u4e00-\\u9eff])+)?$/;//匹配人名的正则表达式 - - $("#userIdentity").change(function(){ - var option = $("#userIdentity option:selected"); - if(option.val()=="1"){ - $("#identity_hint").hide(); - $("#user_student_id_info").show(); - $("#user_te_technical_info").hide(); - $("#user_pro_technical_info").hide(); - }else if(option.val()=="2"){ - $("#user_student_id_info").hide(); - $("#identity_hint").hide(); - $("#user_te_technical_info").hide(); - $("#user_pro_technical_info").show(); - }else if(option.val()=="0"){ - $("#user_student_id_info").hide(); - $("#identity_hint").hide(); - $("#user_pro_technical_info").hide(); - $("#user_te_technical_info").show(); - }else{ - $("#identity_hint").hide(); - } - }); - - $("#hideRealName").on("click", function(){ - if($(this).is(":checked")){ - $("#nickname_li").show(); - } else{ - $("#nickname_li").hide(); - } - }); - - $("#mail_info").on('blur', function(){ - if ($(this).val().trim() == ""){ - $('#mail_hint').html("邮箱地址不能为空").show(); - email_valid = false; - } else{ - if (/^[a-zA-Z0-9]+([.\-_\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/.test($(this).val().trim()) == false){ - $('#mail_hint').html("请输入有效的邮箱地址").show(); - email_valid = false; - } else{ - $.get( - '/account/valid_ajax', - { valid: "mail", - value: $(this).val().trim() }, - function (data) { - if (data.valid) { - email_valid = true; - $('#mail_hint').hide(); - } else { - email_valid = false; - $('#mail_hint').html("该邮箱无效或已被注册").show(); - } - }); - } - } - }); - - $("#my_account_form_link").on('click',function(){ - my_account_form_submit(); - }); - - $('#apply_school').live("click",function(e){ - commit_add_school(); - }); - - $('#apply_department').live("click",function(e){ - commit_add_department(); - }); - - $("#search_department_result_list").scroll(function (e) { - d_nScrollHight = $(this)[0].scrollHeight; - d_nScrollTop = $(this)[0].scrollTop; - var nDivHight = $(this).height(); - if (d_nScrollTop + nDivHight >= d_nScrollHight) //到底部了, - { - //判断页码是否是最大值,如果是的,就不去请求了 - if (page >= maxPage) { - return; - } else { //如果不是,那就请求下一页,请求数据处理 - page++; - $.ajax({ - url: '/department/on_search', - type: 'post', - data: {name: $("input[name='department']").val(), school_id: $("input[name='occupation']").val(), page: page}, - success: function (data) { - d_schoolsResult = data.departments; - if (d_schoolsResult.length != undefined && d_schoolsResult.length != 0) { - var i = 0; - for (; i < d_schoolsResult.length; i++) { - link = '' + d_schoolsResult[i].department.name + ''; - $("#search_department_result_list").append(link); - } - } else { - - } - } - }); - } - } - }); - //查询学校 - $("input[name='department']").on('input', function (e) { - throttle(department_search_fn, window, e); - }); - - $(document.body).click(function (e) { - if ($(e.target).attr("id") != 'search_department_result_list' && $(e.target).attr("id") != 'department') { - $("#search_department_result_list").hide(); - } - }); - $("input[name='department']").on('focus', function (e) { - if ($("input[name='department_id']").val() != '') { //如果已经有id了。肯定存在,不用去找了。 - return; - } - - $.ajax({ - url: '/department/on_search', - type: 'post', - data: {name: e.target.value, school_id: $("input[name='occupation']").val(), page: page}, - success: function (data) { - schoolsResult = data.departments; - count = data.count; - maxPage = Math.ceil(count / 100); //最大页码值 - if (schoolsResult.length != undefined && schoolsResult.length != 0) { - var i = 0; - $("#search_department_result_list").html(''); - for (; i < schoolsResult.length; i++) { - link = '' + schoolsResult[i].department.name + ''; - $("#search_department_result_list").append(link); - } - // $("#search_department_result_list").css('left', $(e.target).offset().left); - // $("#search_department_result_list").css('top', $(e.target).offset().top + 40); - $("#search_department_result_list").css("position", "absolute"); - $("#search_department_result_list").show(); - } else { - $("#search_department_result_list").html(''); - str = e.target.value.length > 4 ? e.target.value.substr(0, 4) + "..." : e.target.value; - $("#apply_dep_a").show(); - } - } - }); - }); - - $("#search_school_result_list").scroll(function (e) { - nScrollHight = $(this)[0].scrollHeight; - nScrollTop = $(this)[0].scrollTop; - var nDivHight = $(this).height(); - if (nScrollTop + nDivHight >= nScrollHight) //到底部了, - { - //判断页码是否是最大值,如果是的,就不去请求了 - if (page >= maxPage) { - return; - } else { //如果不是,那就请求下一页,请求数据处理 - page++; - $.ajax({ - url: '/school/on_search', - type: 'post', - data: {name: $("input[name='school']").val(), page: page}, - success: function (data) { - schoolsResult = data.schools; - if (schoolsResult.length != undefined && schoolsResult.length != 0) { - var i = 0; - for (; i < schoolsResult.length; i++) { - link = '' + schoolsResult[i].school.name + ''; - $("#search_school_result_list").append(link); - } - } else { - - } - } - }); - } - } - }); - //查询学校 - $("input[name='school']").on('input', function (e) { - throttle(shcool_search_fn, window, e); - }); - - $(document.body).click(function (e) { - if ($(e.target).attr("id") != 'search_school_result_list' && $(e.target).attr("id") != 'province') { - $("#search_school_result_list").hide(); - } - }); - $("input[name='school']").on('focus', function (e) { - if ($("input[name='occupation']").val() != '') { //如果已经有id了。肯定存在,不用去找了。 - return; - } - - $.ajax({ - url: '/school/on_search', - type: 'post', - data: {name: e.target.value, page: 1}, - success: function (data) { - schoolsResult = data.schools; - count = data.count; - maxPage = Math.ceil(count / 100); //最大页码值 - if (schoolsResult.length != undefined && schoolsResult.length != 0) { - var i = 0; - $("#search_school_result_list").html(''); - for (; i < schoolsResult.length; i++) { - link = '' + schoolsResult[i].school.name + ''; - $("#search_school_result_list").append(link); - } - $("#search_school_result_list").css("position", "absolute"); - $("#search_school_result_list").show(); - if ($(e.target).val().trim() != '') { - str = e.target.value.length > 8 ? e.target.value.substr(0, 6) + "..." : e.target.value; - $("#no_school_hint").html('找到了' + count + '个包含"' + str + '"的单位'); - $("#no_school_hint").show(); - $("#apply_school_a").hide(); - } else { - $("#no_school_hint").hide(); - $("#apply_school_a").hide(); - } - } else { - $("#search_school_result_list").html(''); - str = e.target.value.length > 4 ? e.target.value.substr(0, 4) + "..." : e.target.value; - $("#apply_school_a").show(); - $("#no_school_hint").hide(); - } - } - }); - }); -}); - -function department_search_fn(e) { - - if ($(e.target).val().trim() == d_lastSearchCondition && $(e.target).val().trim() != '') {//如果输入框没有改变或者输入框为空就返回 - return; - } - $("input[name='department_id']").val(''); //一旦有输入就清空id。 - d_lastSearchCondition = $(e.target).val().trim(); - page = 1; //有新的搜索,页面重置为1 - $.ajax({ - url: '/department/on_search', - type: 'post', - data: {name: e.target.value, school_id: $("input[name='occupation']").val(), page: d_page}, - success: function (data) { - d_schoolsResult = data.departments; - count = data.count; - maxPage = Math.ceil(count / 100); //最大页码值 - if (d_schoolsResult.length != undefined && d_schoolsResult.length != 0) { - var i = 0; - $("#search_department_result_list").html(''); - for (; i < d_schoolsResult.length; i++) { - link = '' + d_schoolsResult[i].department.name + ''; - $("#search_department_result_list").append(link); - } - // $("#search_department_result_list").css('left', $(e.target).offset().left); - // $("#search_department_result_list").css('top', $(e.target).offset().top + 40); - $("#search_department_result_list").css("position", "absolute"); - $("#search_department_result_list").show(); - } else { - $("#search_department_result_list").html(''); - str = e.target.value.length > 4 ? e.target.value.substr(0, 4) + "..." : e.target.value; - $("#apply_dep_a").show(); - } - } - }); -} - -function shcool_search_fn(e) { - if ($(e.target).val().trim() == lastSearchCondition && $(e.target).val().trim() != '') {//如果输入框没有改变或者输入框为空就返回 - return; - } - $("input[name='department']").val(''); - $("input[name='department_id']").val(''); - $("#search_department_result_list").hide(); - $("input[name='occupation']").val(''); //一旦有输入就清空id。 - lastSearchCondition = $(e.target).val().trim(); - page = 1; //有新的搜索,页面重置为1 - $.ajax({ - url: '/school/on_search', - type: 'post', - data: {name: e.target.value, page: page}, - success: function (data) { - schoolsResult = data.schools; - count = data.count; - maxPage = Math.ceil(count / 100) //最大页码值 - if (schoolsResult.length != undefined && schoolsResult.length != 0) { - var i = 0; - $("#search_school_result_list").html(''); - for (; i < schoolsResult.length; i++) { - link = '' + schoolsResult[i].school.name + ''; - $("#search_school_result_list").append(link); - } - $("#search_school_result_list").css("position", "absolute"); - $("#search_school_result_list").show(); - if ($(e.target).val().trim() != '') { - str = e.target.value.length > 8 ? e.target.value.substr(0, 6) + "..." : e.target.value; - $("#no_school_hint").html('找到了' + count + '个包含"' + str + '"的单位'); - $("#no_school_hint").show(); - $("#apply_school_a").hide(); - } else { - $("#no_school_hint").hide(); - $("#apply_school_a").hide(); - } - } else { - $("#search_school_result_list").html(''); - str = e.target.value.length > 4 ? e.target.value.substr(0, 4) + "..." : e.target.value; - $("#apply_school_a").show(); - $("#no_school_hint").hide(); - } - } - }); -} - -function showtechnical_title(val) { - if(val == 1){ - $("#user_student_id_info").show(); - } - $("#identity_hint").hide(); -} - -function init_identity_and_title(pField, identity, title) { - for (var i = 0; i < pField.options.length; i++) { - if (pField.options[i].value == identity) { - pField.selectedIndex = i; - } - } - showtechnical_title(identity); - - if(identity == 0){ - var cField = document.getElementById('teacher'); - for (var i = 0; i < cField.options.length; i++) { - if (cField.options[i].value == title) { - cField.selectedIndex = i; - } - } - } else if(identity != 1){ - var cField = document.getElementById('profession'); - for (var i = 0; i < cField.options.length; i++) { - if (cField.options[i].value == title) { - cField.selectedIndex = i; - } - } - } -} - -function init_province_and_city(pField, province, cField, city) { - for (var i = 0; i < pField.options.length; i++) { - if (pField.options[i].value == province) { - pField.selectedIndex = i; - } - } - showcity(province, cField); - for (var i = 0; i < cField.options.length; i++) { - if (cField.options[i].value == city) { - cField.selectedIndex = i; - } - } -} - -function changeValue(value, data) { - //console.log(value+","+data) - $("input[name='school']").val(value); - $("input[name='occupation']").val(data); - $("#user_department_info").show(); - $("#search_school_result_list").hide(); - $("#no_school_hint").hide(); - $("#apply_school_a").hide(); -} - -function changeDepValue(value, data) { - //console.log(value+","+data) - $("input[name='department']").val(value); - $("input[name='department_id']").val(data); - $("#search_department_result_list").hide(); - $("#no_department_hint").hide(); - $("#apply_dep_a").hide(); -} - -// 基本资料页面提交表单时,判断身份与单位是否合法 -function my_account_form_submit() { - //姓名不能为空 - if ($("input[name='lastname']").val().trim() == '') { - $("#lastname").focus(); - $("#lastname_hint").show(); - e.stopImmediatePropagation(); - return; - } else { - $("#lastname_hint").hide(); - } - - // 登录名称验证 - var $login = $("#login_info"); - if ($login.length > 0){ - // 登录名是否包含字母 - var is_letter = /(^(?=.*?[a-zA-Z]).*$)/.test($login.val()); - // 登录名是否包含特殊字符 - var is_special_character = /[@#\$%\^&\*\.]+/.test($login.val()); - if(!is_letter || is_special_character){ - notice_box("登录名只能是英文,数字和下划线的组合!"); - return; - } - $.ajax({ - url: "/account/check_email", - data: {login: $login.val()}, - dataType: "JSON", - success: function(data){ - if (data.status == -1){ - notice_box("登录名已存在,请重新填写!"); - return; - } - } - }) - } - if ($("#hideRealName").is(":checked")) { - if ($("#nickname").val().trim() == '') { - $("#nickname").focus(); - $("#nickname_hint").show(); - e.stopImmediatePropagation(); - return; - } else { - $("#nickname_hint").hide(); - } - } - - if ($("#userIdentity").val() == -1) { - $("#identity_hint").show(); - e.stopImmediatePropagation(); // 阻止事件冒泡 - return; - } else{ - $("#identity_hint").hide(); - } - - if ($("#userIdentity").val() == 0 && $("#teacher").val() == "0") { - $("#te_technical_hint").show(); - e.stopImmediatePropagation(); - return; - } else{ - $("#te_technical_hint").hide(); - } - - if ($("#userIdentity").val() == 2 && $("#profession").val() == "0") { - $("#pro_technical_hint").show(); - e.stopImmediatePropagation(); - return; - } else{ - $("#pro_technical_hint").hide(); - } - - if ($("#userIdentity").val() == 1 && ($("#user_student_id").val() == "" || !/^[0-9A-Za-z]+$/.test($("#user_student_id").val().trim()))) { - $("#user_student_id").focus(); - if($("#user_student_id").val() == ""){ - $("#student_id_hint").html('学号不能为空').show(); - } else{ - $("#student_id_hint").html('学号只能由数字和字母组成').show(); - } - e.stopImmediatePropagation(); - return; - } else{ - $("#student_id_hint").hide(); - } - - /* if ($("#userProvince").val() == "0" || $("#userCity").val() == "0"){ - $("#province_hint").show(); - e.stopImmediatePropagation(); - return; - } else{ - $("#province_hint").hide(); - }*/ - - // 学校名字必须填写、单位或高校必须从下拉列表中选择 - if ($("input[name='school']").val().trim() == '' || ($("input[name='school']").val().trim() != '' && $("input[name='occupation']").val().trim() == '')) { //学校名字和id不对的话 - $("#no_school_hint").html('请从下拉列表中选择你的学校或公司').show(); - e.stopImmediatePropagation(); - return; - } else{ - $("#no_school_hint").hide(); - } - - // 学院名称如果有则必须从下拉列表中选择 - if ($("input[name='department']").val().trim() != '' && $("input[name='department_id']").val().trim() == '') { //学校名字和id不对的话 - $("#no_department_hint").html('请从下拉列表中选择你的院系或部门').show(); - e.stopImmediatePropagation(); - return; - } else{ - $("#no_department_hint").hide(); - } - - if(email_valid){ - if($("#userIdentity").val() == 1 && $("#user_student_id").val() != ""){ - $.ajax({ - url: '/account/check_user_student_id', - type: 'post', - data: {student_id:$("#user_student_id").val(), school_id:$("input[name='occupation']").val()}, - success: function(data){ - if(data.result == 0){ - notice_box("该学号已被另一个账号(" + data.account + ")使用"); - } - else if (data.result == 1){ - if($("#user_certi_school_id").length == 1 && $("#user_certi_school_id").val() != $("input[name='occupation']").val().trim()){ - var htmlvalue = '
    提示
    '+ - '

    修改单位名称后需要重新申请试用授权

    '; - pop_box_new(htmlvalue, 480, 160); - } else{ - $('#my_account_form').submit(); - } - } - } - }); - } else{ - if($("#userIdentity").val() == 2 && ($("#user_certi_real_name").length == 1 && $("#user_certi_real_name").val() != $("input[name='lastname']").val().trim()) || ($("#user_certi_school_id").length == 1 && $("#user_certi_school_id").val() != $("input[name='occupation']").val().trim())){ - var htmlvalue = '

    提示

    '+ - '

    修改真实姓名/单位名称后需要重新申请试用授权

    '; - pop_box_new(htmlvalue, 480, 160); - } else{ - $('#my_account_form').submit(); - } - } - } -} - -//申请单位 -function commit_add_school(){ - var name,province,city,address,remarks; - - name = $("#schoolname").val(); - province = $("#schollProvince").val(); - address = $("#address").val(); - city = $("#schoolCity").val(); - - if(name == ""){ - $("#schoolname").focus(); - return; - } - if($("#schoolrepeatnotice").attr("value") == "1"){ - return; - } - if(province == "" || city == ""){ - $("#province_notice").show(); - return; - } - if(address == ""){ - $("#address").focus(); - return; - } - remarks = $("#remarks").val(); - $.ajax({ - url: '/school/apply_add_school', - type: 'get', - data: {name:name,province:province,city:city,address:address,remarks:remarks}, - success: function(data){ - if(data.result == 0){ - $("input[name='school']").val(data.name); - $("input[name='occupation']").val(data.school_id); - $("#user_department_li").show(); - $("#no_school_hint").hide(); - $("#apply_school_a").hide(); - $("#school_name_hint").hide(); - //var htmlvalue = "
    添加成功!您可以继续使用了。

    后续我们将对您的高校(单位)进行审核,如有问题我们再联系您。

    "; - //$('#province').onload(); - //$('#my_account_form_link').click(); - long_notice_box("添加成功!您可以继续使用了。
    后续我们将对您的单位进行审核,如有问题我们再联系您。"); - } - else if (data.result == 1){ - } - else if (data.result == 2){ - $("#school_name_check").removeClass("fa-check-circle").removeClass("color-light-green").addClass("fa-times-circle").addClass("color-orange"); - $("#schoolrepeatnotice").show(); - $("#schoolrepeatnotice").attr("value",1); - } - return; - } - }); -} - -function ifNameRepeat(){ - //名称不能为空也不能重复 - if($("#schoolname").val() == ""){ - return; - } - - $.ajax({ - url: '/school/search_repeat_schoolname', - type: 'get', - data: {name:$("#schoolname").val()}, - success: function(data){ - if (data == 1){ - $("#school_name_check").removeClass("fa-check-circle").removeClass("color-green").addClass("fa-times-circle").addClass("color-orange"); - $("#schoolrepeatnotice").show(); - $("#schoolrepeatnotice").attr("value",1); - } - else{ - $("#school_name_check").removeClass("fa-times-circle").removeClass("color-orange").addClass("fa-check-circle").addClass("color-green"); - $("#schoolrepeatnotice").hide(); - $("#schoolrepeatnotice").attr("value",0); - } - } - }); -} - -//申请部门/学院 -function commit_add_department(){ - var school_id, name,remarks; - - school_id = $("#school_id").val(); - name = $("#department_name").val(); - - if(name == ""){ - $("#department_name").focus(); - return; - } - if($("#departmentrepeatnotice").attr("value") == "1"){ - return; - } - remarks = $("#remarks").val(); - $.ajax({ - url: '/department/apply_add_department', - type: 'post', - data: {name:name,school_id:school_id,remarks:remarks}, - success: function(data){ - if(data.result == 0){ - $("input[name='department']").val(data.name); - $("input[name='department_id']").val(data.department_id); - $("#no_department_hint").hide(); - $("#apply_dep_a").hide(); - long_notice_box("添加成功!您可以继续使用了。
    后续我们将对您的部门进行审核,如有问题我们再联系您。"); - } - else if (data.result == 1){ - } - else if (data.result == 2){ - $("#department_name_check").removeClass("fa-check-circle").removeClass("color-light-green").addClass("fa-times-circle").addClass("color-orange"); - $("#departmentrepeatnotice").attr("value",1).show(); - }else if (data.result == 4){ - $("#schoolnamenotice").show(); - $("#departmentrepeatnotice").attr("value",1); - } - return; - } - }); -} - -function ifDepNameRepeat(){ - //名称不能为空也不能重复 - if($("#department_name").val() == ""){ - return; - } - - $.ajax({ - url: '/department/search_repeat_departmentname', - type: 'post', - data: {name:$("#department_name").val(),school_id:$("#school_id").val()}, - success: function(data){ - if (data == 1){ - $("#department_name_check").removeClass("fa-check-circle").removeClass("color-light-green").addClass("fa-times-circle").addClass("color-orange"); - $("#departmentrepeatnotice").attr("value",1).show(); - } else if(data == 2){ - $("#department_name_check").removeClass("fa-times-circle").removeClass("color-orange").addClass("fa-check-circle").addClass("color-light-green"); - $("#departmentrepeatnotice").attr("value",0).hide(); - } else if(data == 0){ - $("#schoolnamenotice").show(); - $("#departmentrepeatnotice").attr("value",1); - } - } - }); -} - -// 完善资料初始化省份 -function loadProvince(){ - if($("#userProvince").length>0){showprovince("userProvince");} -} - - -// 账号安全 -$(function(){ - $("#hide_realname").on("click", function () { - window.location.href = '/users/'+$("#user_current_id").val()+'/show_or_hide_realname'; - }); -}); - -// 修改密码 -$(function(){ - var $psd_correct = false; - $("#password").on("blur", function(){ - if($("#password").val().trim() == ""){ - $("#user_password_1_notice").html("请输入原始密码").show(); - }else { - $.post( - '/account/valid_psd', - { value: this.value }, - function (data) { - if (data.valid) { - $('#user_password_1_notice').hide(); - $psd_correct = true; - } else { - $('#user_password_1_notice').html('密码输入有误').show(); - $psd_correct = false; - } - }); - } - }); - - $("#reset_password_submit").on("click", function(){ - if(!$psd_correct){ - $("#password").blur(); - }else { - $("#user_password_1_notice").hide(); - if($("#new_password").val().length < 8 || $("#new_password").val().length > 16){ - $("#user_password_2_notice").html("新密码8-16位,区分大小写字母").show(); - } else{ - $('#user_password_2_notice').hide(); - if($("#new_password").val() != $("#new_password_confirmation").val()) { - $("#user_password_3_notice").html("两次密码输入不一致").show(); - } else{ - $('#user_password_3_notice').hide(); - $("#my_password_form").submit(); - } - } - } - }); -}); - -// 更改、绑定邮箱/手机 -$(function(){ - if($("#change-bind-drag").length>0 && IsPC()){ - $("#change-bind-drag").drag(); - }else{ - $("#change-bind-drag").empty(); - } - - var $phone_correct = false; - var $mail_correct = false; - $("#change_or_bind_phone_num").blur(function (event) { - if ($(this).is('#change_or_bind_phone_num')) { - if (/^1\d{10}$/.test(this.value) == false){ - $('#change_or_bind_phone_notice').html('请输入有效的11位手机号码').show(); - return false; - } else{ - $.get( - '/account/valid_ajax', - { valid: "phone", - value: this.value }, - function (data) { - if (data.valid) { - $('#change_or_bind_phone_notice').hide(); - $phone_correct = true; - } else { - $('#change_or_bind_phone_notice').html('该手机号已被绑定').show(); - $phone_correct = false; - } - }); - } - } - }); - - $("#change_or_bind_phone_num, #change_or_bind_email_addr").on('input', function(){ - if($(this).val().trim().length > 0){ - $("#get_change_or_bind_verification_code").addClass("edu-back-blue").attr("disabled", false); - $("#change_or_bind_phone_notice").hide(); - } else{ - $("#get_change_or_bind_verification_code").removeClass("edu-back-blue").attr("disabled", "disabled"); - } - }); - // - // $("#change_or_bind_email_addr").on('input', function(){ - // if($(this).val().trim().length > 0){ - // $("#bind_email_or_phone_form_submit").addClass("edu-back-blue").attr("disabled", false); - // $("#change_or_bind_phone_notice").hide(); - // } else{ - // $("#bind_email_or_phone_form_submit").removeClass("edu-back-blue").attr("disabled", "disabled"); - // } - // }); - - $("#change_or_bind_email_addr").on('blur', function(){ - if (/^[a-zA-Z0-9]+([.\-_\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/.test($(this).val().trim()) == false){ - $('#change_or_bind_phone_notice').html('请输入有效的邮箱地址').show(); - $mail_correct = false; - } else{ - $.get( - '/account/valid_ajax', - { valid: "mail", - value: $(this).val().trim() }, - function (data) { - if (data.valid) { - $mail_correct = true; - $('#change_or_bind_phone_notice').html('').hide(); - } else { - $mail_correct = false; - $('#change_or_bind_phone_notice').html('该邮箱无效或已被注册').show(); - } - }); - } - }); - - $("#change_or_bind_verification_code").on("input", function(){ - if($(this).val().trim() != ""){ - $("#bind_email_or_phone_form_submit").addClass("edu-back-blue").attr("disabled", false); - $("#change_or_bind_verification_code_notice").hide(); - } else { - $("#bind_email_or_phone_form_submit").removeClass("edu-back-blue").attr("disabled", "disabled"); - } - }); - - $("#get_change_or_bind_verification_code").on('click', function(){ - btn = this; - if($(this).attr("disabled")){ - return false; - } else{ - if($phone_correct || $mail_correct){ - if(!IsPC() || $('.drag_text').html() == "验证通过") { - btn.setAttribute("disabled", "disabled"); - var value = ""; - var code_type = 4; - if($phone_correct){ - value = $("#change_or_bind_phone_num").val().trim(); - code_type = 4; - } else { - value = $("#change_or_bind_email_addr").val().trim(); - code_type = 5; - } - $.get( - '/account/get_verification_code', - { value: value, - type: code_type}, - function (data) { - if (data.status == "2") { - $('#change_or_bind_phone_notice').html(data.msg).show(); - btn.removeAttribute("disabled"); - } else { - $('#change_or_bind_phone_notice').hide(); - time(btn); - $('#change_or_bind_verification_code_notice').removeClass("color-orange"); - if(code_type == 4){ - if(data.msg != "验证码已经发送到您的手机,请注意查收"){ - $('#change_or_bind_verification_code_notice').addClass("color-orange"); - } - $('#change_or_bind_verification_code_notice').html(data.msg).show(); - } else { - var uurl = gotoEmail(data.msg); - $("#change_or_bind_verification_code_notice").html("验证码已经发送到您的邮箱,去查收").show(); - } - } - }); - } else{ - $("#change_or_bind_verification_notice").html("请先拖动滑块完成验证").show(); - } - } else{ - $('#change_or_bind_phone_num').blur(); - $('#change_or_bind_email_addr').blur(); - } - } - }); - - $("#bind_email_or_phone_form_submit").on('click', function(){ - if($(this).attr("disabled")){ - return; - } - - if($phone_correct || $mail_correct){ - if(!IsPC() || $('.drag_text').html() == "验证通过"){ - if($("#change_or_bind_verification_code").val().trim() == ""){ - $("#change_or_bind_verification_code_notice").html("请输入验证码").show(); - } else{ - $("#change_or_bind_verification_code_notice").html(""); - var value = ""; - var code_type = 4; - if($phone_correct){ - value = $("#change_or_bind_phone_num").val().trim(); - code_type = 4; - } else { - value = $("#change_or_bind_email_addr").val().trim(); - code_type = 5; - } - $.get( - '/account/valid_verification_code', - { phone: value, - code: $("#change_or_bind_verification_code").val().trim(), - type: code_type}, - function (data) { - if (data.valid) { - $("#change_or_bind_verification_code_notice").hide(); - $("#bind_email_or_phone_form_submit").attr("disabled", "disabled"); - $("#bind_email_or_phone_form").submit(); - } else { - $("#change_or_bind_verification_code_notice").html("验证码错误或过期").addClass("color-orange").show(); - } - }); - } - } else{ - $("#change_or_bind_verification_notice").html("请先拖动滑块完成验证").show(); - } - } else{ - $('#change_or_bind_phone_num').blur(); - $('#change_or_bind_email_addr').blur(); - } - }); -}); +$(function(){ + //注册系页面 + resizeReg(); + //登录切换方式 + $(".log_nav li").click(function(){ + $(".log_nav li").removeClass("active"); + $(this).addClass("active"); + var index=parseInt($(this).index())+1; + $(".login-panel").hide(); + $("#login-panel-"+index).show(); + if(index == 2 && IsPC()){ + $("#quick-drag").drag(); + }else{ + $("#quick-drag").empty(); + } + }); + + //注册--初始化滑动验证 + if($("#reg-drag").length>0 && IsPC()){ + $("#reg-drag").drag(); + }else{ + $("#reg-drag").empty(); + } + + //找回密码--初始化滑动验证 + if($("#lost-drag").length>0 && IsPC()){ + $("#lost-drag").drag(); + }else{ + $("#lost-drag").empty(); + } + + $("#findType").click(function(){ + var type=$(this).attr("type"); + if(type == "email"){ + $(this).attr("type","phone"); + $("#lost_phone").addClass("none"); + $("#lost_email").removeClass("none"); + $(this).html("通过手机号码找回"); + }else{ + $(this).attr("type","email"); + $("#lost_phone").removeClass("none"); + $("#lost_email").addClass("none"); + $(this).html("通过邮箱找回"); + } + $("#lost_phone").val(""); + $("#lost_email").val(""); + $('#lost-drag').empty(); + $('#lost-drag').drag(); + $("#find_phone_testcode").hide(); + $("#user_reg_verification_notice").hide(); + $("#lost_psd_input_testcode").hide(); + $("#lost_psd_ver_code").val(""); + $("#lost_psd_get_code").html("获取验证码"); + $("#lost_psd_get_code").removeClass("edu-back-blue").attr("disabled", "disabled"); + $("#lost_psd_next_a").removeClass("edu-back-blue").attr("disabled", "disabled"); + wait = 60; + clearTimeout(timer); + }); + + if(IsPC() == false){$(".drag_certi_block").hide();}//非web端打开,隐藏滚动条 + + loadProvince(); + + if($("#name_loggin_input").length > 0 && $("#name_loggin_input").val().trim() != ""){ + $("#psd_login_btn").addClass("edu-back-blue"); + $("#psd_login_btn").attr("disabled", false); + } + +}); +$(window).resize(function(){ + resizeReg(); +}) + +function resizeReg(){ + if($(".reg_pass").length>0){ + var height1=$("body").height(); + $(".reg_pass").height(height1); + } +} + +//昵称修改提交 +function submitRename(){ + if($("#newnickname").val().trim()==""){ + $("#nickname_empty_notice").removeClass("none"); + $("#newnickname").addClass("bor-red"); + }else{ + $("#nickname_empty_notice").addClass("none"); + $("#newnickname").removeClass("bor-red"); + $("#update_user_nickname_form").submit(); + hideModal(); + } +} + +//登录页面 +$(window).load(function(){ + if($("#login-panel-1").length == 0)return; + //页面加载后,输入框里面已经显示保存的用户账号和密码!有账号必定有密码(谷歌默认填充内容只能获得账号,密码为空),所以账号不为空后,密码删除按钮也要显示出来 + if($("#name_loggin_input").val().trim() != ""){ + $("#psd_login_btn").addClass("edu-back-blue"); + $("#psd_login_btn").attr("disabled", false); + } +}); +$(function() { + if($("#login-panel-1").length == 0)return; + if($("#password_loggin_input").val().trim() != ""){ + $("#psd_login_btn").addClass("edu-back-blue"); + $("#psd_login_btn").attr("disabled", false); + } + + // $("#name_loggin_input").on("input", function () { + // $("#password_error_notice").hide(); + // }); + + $("#pass_name_input").on("input", function () { + $("#send_code_notice").hide(); + }); + + $("#name_loggin_input").on("blur", function(){ + if ($(this).val().trim().length == 0){ + $(this).next().find("p").html("请输入有效的手机号/邮箱号/用户名").show(); + } else{ + $.get( + '/account/valid_ajax', + { valid: "", + value: $("#name_loggin_input").val().trim() }, + function (data) { + console.log("valid:"+data.valid); + if (data.valid) { + $("#name_loggin_input").next().find("p").html("该用户尚未注册,您可以去注册").show(); + } else { + $("#name_loggin_input").next().find("p").hide(); + } + }); + } + }); + + $("#pass_name_input").on("blur", function(){ + if (!/^1\d{10}$/.test($(this).val()) && !/^[a-zA-Z0-9]+([.\-_\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/.test($(this).val())){ + $(this).next().find("p").html("请输入有效的手机号/邮箱号").show(); + $("#get_verification_code").removeClass("edu-back-blue"); + $("#get_verification_code").attr("disabled", "disabled"); + } else{ + $(this).next().find("p").hide(); + $("#get_verification_code").addClass("edu-back-blue"); + $("#get_verification_code").attr("disabled", false); + } + }); + + $("#password_loggin_input").on('input', function(){ + // $("#password_error_notice").hide(); + if($(this).val().trim().length > 0){ + $("#psd_login_btn").addClass("edu-back-blue"); + $("#psd_login_btn").attr("disabled", false); + // $("#password_error_notice").hide(); + $("#login_error_notice").hide(); + } else{ + $("#psd_login_btn").removeClass("edu-back-blue"); + $("#psd_login_btn").attr("disabled", "disabled"); + } + }); + + $("#login_verification_code").on('input', function(){ + $("#send_code_notice").hide(); + if($(this).val().trim().length > 0){ + $("#code_login_btn").addClass("edu-back-blue"); + $("#code_login_btn").attr("disabled", false); + $("#send_code_notice").hide(); + $("#login_code_error_notice").hide(); + } else{ + $("#code_login_btn").removeClass("edu-back-blue"); + $("#code_login_btn").attr("disabled", "disabled"); + } + }); + + $("#psd_login_btn").on("click", function(){ + if($(this).attr("disabled")){ + return false; + } else{ + var result = true; + if ($("#name_loggin_input").val().trim().length == 0){ + $("#name_loggin_input").next().find("p").show(); + result = false; + } else { + $("#name_loggin_input").next().find("p").hide(); + } + if($("#password_loggin_input").val().trim().length == 0){ + $("#password_error_notice").show(); + $("#login_error_notice").hide(); + result = false; + } else{ + $("#password_error_notice").hide(); + $("#login_error_notice").hide(); + } + if(result){ + $("#main_login_form").submit(); + + /*if (/^1\d{10}$/.test($("#name_loggin_input").val())){ + $.get( + '/account/valid_ajax', + { valid: "phone", + value: $("#name_loggin_input").val().trim() }, + function (data) { + if (data.valid) { + $("#psd_none_reg").find("span").html("该手机号尚未注册,你可以去注册"); + $("#psd_none_reg").show(); + } else { + $("#psd_none_reg").hide(); + $("#main_login_form").submit(); + } + }); + } else if(/^[a-zA-Z0-9]+([.\-_\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/.test($("#name_loggin_input").val())){ + $.get( + '/account/valid_ajax', + { valid: "mail", + value: $("#name_loggin_input").val().trim() }, + function (data) { + if (data.valid) { + $("#psd_none_reg").find("span").html("该邮箱尚未绑定,你可以登录后去绑定"); + $("#psd_none_reg").show(); + } else { + $("#psd_none_reg").hide(); + $("#main_login_form").submit(); + } + }); + } else{ + $("#psd_none_reg").hide(); + $("#main_login_form").submit(); + }*/ + } + } + }); + + $("#code_login_btn").on("click", function(){ + if($(this).attr("disabled")){ + return false; + } else{ + var result = true; + if ($("#pass_name_input").val().trim().length == 0){ + $("#pass_name_input").next().find("p").html("请输入有效的手机号/邮箱号").show(); + result = false; + } else { + $("#pass_name_input").next().find("p").hide(); + } + if($("#login_verification_code").val().trim().length == 0){ + $("#send_code_notice").html("请输入验证码").show(); + result = false; + } else{ + $("#send_code_notice").hide(); + } + if(result){ + if (/^1\d{10}$/.test($("#pass_name_input").val())){ + $.get( + '/account/valid_ajax', + { valid: "phone", + value: $("#pass_name_input").val().trim() }, + function (data) { + if (data.valid) { + $("#pass_name_input").next().find("p").html("该手机号尚未注册,你可以去注册").show(); + } else { + $("#pass_name_input").next().find("p").hide(); + $("#code_login_form").submit(); + } + }); + } else if(/^[a-zA-Z0-9]+([.\-_\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/.test($("#pass_name_input").val())){ + $.get( + '/account/valid_ajax', + { valid: "mail", + value: $("#pass_name_input").val().trim() }, + function (data) { + if (data.valid) { + $("#pass_name_input").next().find("p").html("该邮箱尚未绑定,你可以登录后去绑定").show(); + } else { + $("#pass_name_input").next().find("p").hide(); + $("#code_login_form").submit(); + } + }); + } + } + } + }); +}); + +function user_login_keypress(e){ + if (e.keyCode == '13') { + $('#main_login_form').submit(); + } +} + +function user_login_code_keypress(e){ + if (e.keyCode == '13') { + $('#code_login_form').submit(); + } +} + +function get_login_verification_code(btn) { + if($(btn).attr("disabled")) { + return false; + } else { + if (/^1\d{10}$/.test($("#pass_name_input").val()) || /^[a-zA-Z0-9]+([.\-_\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/.test($("#pass_name_input").val())){ + if(!IsPC() || $('#quick-drag .drag_text').html() == "验证通过") { + $("#passlogin_error_notice").hide(); + btn.setAttribute("disabled", "disabled"); + var val = ''; + var type = 6; + if(/^1\d{10}$/.test($("#pass_name_input").val())){ + type = 6; + } else if(/^[a-zA-Z0-9]+([.\-_\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/.test($("#pass_name_input").val())){ + type = 7; + } + $.get( + '/account/get_verification_code', + { value: $('#pass_name_input').val().trim(), + type: type}, + function (data) { + if (data.status == "2") { + if(type == 6){ + $("#pass_name_input").next().find("p").html("该手机号尚未注册,你可以去注册").show(); + } else{ + $("#pass_name_input").next().find("p").html("该邮箱尚未绑定,你可以登录后去绑定").show(); + } + } else { + $("#pass_name_input").next().find("p").hide(); + $('#send_code_notice').removeClass("color-orange"); + if(type == 6){ + if(data.msg != "验证码已经发送到您的手机,请注意查收"){ + $('#send_code_notice').addClass("color-orange"); + } + $("#send_code_notice").html(data.msg).show(); + } else{ + var uurl = gotoEmail(data.link); + $("#send_code_notice").html("验证码已经发送到您的邮箱,去查收").show(); + } + time(btn); + } + }); + } else{ + $("#passlogin_error_notice").show(); + } + } + } +} + +//注册页面 +$(function(){ + $("#phone_verification_code").on('input', function(){ + if($(this).val().trim().length > 0){ + $("#regist_btn_phone").addClass("edu-back-blue"); + $("#regist_btn_phone").attr("disabled", false); + } else{ + $("#regist_btn_phone").removeClass("edu-back-blue"); + $("#regist_btn_phone").attr("disabled", "disabled"); + } + }); +}); + +$("#phone_verification_code_notice").onkeydown=function(event){ + e = event ? event :(window.event ? window.event : null); + if(e.keyCode==13){ + phone_register(); + } +}; + +function get_phone_reg_verification_code(btn) { + if($(btn).attr("disabled")) { + return false; + } else { + if ($phone_correct){ + if(!IsPC() || $('#reg-drag .drag_text').html() == "验证通过") { + var valid_type = /^1\d{10}$/.test($('#user_phone_num').val()) ? 1 : 8; + $.get( + '/account/get_verification_code', + { value: $('#user_phone_num').val().trim(), + type: valid_type}, + function (data) { + if (data.status == "2") { + $('#user_phone_notice').html('该手机号/邮箱已被注册').show(); + } else { + $('#phone_verification_code_notice').removeClass("color-orange"); + if(valid_type == 1){ + if(data.msg != "验证码已经发送到您的手机,请注意查收"){ + $('#phone_verification_code_notice').addClass("color-orange"); + } + $('#phone_verification_code_notice').html(data.msg).show(); + } else{ + var uurl = gotoEmail(data.msg); + $("#phone_verification_code_notice").html("验证码已经发送到您的邮箱,去查收").show(); + } + time(btn); + } + }); + } else{ + $("#user_verification_notice").html("请先拖动滑块完成验证").show(); + } + } + } +} + +var $phone_correct = false; +var $passwd_1_correct = false; +jQuery(document).ready(function () { + var $phone_num = $('#user_phone_num'); + var $password1 = $('#user_password_1'); + $phone_num.blur(function (event) { + if ($(this).is('#user_phone_num')) { + if($("#phone_verification_code").length > 0){ + if (!/^1\d{10}$/.test($(this).val()) && !/^[a-zA-Z0-9]+([.\-_\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/.test($(this).val())){ + $('#user_phone_notice').html('请输入正确的手机号或邮箱').show(); + return false; + } else{ + var valid_type = /^1\d{10}$/.test($(this).val()) ? "phone" : "mail"; + $.get( + '/account/valid_ajax', + { valid: valid_type, + value: this.value }, + function (data) { + if (data.valid) { + $('#user_phone_notice').html('').hide(); + $("#get_verification_code").addClass("edu-back-blue"); + $("#get_verification_code").attr("disabled", false); + $phone_correct = true; + } else { + $('#user_phone_notice').html('该手机号或邮箱已被注册').show(); + $("#get_verification_code").removeClass("edu-back-blue"); + $("#get_verification_code").attr("disabled", "disabled"); + $phone_correct = false; + } + }); + } + } else { + if (!/^[a-zA-Z0-9]+([.\-_\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/.test($(this).val())){ + $('#user_phone_notice').html('请输入正确的邮箱').show(); + return false; + } else{ + var valid_type = "mail"; + $.get( + '/account/valid_ajax', + { valid: valid_type, + value: this.value }, + function (data) { + if (data.valid) { + $('#user_phone_notice').html('').hide(); + $("#regist_btn_phone").addClass("edu-back-blue"); + $("#regist_btn_phone").attr("disabled", false); + $phone_correct = true; + } else { + $('#user_phone_notice').html('该邮箱已被注册').show(); + $("#regist_btn_phone").removeClass("edu-back-blue"); + $("#regist_btn_phone").attr("disabled", "disabled"); + $phone_correct = false; + } + }); + } + } + } + }); + + $password1.blur(function () { + var pas1 = document.getElementById("user_password_1").value; + var password_min_length = 8; + var password_max_length = 16; + if (pas1.length >= password_min_length && pas1.length <= password_max_length) { + $('#user_password_1_notice').html('').hide(); + $passwd_1_correct = true; + } else { + $('#user_password_1_notice').html('请输入8-16位密码,区分大小写字母').show(); + $passwd_1_correct = false; + } + }); +}); + +function phone_register(){ + if($phone_correct && $passwd_1_correct){ + if($("#phone_verification_code").length > 0){ + if($("#phone_verification_code").val().trim() == ""){ + $("#phone_verification_code_notice").html("请输入手机/邮箱验证码").show(); + } else{ + $("#phone_verification_code_notice").html("").hide(); + if($("#read_and_confirm_1").attr("checked") == 'checked'){ + $("#user_aggre_1_notice").html("").hide(); + $("#user_aggre_1_notice").parent(); + var valid_type = /^1\d{10}$/.test($("#user_phone_num").val().trim()) ? 1 : 8; + $.get( + '/account/valid_verification_code', + { phone: $("#user_phone_num").val().trim(), + code: $("#phone_verification_code").val().trim(), + type: valid_type}, + function (data) { + if (data.valid) { + $("#phone_verification_code_notice").html("").hide(); + $("#main_reg_form").submit(); + $("#regist_btn_phone").attr("disabled", "disabled"); + } else { + $("#phone_verification_code_notice").html("验证码错误或过期").addClass("color-orange").show(); + } + }); + } else{ + $("#user_aggre_1_notice").html("如果要继续请选中此框").show(); + } + } + } else{ + if($("#read_and_confirm_1").attr("checked") == 'checked'){ + $("#user_aggre_1_notice").html("").hide(); + $("#user_aggre_1_notice").parent(); + $("#main_reg_form").submit(); + $("#regist_btn_phone").attr("disabled", "disabled"); + } else{ + $("#user_aggre_1_notice").html("如果要继续请选中此框").show(); + } + } + }else{ + } +} + +var bind_email_status = false; + +// 新注册用户绑定邮箱 +$(function(){ + $("#user_new_email_addr").on('input', function(){ + if($(this).val().trim().length > 0){ + $("#regist_bind_email").addClass("edu-back-blue"); + $("#regist_bind_email").attr("disabled", false); + } else{ + $("#regist_bind_email").removeClass("edu-back-blue"); + $("#regist_bind_email").attr("disabled", "disabled"); + } + }); + + $("#user_new_email_addr").on('blur', function(){ + if (/^[a-zA-Z0-9]+([.\-_\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/.test($(this).val().trim()) == false){ + $('#user_email_addr_notice').html('请输入有效的邮箱地址').show(); + bind_email_status = false; + } else{ + $.get( + '/account/valid_ajax', + { valid: "mail", + value: $(this).val().trim() }, + function (data) { + if (data.valid) { + bind_email_status = true; + $('#user_email_addr_notice').html('').hide(); + } else { + bind_email_status = false; + $('#user_email_addr_notice').html('该邮箱无效或已被注册').show(); + } + }); + } + }); +}); + +function register_bind_email(){ + if(bind_email_status){ + $("#main_bind_email_form").submit(); + } +} + +var wait = 60; + +function time(btn){ + if (wait==0) { + $(btn).addClass("edu-back-blue"); + btn.removeAttribute("disabled"); + btn.innerHTML = "获取验证码"; + wait = 60; + return; + }else{ + $(btn).removeClass("edu-back-blue"); + btn.setAttribute("disabled", "disabled"); + btn.innerHTML = wait + "s后重试"; + wait--; + } + timer = setTimeout(function(){ + time(btn); + },1000); +} + +// 邮箱验证 +//功能:根据用户输入的Email跳转到相应的电子邮箱首页 +function gotoEmail($mail) { + $t = $mail; + $t = $t.toLowerCase(); + if ($t == '163.com') { + return 'mail.163.com'; + } else if ($t == 'vip.163.com') { + return 'vip.163.com'; + } else if ($t == '126.com') { + return 'mail.126.com'; + } else if ($t == 'qq.com' || $t == 'vip.qq.com' || $t == 'foxmail.com') { + return 'mail.qq.com'; + } else if ($t == 'gmail.com') { + return 'mail.google.com'; + } else if ($t == 'sohu.com') { + return 'mail.sohu.com'; + } else if ($t == 'tom.com') { + return 'mail.tom.com'; + } else if ($t == 'vip.sina.com') { + return 'vip.sina.com'; + } else if ($t == 'sina.com.cn' || $t == 'sina.com') { + return 'mail.sina.com.cn'; + } else if ($t == 'tom.com') { + return 'mail.tom.com'; + } else if ($t == 'yahoo.com.cn' || $t == 'yahoo.cn') { + return 'mail.cn.yahoo.com'; + } else if ($t == 'tom.com') { + return 'mail.tom.com'; + } else if ($t == 'yeah.net') { + return 'www.yeah.net'; + } else if ($t == '21cn.com') { + return 'mail.21cn.com'; + } else if ($t == 'hotmail.com') { + return 'www.hotmail.com'; + } else if ($t == 'sogou.com') { + return 'mail.sogou.com'; + } else if ($t == '188.com') { + return 'www.188.com'; + } else if ($t == '139.com') { + return 'mail.10086.cn'; + } else if ($t == '189.cn') { + return 'webmail15.189.cn/webmail'; + } else if ($t == 'wo.com.cn') { + return 'mail.wo.com.cn/smsmail'; + } else if ($t == '139.com') { + return 'mail.10086.cn'; + } else if ($t == 'educoder.net'){ + return 'qiye.aliyun.com' + } else { + return 'qiye.aliyun.com'; + } +} + +// 找回密码 +$(function(){ + $("#lost_phone").on("blur", function(){ + if($("#lost_phone").is(":visible")){ + if (/^1\d{10}$/.test($("#lost_phone").val().trim()) == false){ + $('#find_phone_testcode').html('请输入正确的手机号码').show(); + $("#lost_psd_get_code").removeClass("edu-back-blue").attr("disabled", "disabled"); + } else{ + $('#find_phone_testcode').hide(); + $("#lost_psd_get_code").addClass("edu-back-blue").attr("disabled", false); + } + } + }); + + $("#lost_email").on("blur", function(){ + if($("#lost_email").is(":visible")){ + if (/^[a-zA-Z0-9]+([.\-_\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/.test($("#lost_email").val().trim()) == false){ + $('#find_phone_testcode').html('请输入正确的邮箱地址').show(); + $("#lost_psd_get_code").removeClass("edu-back-blue").attr("disabled", "disabled"); + } else{ + $('#find_phone_testcode').hide(); + $("#lost_psd_get_code").addClass("edu-back-blue").attr("disabled", false); + } + } + }); + + $("#lost_psd_ver_code").on("input", function(){ + if ($(this).val().trim().length > 0) { + $("#lost_psd_next_a").addClass("edu-back-blue").attr("disabled", false); + $("#lost_psd_input_testcode").hide(); + } else { + $("#lost_psd_next_a").removeClass("edu-back-blue").attr("disabled", "disabled"); + } + }); + + $("#lost_psd_next_a").on("click", function(){ + if($(this).attr("disabled")){ + return false; + } else{ + if($("#reset_password").val().trim().length < 8 || $("#reset_password").val().trim().length > 16){ + $('#reset_password_notice').show(); + } else{ + $('#reset_password_notice').hide(); + if($("#reset_password").val() != $("#reset_password_confirmation").val()) { + $('#reset_password_confirmation_notice').show(); + } else{ + $('#reset_password_confirmation_notice').hide(); + if($("#lost_phone").is(":visible")) { + if($("#lost_phone").val().trim() != ""){ + $("#find_phone_testcode").hide(); + if($("#lost_psd_ver_code").val().trim() != ""){ + $.get( + '/account/valid_verification_code', + { phone: $("#lost_phone").val().trim(), + code: $("#lost_psd_ver_code").val().trim(), + type: 2}, + function (data) { + if (data.valid) { + $("#lost_psd_input_testcode").hide(); + $("#lost_psd_next_a").attr("disabled", "disabled"); + $("#lost_password_form").submit(); + } else { + $("#lost_psd_input_testcode").html("手机验证码错误或过期").addClass("color-orange").show(); + } + }); + } else{ + $("#lost_psd_input_testcode").html("请输入验证码").show(); + $("#lost_psd_next_a").removeClass("edu-back-blue").attr("disabled", "disabled"); + } + } else{ + $("#find_phone_testcode").html("请输入正确的手机号码").show(); + } + } else if($("#lost_email").is(":visible")){ + if($("#lost_email").val().trim() != ""){ + $("#find_phone_testcode").hide(); + if($("#lost_psd_ver_code").val().trim() != ""){ + $.get( + '/account/valid_verification_code', + { phone: $("#lost_email").val().trim(), + code: $("#lost_psd_ver_code").val().trim(), + type: 3}, + function (data) { + if (data.valid) { + $("#lost_psd_input_testcode").hide(); + $("#lost_psd_next_a").attr("disabled", "disabled"); + $("#lost_password_form").submit(); + } else { + $("#lost_psd_input_testcode").html("邮箱验证码错误或过期").addClass("color-orange").show(); + } + }); + } else{ + $("#lost_psd_input_testcode").html("请输入验证码").show(); + $("#lost_psd_next_a").removeClass("edu-back-blue").attr("disabled", "disabled"); + } + } else{ + $("#find_phone_testcode").html("请输入正确的邮箱地址").show(); + } + } + } + } + } + }); +}); + +function get_lost_psd_code(btn){ + if($(btn).attr("disabled")) { + return false; + } else { + $("#lost_psd_input_testcode").hide(); + if($("#lost_phone").is(":visible")){ + if (/^1\d{10}$/.test($("#lost_phone").val().trim())){ + if(!IsPC() || $('#lost-drag .drag_text').html() == "验证通过") { + $("#user_reg_verification_notice").hide(); + $(btn).attr("disabled", "disabled"); + $.get( + '/account/get_verification_code', + { value: $('#lost_phone').val().trim(), + type: 2}, + function (data) { + if (data.status == "2") { + $("#find_phone_testcode").html("该手机号尚未注册").show(); + } else { + $("#find_phone_testcode").hide(); + $('#lost_psd_input_testcode').removeClass("color-orange"); + if(data.msg != "验证码已经发送到您的手机,请注意查收"){ + $('#lost_psd_input_testcode').addClass("color-orange"); + } + $("#lost_psd_input_testcode").html(data.msg).show(); + time(btn); + } + }); + } else{ + $("#user_reg_verification_notice").html("请先拖动滑块完成验证").show(); + } + } else{ + $('#find_phone_testcode').html('请输入正确的手机号码').show(); + } + } else if($("#lost_email").is(":visible")){ + if (/^[a-zA-Z0-9]+([.\-_\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/.test($("#lost_email").val().trim())){ + if(!IsPC() || $('#lost-drag .drag_text').html() == "验证通过") { + $("#user_reg_verification_notice").hide(); + $(btn).attr("disabled", "disabled"); + $.get( + '/account/get_verification_code', + { value: $('#lost_email').val().trim(), + type: 3}, + function (data) { + if (data.status == "2") { + $("#find_phone_testcode").html("该邮箱尚未注册").show(); + } else { + $("#find_phone_testcode").hide(); + var uurl = gotoEmail(data.link); + $('#lost_psd_input_testcode').removeClass("color-orange"); + $("#lost_psd_input_testcode").html("验证码已经发送到您的邮箱,去查收").show(); + time(btn); + } + }); + } else{ + $("#user_reg_verification_notice").html("请先拖动滑块完成验证").show(); + } + } else{ + $('#find_phone_testcode').html('请输入正确的邮箱地址').show(); + } + } + } +} + +// 重置密码 +$(function(){ + $("#reset_password").on("blur", function(){ + if($(this).val().trim().length < 8 || $(this).val().trim().length > 16){ + $('#reset_password_notice').show(); + } else{ + $('#reset_password_notice').hide(); + } + }); + + $("#reset_password_confirmation").on("input", function(){ + if($(this).val().trim().length > 0){ + $("#new_psd_submit").addClass("edu-back-blue").attr("disabled", false); + } else{ + $("#new_psd_submit").removeClass("edu-back-blue").attr("disabled", "disabled"); + } + }); + + $("#new_psd_submit").on("click", function(){ + if($(this).attr("disabled")){ + return false; + } else{ + if($("#reset_password").val().trim().length < 8 || $("#reset_password").val().trim().length > 16){ + $('#reset_password_notice').show(); + } else{ + $('#reset_password_notice').hide(); + if($("#reset_password").val() != $("#reset_password_confirmation").val()) { + $('#reset_password_confirmation_notice').show(); + } else{ + $('#reset_password_confirmation_notice').hide(); + $("#new_psd_submit").parent().parent().submit(); + } + } + } + }); +}); + +// 实名认证 +$(function(){ + var image = $("#ren_zheng_image"); + var element = $("").attr("href", image.attr('src')+".png"); + image.wrap(element); + image.parent().colorbox({rel: 'nofollow', close: "关闭", returnFocus: false}); + + var auth_image = $("#upload_id_image"); + var auth_element = $("").attr("href", auth_image.attr('src')+".png"); + auth_image.wrap(auth_element); + auth_image.parent().colorbox({rel: 'nofollow', close: "关闭", returnFocus: false}); + + $("#user_auth_submit_a").one("click", function(){ + user_auth_submit(1); + }); + + $("#user_auth_save_a").one("click", function(){ + user_auth_submit(0); + }); + + $("#pro_certification_submit_a").one('click',function(){ + submit_pro_certification(1); + }); + + $("#pro_certification_save_a").one('click',function(){ + submit_pro_certification(0); + }); +}); + +function user_auth_submit(type){ + var flagname=true;//判断姓名 + var flagno=true;//判断身份证号码 + var flagimg= type == 1 ? false : true;//判断上传图片 + var inputname=$("#lastname").val().trim(); + var inputNo=$("#ID_number").val().trim(); + var notip=""; + if(inputname==""){ + flagname=false; + $("#lastname").siblings(".notice").find(".falseInfo").show(); + }else{ + flagname=true; + $("#lastname").siblings(".notice").find(".falseInfo").hide(); + } + var regIdCard=/^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/; + if(inputNo==""){ + flagno=false; + notip="身份证号码不能为空"; + $("#ID_number").siblings(".notice").find(".falseInfo").html(notip).show(); + } else if(regIdCard.test(inputNo)==false){ + flagno=false; + notip="身份证号码格式错误"; + $("#ID_number").siblings(".notice").find(".falseInfo").html(notip).show(); + }else{ + flagno=true; + $("#ID_number").siblings(".notice").find(".falseInfo").hide(); + } + + if(type == 1){ + if($("#upload_img_id_sign").val() == 1){ + flagimg = true; + $("#upload_img_id_sign_notice").hide(); + } else{ + $("#upload_img_id_sign_notice").show(); + } + } + + $("#save_or_submit").val(type); + + if(flagname && flagno && flagimg){ + $.ajax({ + url: '/account/check_id_number', + type: 'post', + data: {id_number:inputNo}, + success: function(data){ + if(data.result == 0){ + $("#user_auth_submit_a").removeAttr("disabled"); + notice_box("该证件号码已被另一个账号(" + data.account + ")用于认证"); + if(type == 1){ + $("#user_auth_submit_a").one("click", function(){ + user_auth_submit(1); + }); + } else{ + $("#user_auth_save_a").one("click", function(){ + user_auth_submit(0); + }); + } + } + else if (data.result == 1){ + if($("#user_certi_real_name").length == 1 && $("#user_certi_real_name").val() != inputname){ + var htmlvalue = '

    提示

    '+ + '

    修改真实姓名后需要重新申请试用授权

    '; + pop_box_new(htmlvalue, 480, 160); + } else{ + $('#my_user_auth_form').submit(); + } + } else{ + if(type == 1){ + $("#user_auth_submit_a").one("click", function(){ + user_auth_submit(1); + }); + } else{ + $("#user_auth_save_a").one("click", function(){ + user_auth_submit(0); + }); + } + } + } + }); + } else{ + if(type == 1){ + $("#user_auth_submit_a").one("click", function(){ + user_auth_submit(1); + }); + } else{ + $("#user_auth_save_a").one("click", function(){ + user_auth_submit(0); + }); + } + } +} + +function submit_pro_certification(type){ + var check = true; + if ($("#userIdentity").val() == "-1") { + $("#identity_hint").show(); + check = false; + } else{ + $("#identity_hint").hide(); + } + + if ($("#userIdentity").val() == 0 && $("#teacher").val() == "0") { + $("#te_technical_hint").show(); + check = false; + } else{ + $("#te_technical_hint").hide(); + } + + if ($("#userIdentity").val() == 2 && $("#profession").val() == "0") { + $("#pro_technical_hint").show(); + check = false; + } else{ + $("#pro_technical_hint").hide(); + } + + if ($("#userIdentity").val() == 1 && ($("#user_student_id").val().trim() == "" || !/^[0-9A-Za-z]+$/.test($("#user_student_id").val().trim()))) { + $("#user_student_id").focus(); + if($("#user_student_id").val() == ""){ + $("#student_id_hint").html('学号不能为空').show(); + } else{ + $("#student_id_hint").html('学号只能由数字和字母组成').show(); + } + check = false; + } else{ + $("#student_id_hint").hide(); + } + + // 单位或高校必须从下拉列表中选择 + if ($("input[name='school']").val().trim() == '' || ($("input[name='school']").val().trim() != '' && $("input[name='occupation']").val().trim() == '')) { //学校名字和id不对的话 + $("#no_school_hint").html('请从下拉列表中选择你的学校/公司').show(); + check = false; + } else{ + $("#no_school_hint").hide(); + } + + if($("#department").val().trim() == "" || ($("input[name='department']").val().trim() != '' && $("input[name='department_id']").val().trim() == '')){ + $("#no_department_hint").html('请从下拉列表中选择你的院系/部门').show(); + check=false; + }else{ + $("#no_department_hint").hide(); + } + + if(type == 1){ + if($("#upload_img_pro_sign").val() != 1){ + check = false; + notice_box("请上传职业证的正面照"); + } + } + + $("#save_or_submit").val(type); + + if(check){ + if ($("#userIdentity").val() == 1 && $("#user_student_id").val().trim() != ""){ + $.ajax({ + url: '/account/check_student_id', + type: 'post', + data: {student_id:$("#user_student_id").val(), school_id:$("input[name='occupation']").val()}, + success: function(data){ + if(data.result == 0){ + notice_box("该学号已被另一个账号(" + data.account + ")使用"); + if(type == 1){ + $("#pro_certification_submit_a").one("click", function(){ + submit_pro_certification(1); + }); + } else{ + $("#pro_certification_save_a").one("click", function(){ + submit_pro_certification(0); + }); + } + } + else if (data.result == 1){ + if($("#user_certi_school_id").length == 1 && $("#user_certi_school_id").val() != $("input[name='occupation']").val().trim()){ + var htmlvalue = '
    提示
    '+ + '

    修改单位名称后需要重新申请试用授权

    '; + pop_box_new(htmlvalue, 480, 160); + } else{ + $('#my_pro_certification_form').submit(); + } + } else{ + if(type == 1){ + $("#pro_certification_submit_a").one("click", function(){ + submit_pro_certification(1); + }); + } else{ + $("#pro_certification_save_a").one("click", function(){ + submit_pro_certification(0); + }); + } + } + } + }); + } else{ + if($("#user_certi_school_id").length == 1 && $("#user_certi_school_id").val() != $("input[name='occupation']").val().trim()){ + var htmlvalue = '
    提示
    '+ + '

    修改单位名称后需要重新申请试用授权

    '; + pop_box_new(htmlvalue, 480, 160); + } else{ + $('#my_pro_certification_form').submit(); + } + } + } else{ + if(type == 1){ + $("#pro_certification_submit_a").one("click", function(){ + submit_pro_certification(1); + }); + } else{ + $("#pro_certification_save_a").one("click", function(){ + submit_pro_certification(0); + }); + } + } +} + +function cancel_submit_pro(type){ + hideModal(); + if(type == 1){ + $("#pro_certification_submit_a").one("click", function(){ + submit_pro_certification(1); + }); + } else{ + $("#pro_certification_save_a").one("click", function(){ + submit_pro_certification(0); + }); + } +} + +var d_lastSearchCondition = ''; +var d_page = 1; //唯一控制页码 变量 +var d_count = 0; //查询结果的总量 +var d_maxPage = 0;//最大页面值 + + +var lastSearchCondition = ''; +var page = 1; //唯一控制页码 变量 +var count = 0; //查询结果的总量 +var maxPage = 0;//最大页面值 +var email_valid = true; + +//---------------------------基本资料-----------------------------// +$(function(){ + var testName = /^([a-zA-z]|[\\u4e00-\\u9eff])+([\\s·]([a-zA-z]|[\\u4e00-\\u9eff])+)?$/;//匹配人名的正则表达式 + + $("#userIdentity").change(function(){ + var option = $("#userIdentity option:selected"); + if(option.val()=="1"){ + $("#identity_hint").hide(); + $("#user_student_id_info").show(); + $("#user_te_technical_info").hide(); + $("#user_pro_technical_info").hide(); + }else if(option.val()=="2"){ + $("#user_student_id_info").hide(); + $("#identity_hint").hide(); + $("#user_te_technical_info").hide(); + $("#user_pro_technical_info").show(); + }else if(option.val()=="0"){ + $("#user_student_id_info").hide(); + $("#identity_hint").hide(); + $("#user_pro_technical_info").hide(); + $("#user_te_technical_info").show(); + }else{ + $("#identity_hint").hide(); + } + }); + + $("#hideRealName").on("click", function(){ + if($(this).is(":checked")){ + $("#nickname_li").show(); + } else{ + $("#nickname_li").hide(); + } + }); + + $("#mail_info").on('blur', function(){ + if ($(this).val().trim() == ""){ + $('#mail_hint').html("邮箱地址不能为空").show(); + email_valid = false; + } else{ + if (/^[a-zA-Z0-9]+([.\-_\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/.test($(this).val().trim()) == false){ + $('#mail_hint').html("请输入有效的邮箱地址").show(); + email_valid = false; + } else{ + $.get( + '/account/valid_ajax', + { valid: "mail", + value: $(this).val().trim() }, + function (data) { + if (data.valid) { + email_valid = true; + $('#mail_hint').hide(); + } else { + email_valid = false; + $('#mail_hint').html("该邮箱无效或已被注册").show(); + } + }); + } + } + }); + + $("#my_account_form_link").on('click',function(){ + my_account_form_submit(); + }); + + $('#apply_school').live("click",function(e){ + commit_add_school(); + }); + + $('#apply_department').live("click",function(e){ + commit_add_department(); + }); + + $("#search_department_result_list").scroll(function (e) { + d_nScrollHight = $(this)[0].scrollHeight; + d_nScrollTop = $(this)[0].scrollTop; + var nDivHight = $(this).height(); + if (d_nScrollTop + nDivHight >= d_nScrollHight) //到底部了, + { + //判断页码是否是最大值,如果是的,就不去请求了 + if (page >= maxPage) { + return; + } else { //如果不是,那就请求下一页,请求数据处理 + page++; + $.ajax({ + url: '/department/on_search', + type: 'post', + data: {name: $("input[name='department']").val(), school_id: $("input[name='occupation']").val(), page: page}, + success: function (data) { + d_schoolsResult = data.departments; + if (d_schoolsResult.length != undefined && d_schoolsResult.length != 0) { + var i = 0; + for (; i < d_schoolsResult.length; i++) { + link = '' + d_schoolsResult[i].department.name + ''; + $("#search_department_result_list").append(link); + } + } else { + + } + } + }); + } + } + }); + //查询学校 + $("input[name='department']").on('input', function (e) { + throttle(department_search_fn, window, e); + }); + + $(document.body).click(function (e) { + if ($(e.target).attr("id") != 'search_department_result_list' && $(e.target).attr("id") != 'department') { + $("#search_department_result_list").hide(); + } + }); + $("input[name='department']").on('focus', function (e) { + if ($("input[name='department_id']").val() != '') { //如果已经有id了。肯定存在,不用去找了。 + return; + } + + $.ajax({ + url: '/department/on_search', + type: 'post', + data: {name: e.target.value, school_id: $("input[name='occupation']").val(), page: page}, + success: function (data) { + schoolsResult = data.departments; + count = data.count; + maxPage = Math.ceil(count / 100); //最大页码值 + if (schoolsResult.length != undefined && schoolsResult.length != 0) { + var i = 0; + $("#search_department_result_list").html(''); + for (; i < schoolsResult.length; i++) { + link = '' + schoolsResult[i].department.name + ''; + $("#search_department_result_list").append(link); + } + // $("#search_department_result_list").css('left', $(e.target).offset().left); + // $("#search_department_result_list").css('top', $(e.target).offset().top + 40); + $("#search_department_result_list").css("position", "absolute"); + $("#search_department_result_list").show(); + } else { + $("#search_department_result_list").html(''); + str = e.target.value.length > 4 ? e.target.value.substr(0, 4) + "..." : e.target.value; + $("#apply_dep_a").show(); + } + } + }); + }); + + $("#search_school_result_list").scroll(function (e) { + nScrollHight = $(this)[0].scrollHeight; + nScrollTop = $(this)[0].scrollTop; + var nDivHight = $(this).height(); + if (nScrollTop + nDivHight >= nScrollHight) //到底部了, + { + //判断页码是否是最大值,如果是的,就不去请求了 + if (page >= maxPage) { + return; + } else { //如果不是,那就请求下一页,请求数据处理 + page++; + $.ajax({ + url: '/school/on_search', + type: 'post', + data: {name: $("input[name='school']").val(), page: page}, + success: function (data) { + schoolsResult = data.schools; + if (schoolsResult.length != undefined && schoolsResult.length != 0) { + var i = 0; + for (; i < schoolsResult.length; i++) { + link = '' + schoolsResult[i].school.name + ''; + $("#search_school_result_list").append(link); + } + } else { + + } + } + }); + } + } + }); + //查询学校 + $("input[name='school']").on('input', function (e) { + throttle(shcool_search_fn, window, e); + }); + + $(document.body).click(function (e) { + if ($(e.target).attr("id") != 'search_school_result_list' && $(e.target).attr("id") != 'province') { + $("#search_school_result_list").hide(); + } + }); + $("input[name='school']").on('focus', function (e) { + if ($("input[name='occupation']").val() != '') { //如果已经有id了。肯定存在,不用去找了。 + return; + } + + $.ajax({ + url: '/school/on_search', + type: 'post', + data: {name: e.target.value, page: 1}, + success: function (data) { + schoolsResult = data.schools; + count = data.count; + maxPage = Math.ceil(count / 100); //最大页码值 + if (schoolsResult.length != undefined && schoolsResult.length != 0) { + var i = 0; + $("#search_school_result_list").html(''); + for (; i < schoolsResult.length; i++) { + link = '' + schoolsResult[i].school.name + ''; + $("#search_school_result_list").append(link); + } + $("#search_school_result_list").css("position", "absolute"); + $("#search_school_result_list").show(); + if ($(e.target).val().trim() != '') { + str = e.target.value.length > 8 ? e.target.value.substr(0, 6) + "..." : e.target.value; + $("#no_school_hint").html('找到了' + count + '个包含"' + str + '"的单位'); + $("#no_school_hint").show(); + $("#apply_school_a").hide(); + } else { + $("#no_school_hint").hide(); + $("#apply_school_a").hide(); + } + } else { + $("#search_school_result_list").html(''); + str = e.target.value.length > 4 ? e.target.value.substr(0, 4) + "..." : e.target.value; + $("#apply_school_a").show(); + $("#no_school_hint").hide(); + } + } + }); + }); +}); + +function department_search_fn(e) { + + if ($(e.target).val().trim() == d_lastSearchCondition && $(e.target).val().trim() != '') {//如果输入框没有改变或者输入框为空就返回 + return; + } + $("input[name='department_id']").val(''); //一旦有输入就清空id。 + d_lastSearchCondition = $(e.target).val().trim(); + page = 1; //有新的搜索,页面重置为1 + $.ajax({ + url: '/department/on_search', + type: 'post', + data: {name: e.target.value, school_id: $("input[name='occupation']").val(), page: d_page}, + success: function (data) { + d_schoolsResult = data.departments; + count = data.count; + maxPage = Math.ceil(count / 100); //最大页码值 + if (d_schoolsResult.length != undefined && d_schoolsResult.length != 0) { + var i = 0; + $("#search_department_result_list").html(''); + for (; i < d_schoolsResult.length; i++) { + link = '' + d_schoolsResult[i].department.name + ''; + $("#search_department_result_list").append(link); + } + // $("#search_department_result_list").css('left', $(e.target).offset().left); + // $("#search_department_result_list").css('top', $(e.target).offset().top + 40); + $("#search_department_result_list").css("position", "absolute"); + $("#search_department_result_list").show(); + } else { + $("#search_department_result_list").html(''); + str = e.target.value.length > 4 ? e.target.value.substr(0, 4) + "..." : e.target.value; + $("#apply_dep_a").show(); + } + } + }); +} + +function shcool_search_fn(e) { + if ($(e.target).val().trim() == lastSearchCondition && $(e.target).val().trim() != '') {//如果输入框没有改变或者输入框为空就返回 + return; + } + $("input[name='department']").val(''); + $("input[name='department_id']").val(''); + $("#search_department_result_list").hide(); + $("input[name='occupation']").val(''); //一旦有输入就清空id。 + lastSearchCondition = $(e.target).val().trim(); + page = 1; //有新的搜索,页面重置为1 + $.ajax({ + url: '/school/on_search', + type: 'post', + data: {name: e.target.value, page: page}, + success: function (data) { + schoolsResult = data.schools; + count = data.count; + maxPage = Math.ceil(count / 100) //最大页码值 + if (schoolsResult.length != undefined && schoolsResult.length != 0) { + var i = 0; + $("#search_school_result_list").html(''); + for (; i < schoolsResult.length; i++) { + link = '' + schoolsResult[i].school.name + ''; + $("#search_school_result_list").append(link); + } + $("#search_school_result_list").css("position", "absolute"); + $("#search_school_result_list").show(); + if ($(e.target).val().trim() != '') { + str = e.target.value.length > 8 ? e.target.value.substr(0, 6) + "..." : e.target.value; + $("#no_school_hint").html('找到了' + count + '个包含"' + str + '"的单位'); + $("#no_school_hint").show(); + $("#apply_school_a").hide(); + } else { + $("#no_school_hint").hide(); + $("#apply_school_a").hide(); + } + } else { + $("#search_school_result_list").html(''); + str = e.target.value.length > 4 ? e.target.value.substr(0, 4) + "..." : e.target.value; + $("#apply_school_a").show(); + $("#no_school_hint").hide(); + } + } + }); +} + +function showtechnical_title(val) { + if(val == 1){ + $("#user_student_id_info").show(); + } + $("#identity_hint").hide(); +} + +function init_identity_and_title(pField, identity, title) { + for (var i = 0; i < pField.options.length; i++) { + if (pField.options[i].value == identity) { + pField.selectedIndex = i; + } + } + showtechnical_title(identity); + + if(identity == 0){ + var cField = document.getElementById('teacher'); + for (var i = 0; i < cField.options.length; i++) { + if (cField.options[i].value == title) { + cField.selectedIndex = i; + } + } + } else if(identity != 1){ + var cField = document.getElementById('profession'); + for (var i = 0; i < cField.options.length; i++) { + if (cField.options[i].value == title) { + cField.selectedIndex = i; + } + } + } +} + +function init_province_and_city(pField, province, cField, city) { + for (var i = 0; i < pField.options.length; i++) { + if (pField.options[i].value == province) { + pField.selectedIndex = i; + } + } + showcity(province, cField); + for (var i = 0; i < cField.options.length; i++) { + if (cField.options[i].value == city) { + cField.selectedIndex = i; + } + } +} + +function changeValue(value, data) { + //console.log(value+","+data) + $("input[name='school']").val(value); + $("input[name='occupation']").val(data); + $("#user_department_info").show(); + $("#search_school_result_list").hide(); + $("#no_school_hint").hide(); + $("#apply_school_a").hide(); +} + +function changeDepValue(value, data) { + //console.log(value+","+data) + $("input[name='department']").val(value); + $("input[name='department_id']").val(data); + $("#search_department_result_list").hide(); + $("#no_department_hint").hide(); + $("#apply_dep_a").hide(); +} + +// 基本资料页面提交表单时,判断身份与单位是否合法 +function my_account_form_submit() { + //姓名不能为空 + if ($("input[name='lastname']").val().trim() == '') { + $("#lastname").focus(); + $("#lastname_hint").show(); + return; + } else { + $("#lastname_hint").hide(); + } + + // 登录名称验证 + var $login = $("#login_info"); + if ($login.length > 0){ + // 登录名是否包含字母 + var is_letter = /(^(?=.*?[a-zA-Z]).*$)/.test($login.val()); + // 登录名是否包含特殊字符 + var is_special_character = /[@#\$%\^&\*\.]+/.test($login.val()); + if(!is_letter || is_special_character){ + notice_box("登录名只能是英文,数字和下划线的组合!"); + return; + } + $.ajax({ + url: "/account/check_email", + data: {login: $login.val()}, + dataType: "JSON", + success: function(data){ + if (data.status == -1){ + notice_box("登录名已存在,请重新填写!"); + return; + } + } + }) + } + if ($("#hideRealName").is(":checked")) { + if ($("#nickname").val().trim() == '') { + $("#nickname").focus(); + $("#nickname_hint").show(); + return; + } else { + $("#nickname_hint").hide(); + } + } + + + if($("input[name='new_password']").val().length<8){ + $("#new_password").focus(); + $("#new_password_hint").show(); + return; + } else { + $("#new_password_hint").hide(); + } + + if($("input[name='new_password']").val() !== $("input[name='new_password_confirmation']").val() ){ + $("#new_password_confirmation").focus(); + $("#new_password_confirmation_hint").show(); + return; + } else { + $("#new_password_confirmation_hint").hide(); + } + + if ($("#userIdentity").val() == -1) { + $("#identity_hint").show(); + return; + } else{ + $("#identity_hint").hide(); + } + + if ($("#userIdentity").val() == 0 && $("#teacher").val() == "0") { + $("#te_technical_hint").show(); + return; + } else{ + $("#te_technical_hint").hide(); + } + + if ($("#userIdentity").val() == 2 && $("#profession").val() == "0") { + $("#pro_technical_hint").show(); + return; + } else{ + $("#pro_technical_hint").hide(); + } + + if ($("#userIdentity").val() == 1 && ($("#user_student_id").val() == "" || !/^[0-9A-Za-z]+$/.test($("#user_student_id").val().trim()))) { + $("#user_student_id").focus(); + if($("#user_student_id").val() == ""){ + $("#student_id_hint").html('学号不能为空').show(); + } else{ + $("#student_id_hint").html('学号只能由数字和字母组成').show(); + } + return; + } else{ + $("#student_id_hint").hide(); + } + + /* if ($("#userProvince").val() == "0" || $("#userCity").val() == "0"){ + $("#province_hint").show(); + e.stopImmediatePropagation(); + return; + } else{ + $("#province_hint").hide(); + }*/ + + // 学校名字必须填写、单位或高校必须从下拉列表中选择 + if ($("input[name='school']").val().trim() == '' || ($("input[name='school']").val().trim() != '' && $("input[name='occupation']").val().trim() == '')) { //学校名字和id不对的话 + $("#no_school_hint").html('请从下拉列表中选择你的学校或公司').show(); + e.stopImmediatePropagation(); + return; + } else{ + $("#no_school_hint").hide(); + } + + // 学院名称如果有则必须从下拉列表中选择 + if ($("input[name='department']").val().trim() != '' && $("input[name='department_id']").val().trim() == '') { //学校名字和id不对的话 + $("#no_department_hint").html('请从下拉列表中选择你的院系或部门').show(); + e.stopImmediatePropagation(); + return; + } else{ + $("#no_department_hint").hide(); + } + + if(email_valid){ + if($("#userIdentity").val() == 1 && $("#user_student_id").val() != ""){ + $.ajax({ + url: '/account/check_user_student_id', + type: 'post', + data: {student_id:$("#user_student_id").val(), school_id:$("input[name='occupation']").val()}, + success: function(data){ + if(data.result == 0){ + notice_box("该学号已被另一个账号(" + data.account + ")使用"); + } + else if (data.result == 1){ + if($("#user_certi_school_id").length == 1 && $("#user_certi_school_id").val() != $("input[name='occupation']").val().trim()){ + var htmlvalue = '
    提示
    '+ + '

    修改单位名称后需要重新申请试用授权

    '; + pop_box_new(htmlvalue, 480, 160); + } else{ + $('#my_account_form').submit(); + } + } + } + }); + } else{ + if($("#userIdentity").val() == 2 && ($("#user_certi_real_name").length == 1 && $("#user_certi_real_name").val() != $("input[name='lastname']").val().trim()) || ($("#user_certi_school_id").length == 1 && $("#user_certi_school_id").val() != $("input[name='occupation']").val().trim())){ + var htmlvalue = '

    提示

    '+ + '

    修改真实姓名/单位名称后需要重新申请试用授权

    '; + pop_box_new(htmlvalue, 480, 160); + } else{ + $('#my_account_form').submit(); + } + } + } +} + +//申请单位 +function commit_add_school(){ + var name,province,city,address,remarks; + + name = $("#schoolname").val(); + province = $("#schollProvince").val(); + address = $("#address").val(); + city = $("#schoolCity").val(); + + if(name == ""){ + $("#schoolname").focus(); + return; + } + if($("#schoolrepeatnotice").attr("value") == "1"){ + return; + } + if(province == "" || city == ""){ + $("#province_notice").show(); + return; + } + if(address == ""){ + $("#address").focus(); + return; + } + remarks = $("#remarks").val(); + $.ajax({ + url: '/school/apply_add_school', + type: 'get', + data: {name:name,province:province,city:city,address:address,remarks:remarks}, + success: function(data){ + if(data.result == 0){ + $("input[name='school']").val(data.name); + $("input[name='occupation']").val(data.school_id); + $("#user_department_li").show(); + $("#no_school_hint").hide(); + $("#apply_school_a").hide(); + $("#school_name_hint").hide(); + //var htmlvalue = "
    添加成功!您可以继续使用了。

    后续我们将对您的高校(单位)进行审核,如有问题我们再联系您。

    "; + //$('#province').onload(); + //$('#my_account_form_link').click(); + long_notice_box("添加成功!您可以继续使用了。
    后续我们将对您的单位进行审核,如有问题我们再联系您。"); + } + else if (data.result == 1){ + } + else if (data.result == 2){ + $("#school_name_check").removeClass("fa-check-circle").removeClass("color-light-green").addClass("fa-times-circle").addClass("color-orange"); + $("#schoolrepeatnotice").show(); + $("#schoolrepeatnotice").attr("value",1); + } + return; + } + }); +} + +function ifNameRepeat(){ + //名称不能为空也不能重复 + if($("#schoolname").val() == ""){ + return; + } + + $.ajax({ + url: '/school/search_repeat_schoolname', + type: 'get', + data: {name:$("#schoolname").val()}, + success: function(data){ + if (data == 1){ + $("#school_name_check").removeClass("fa-check-circle").removeClass("color-green").addClass("fa-times-circle").addClass("color-orange"); + $("#schoolrepeatnotice").show(); + $("#schoolrepeatnotice").attr("value",1); + } + else{ + $("#school_name_check").removeClass("fa-times-circle").removeClass("color-orange").addClass("fa-check-circle").addClass("color-green"); + $("#schoolrepeatnotice").hide(); + $("#schoolrepeatnotice").attr("value",0); + } + } + }); +} + +//申请部门/学院 +function commit_add_department(){ + var school_id, name,remarks; + + school_id = $("#school_id").val(); + name = $("#department_name").val(); + + if(name == ""){ + $("#department_name").focus(); + return; + } + if($("#departmentrepeatnotice").attr("value") == "1"){ + return; + } + remarks = $("#remarks").val(); + $.ajax({ + url: '/department/apply_add_department', + type: 'post', + data: {name:name,school_id:school_id,remarks:remarks}, + success: function(data){ + if(data.result == 0){ + $("input[name='department']").val(data.name); + $("input[name='department_id']").val(data.department_id); + $("#no_department_hint").hide(); + $("#apply_dep_a").hide(); + long_notice_box("添加成功!您可以继续使用了。
    后续我们将对您的部门进行审核,如有问题我们再联系您。"); + } + else if (data.result == 1){ + } + else if (data.result == 2){ + $("#department_name_check").removeClass("fa-check-circle").removeClass("color-light-green").addClass("fa-times-circle").addClass("color-orange"); + $("#departmentrepeatnotice").attr("value",1).show(); + }else if (data.result == 4){ + $("#schoolnamenotice").show(); + $("#departmentrepeatnotice").attr("value",1); + } + return; + } + }); +} + +function ifDepNameRepeat(){ + //名称不能为空也不能重复 + if($("#department_name").val() == ""){ + return; + } + + $.ajax({ + url: '/department/search_repeat_departmentname', + type: 'post', + data: {name:$("#department_name").val(),school_id:$("#school_id").val()}, + success: function(data){ + if (data == 1){ + $("#department_name_check").removeClass("fa-check-circle").removeClass("color-light-green").addClass("fa-times-circle").addClass("color-orange"); + $("#departmentrepeatnotice").attr("value",1).show(); + } else if(data == 2){ + $("#department_name_check").removeClass("fa-times-circle").removeClass("color-orange").addClass("fa-check-circle").addClass("color-light-green"); + $("#departmentrepeatnotice").attr("value",0).hide(); + } else if(data == 0){ + $("#schoolnamenotice").show(); + $("#departmentrepeatnotice").attr("value",1); + } + } + }); +} + +// 完善资料初始化省份 +function loadProvince(){ + if($("#userProvince").length>0){showprovince("userProvince");} +} + + +// 账号安全 +$(function(){ + $("#hide_realname").on("click", function () { + window.location.href = '/users/'+$("#user_current_id").val()+'/show_or_hide_realname'; + }); +}); + +// 修改密码 +$(function(){ + var $psd_correct = false; + $("#password").on("blur", function(){ + if($("#password").val().trim() == ""){ + $("#user_password_1_notice").html("请输入原始密码").show(); + }else { + $.post( + '/account/valid_psd', + { value: this.value }, + function (data) { + if (data.valid) { + $('#user_password_1_notice').hide(); + $psd_correct = true; + } else { + $('#user_password_1_notice').html('密码输入有误').show(); + $psd_correct = false; + } + }); + } + }); + + $("#reset_password_submit").on("click", function(){ + if(!$psd_correct){ + $("#password").blur(); + }else { + $("#user_password_1_notice").hide(); + if($("#new_password").val().length < 8 || $("#new_password").val().length > 16){ + $("#user_password_2_notice").html("新密码8-16位,区分大小写字母").show(); + } else{ + $('#user_password_2_notice').hide(); + if($("#new_password").val() != $("#new_password_confirmation").val()) { + $("#user_password_3_notice").html("两次密码输入不一致").show(); + } else{ + $('#user_password_3_notice').hide(); + $("#my_password_form").submit(); + } + } + } + }); +}); + +// 更改、绑定邮箱/手机 +$(function(){ + if($("#change-bind-drag").length>0 && IsPC()){ + $("#change-bind-drag").drag(); + }else{ + $("#change-bind-drag").empty(); + } + + var $phone_correct = false; + var $mail_correct = false; + $("#change_or_bind_phone_num").blur(function (event) { + if ($(this).is('#change_or_bind_phone_num')) { + if (/^1\d{10}$/.test(this.value) == false){ + $('#change_or_bind_phone_notice').html('请输入有效的11位手机号码').show(); + return false; + } else{ + $.get( + '/account/valid_ajax', + { valid: "phone", + value: this.value }, + function (data) { + if (data.valid) { + $('#change_or_bind_phone_notice').hide(); + $phone_correct = true; + } else { + $('#change_or_bind_phone_notice').html('该手机号已被绑定').show(); + $phone_correct = false; + } + }); + } + } + }); + + $("#change_or_bind_phone_num, #change_or_bind_email_addr").on('input', function(){ + if($(this).val().trim().length > 0){ + $("#get_change_or_bind_verification_code").addClass("edu-back-blue").attr("disabled", false); + $("#change_or_bind_phone_notice").hide(); + } else{ + $("#get_change_or_bind_verification_code").removeClass("edu-back-blue").attr("disabled", "disabled"); + } + }); + // + // $("#change_or_bind_email_addr").on('input', function(){ + // if($(this).val().trim().length > 0){ + // $("#bind_email_or_phone_form_submit").addClass("edu-back-blue").attr("disabled", false); + // $("#change_or_bind_phone_notice").hide(); + // } else{ + // $("#bind_email_or_phone_form_submit").removeClass("edu-back-blue").attr("disabled", "disabled"); + // } + // }); + + $("#change_or_bind_email_addr").on('blur', function(){ + if (/^[a-zA-Z0-9]+([.\-_\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/.test($(this).val().trim()) == false){ + $('#change_or_bind_phone_notice').html('请输入有效的邮箱地址').show(); + $mail_correct = false; + } else{ + $.get( + '/account/valid_ajax', + { valid: "mail", + value: $(this).val().trim() }, + function (data) { + if (data.valid) { + $mail_correct = true; + $('#change_or_bind_phone_notice').html('').hide(); + } else { + $mail_correct = false; + $('#change_or_bind_phone_notice').html('该邮箱无效或已被注册').show(); + } + }); + } + }); + + $("#change_or_bind_verification_code").on("input", function(){ + if($(this).val().trim() != ""){ + $("#bind_email_or_phone_form_submit").addClass("edu-back-blue").attr("disabled", false); + $("#change_or_bind_verification_code_notice").hide(); + } else { + $("#bind_email_or_phone_form_submit").removeClass("edu-back-blue").attr("disabled", "disabled"); + } + }); + + $("#get_change_or_bind_verification_code").on('click', function(){ + btn = this; + if($(this).attr("disabled")){ + return false; + } else{ + if($phone_correct || $mail_correct){ + if(!IsPC() || $('.drag_text').html() == "验证通过") { + btn.setAttribute("disabled", "disabled"); + var value = ""; + var code_type = 4; + if($phone_correct){ + value = $("#change_or_bind_phone_num").val().trim(); + code_type = 4; + } else { + value = $("#change_or_bind_email_addr").val().trim(); + code_type = 5; + } + $.get( + '/account/get_verification_code', + { value: value, + type: code_type}, + function (data) { + if (data.status == "2") { + $('#change_or_bind_phone_notice').html(data.msg).show(); + btn.removeAttribute("disabled"); + } else { + $('#change_or_bind_phone_notice').hide(); + time(btn); + $('#change_or_bind_verification_code_notice').removeClass("color-orange"); + if(code_type == 4){ + if(data.msg != "验证码已经发送到您的手机,请注意查收"){ + $('#change_or_bind_verification_code_notice').addClass("color-orange"); + } + $('#change_or_bind_verification_code_notice').html(data.msg).show(); + } else { + var uurl = gotoEmail(data.msg); + $("#change_or_bind_verification_code_notice").html("验证码已经发送到您的邮箱,去查收").show(); + } + } + }); + } else{ + $("#change_or_bind_verification_notice").html("请先拖动滑块完成验证").show(); + } + } else{ + $('#change_or_bind_phone_num').blur(); + $('#change_or_bind_email_addr').blur(); + } + } + }); + + $("#bind_email_or_phone_form_submit").on('click', function(){ + if($(this).attr("disabled")){ + return; + } + + if($phone_correct || $mail_correct){ + if(!IsPC() || $('.drag_text').html() == "验证通过"){ + if($("#change_or_bind_verification_code").val().trim() == ""){ + $("#change_or_bind_verification_code_notice").html("请输入验证码").show(); + } else{ + $("#change_or_bind_verification_code_notice").html(""); + var value = ""; + var code_type = 4; + if($phone_correct){ + value = $("#change_or_bind_phone_num").val().trim(); + code_type = 4; + } else { + value = $("#change_or_bind_email_addr").val().trim(); + code_type = 5; + } + $.get( + '/account/valid_verification_code', + { phone: value, + code: $("#change_or_bind_verification_code").val().trim(), + type: code_type}, + function (data) { + if (data.valid) { + $("#change_or_bind_verification_code_notice").hide(); + $("#bind_email_or_phone_form_submit").attr("disabled", "disabled"); + $("#bind_email_or_phone_form").submit(); + } else { + $("#change_or_bind_verification_code_notice").html("验证码错误或过期").addClass("color-orange").show(); + } + }); + } + } else{ + $("#change_or_bind_verification_notice").html("请先拖动滑块完成验证").show(); + } + } else{ + $('#change_or_bind_phone_num').blur(); + $('#change_or_bind_email_addr').blur(); + } + }); +});