From fe9032787c645fb7cae9a9b63d80c22a1d65d7ff Mon Sep 17 00:00:00 2001 From: nccu Date: Mon, 23 Apr 2012 10:13:44 +0800 Subject: [PATCH] NCCU ldap debug --- Gemfile | 1 - Gemfile.lock | 2 +- app/assets/javascripts/inc/search.js | 39 ++++++++++--------- app/assets/stylesheets/new_admin.css.erb | 4 +- app/assets/stylesheets/widget.css | 2 +- app/controllers/sessions_controller.rb | 20 +++++----- app/views/devise/sessions/new.html.erb | 3 +- lib/tasks/mid_site_sync.rake | 4 +- .../fact_checks/_privilege_user.html.erb | 3 +- 9 files changed, 41 insertions(+), 37 deletions(-) diff --git a/Gemfile b/Gemfile index dc28553d..a1ed5fb0 100644 --- a/Gemfile +++ b/Gemfile @@ -18,7 +18,6 @@ gem 'mini_magick' gem 'mongoid' gem "mongo_session_store-rails3" gem 'mysql2' -gem "net-ldap", "~> 0.3.1" gem 'nokogiri' gem 'radius' gem 'rake' diff --git a/Gemfile.lock b/Gemfile.lock index d5ae1680..5089191c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -116,9 +116,9 @@ GEM activemodel (~> 3.1) mongo (~> 1.3) tzinfo (~> 0.3.22) + multi_json (1.1.0) mysql2 (0.3.11) net-ldap (0.3.1) - multi_json (1.1.0) nokogiri (1.5.2) orm_adapter (0.0.6) pdf-writer (1.1.8) diff --git a/app/assets/javascripts/inc/search.js b/app/assets/javascripts/inc/search.js index 979b5621..70507fc6 100644 --- a/app/assets/javascripts/inc/search.js +++ b/app/assets/javascripts/inc/search.js @@ -8,24 +8,27 @@ $.extend($.expr[':'], { return (elem.textContent || elem.innerText || '').toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0; } }); +var interval,sval; $(document).ready(function(){ $("#user_filter").keyup(function(){ - if($(this).val()){ - var totalfoundbyname = $("div#users_checkbox_ary label.member-name:containsi("+$(this).val()+")").length - if(totalfoundbyname!=0){ - $("div#users_checkbox_ary label.member-name:not(:containsi("+$(this).val()+"))").parent().parent().slideUp(); - //$("div#users_checkbox_ary label.member-name:not(:containsi("+$(this).val()+"))").parent().popover('hide'); - $("div#users_checkbox_ary label.member-name:containsi("+$(this).val()+")").parent().parent().slideDown(); - $("div#users_checkbox_ary label.member-name:containsi("+$(this).val()+")").parent().popover('toggle'); - }else if(totalfoundbyname==0){ - $("div#users_checkbox_ary div.for_unit:not(:containsi("+$(this).val()+"))").parent().slideUp(); - //$("div#users_checkbox_ary div.for_unit:not(:containsi("+$(this).val()+"))").popover('hide'); - $("div#users_checkbox_ary div.for_unit:containsi("+$(this).val()+")").parent().slideDown(); - $("div#users_checkbox_ary div.for_unit:containsi("+$(this).val()+")").popover('toggle'); - } - }else{ - $(".checkbox").popover('hide'); - $("div.checkblock").slideDown(); - } + sval = $(this).val(); + $(".checkbox").popover("hide"); + $("div.checkblock").hide(); + clearInterval(interval); + interval = setInterval(waitForSearch,1000); }) -}) \ No newline at end of file +}) +var waitForSearch = function(){ + if(sval){ + var totalfoundbyname = $("div#users_checkbox_ary label.member-name:containsi("+sval+")").length + if(totalfoundbyname!=0){ + $("div#users_checkbox_ary label.member-name:containsi("+sval+")").parent().parent().show(); + }else if(totalfoundbyname==0){ + $("div#users_checkbox_ary div.for_unit:containsi("+sval+")").parent().show(); + } + }else{ + $(".checkbox").popover('hide'); + $("div.checkblock").show(); + } + clearInterval(interval); +} \ No newline at end of file diff --git a/app/assets/stylesheets/new_admin.css.erb b/app/assets/stylesheets/new_admin.css.erb index 9d687eb6..d336a2de 100644 --- a/app/assets/stylesheets/new_admin.css.erb +++ b/app/assets/stylesheets/new_admin.css.erb @@ -8,8 +8,8 @@ *= require bootstrap *= require bootstrap-orbit *= require list - *= require widgets *= require style + *= widget *= require scroll_style *= require isotope -*/ \ No newline at end of file +*/ diff --git a/app/assets/stylesheets/widget.css b/app/assets/stylesheets/widget.css index 7a658f36..2a9f430d 100644 --- a/app/assets/stylesheets/widget.css +++ b/app/assets/stylesheets/widget.css @@ -145,4 +145,4 @@ position: absolute; visibility: hidden; left: 11px; -} \ No newline at end of file +} diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 2c8b9707..a27f2841 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -11,28 +11,28 @@ class SessionsController < Devise::SessionsController login_uid = params[:user][:nccu_ldap_uid] result = false ldap = Net::LDAP.new - ldap.port = '8001' - ldap.host = '127.0.0.1' - # ldap.port = '389' - # ldap.host = '140.119.166.23' + #ldap.port = '8001' + #ldap.host = '127.0.0.1' + ldap.port = '389' + ldap.host = '140.119.166.23' ldap_filter = "(uid=#{login_uid})" ldap_base = 'ou=People,dc=nccu,dc=edu,dc=tw' ldap.authenticate("cn=uccn,ou=profile,dc=nccu,dc=edu,dc=tw","nccu2ucc") - if ldap.bind + if ldap.bind && login_password!='' #need to block password empty result = ldap.bind_as(:base => ldap_base,:filter => ldap_filter,:password=> login_password) if result nccu_id = get_nccu_id_from_mid_site(login_uid) - resource = User.first(conditions:{ nccu_id: nccu_id }) + resource = nccu_id.nil? ? nil : (User.first(conditions:{ nccu_id: nccu_id })) # resource = env['warden'].authenticate!(:check_nccu_ldap) # resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new") set_flash_message(:notice, :signed_in) if is_navigational_format? - unless resource_name.nil? + if (resource.nil? || nccu_id.nil?) + flash[:notice] = t('devise.failure.ldap_pass_but_account_not_in_orbit') + render :action => "new" + else resource_name = resource._type.downcase sign_in(resource_name, resource) respond_with resource, :location => redirect_location(resource_name, resource) - else - flash[:notice] = t('devise.failure.ldap_pass_but_account_not_in_orbit') - render :action => "new" end else flash[:notice] = t('devise.failure.ldap_invalid') diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb index 78c94936..74c78d0b 100644 --- a/app/views/devise/sessions/new.html.erb +++ b/app/views/devise/sessions/new.html.erb @@ -1,8 +1,9 @@ -

<%= t(:ruling_site) %>

<%= t(:login) %>

+ + <%= flash_messages %>
<%= form_for :user, :url => user_session_path, :html => {:class => 'user_new form-horizontal'} do |f| %>
diff --git a/lib/tasks/mid_site_sync.rake b/lib/tasks/mid_site_sync.rake index d0bf84d3..76660bf8 100644 --- a/lib/tasks/mid_site_sync.rake +++ b/lib/tasks/mid_site_sync.rake @@ -6,6 +6,8 @@ namespace :mid_site do officer_posgrp_code = %w{02 06 10 05} #from RSS2 admin_role = nil sub_role = nil + test_account_ldap_id ='139716' + task :sync => :environment do info_profile = Info.first(conditions: {:key => 'profile'}) @@ -31,7 +33,7 @@ namespace :mid_site do #remove delete user sho has been deleted at remote first local_need_remove = User.all.collect{|t| t.nccu_id rescue nil}.uniq.delete_if {|x| x == nil} - remote_list desc "Going to delete User with IDs: #{local_need_remove.inspect}" - local_need_remove.each{|user_id| (User.find user_id).destroy} + local_need_remove = User.excludes(nccu_id: test_account_ldap_id ).collect{|t| t.nccu_id rescue nil}.uniq.delete_if {|x| x == nil} - remote_list desc "Deletion completed! \n" #starting update user diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/fact_checks/_privilege_user.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/fact_checks/_privilege_user.html.erb index 759e941d..207367a0 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/fact_checks/_privilege_user.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/fact_checks/_privilege_user.html.erb @@ -3,7 +3,6 @@ <% sys_users.each do |user| -%>
- <% user.sub_roles.each do |sr| %> <% end %> @@ -23,4 +22,4 @@
<% end -%> -<% end -%> \ No newline at end of file +<% end -%>