diff --git a/Gemfile b/Gemfile
index 94d29f4f..208e49f2 100644
--- a/Gemfile
+++ b/Gemfile
@@ -14,6 +14,7 @@ gem 'kaminari'
gem 'mini_magick'
gem 'mongoid'
+gem 'mysql2'
gem 'radius'
gem 'rake'
gem 'ruby-debug19'
diff --git a/Gemfile.lock b/Gemfile.lock
index 1abf066f..2357dd03 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -95,6 +95,8 @@ GEM
mongo (~> 1.3)
tzinfo (~> 0.3.22)
multi_json (1.0.4)
+ mysql2 (0.3.11)
+ mysql2 (0.3.11-x86-mingw32)
net-ldap (0.3.1)
orm_adapter (0.0.6)
polyglot (0.3.3)
@@ -217,6 +219,7 @@ DEPENDENCIES
kaminari
mini_magick
mongoid
+ mysql2
net-ldap (~> 0.3.1)
radius
rails (>= 3.1.0, < 3.2.0)
diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb
index 3e31ca4e..75c18d87 100644
--- a/app/controllers/sessions_controller.rb
+++ b/app/controllers/sessions_controller.rb
@@ -17,7 +17,8 @@ class SessionsController < Devise::SessionsController
if ldap.bind
result = ldap.bind_as(:base => ldap_base,:filter => ldap_filter,:password=> login_password)
if result
- resource = User.find_or_initialize_by( nccu_ldap_uid: login_uid )
+ nccu_id = get_nccu_id_from_mid_site(login_uid)
+ resource = 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?
@@ -33,5 +34,21 @@ class SessionsController < Devise::SessionsController
render :action => "new"
end
end
-
+private
+ def get_nccu_id_from_mid_site(ldap_id)
+ nccu_id = MID_CLIENT.query("SELECT nccu_id FROM rss_aaldap_view WHERE ldap_id='#{ldap_id}' LIMIT 1").first['nccu_id'] rescue nil
+ #
+ # if nccu_id.nil?
+ # #show_error
+ # p 'account not exist'
+ # #should return?
+ # end
+ # # User.first(conditions: { })
+ # rss_pautlst_ut = MID_CLIENT.query("SELECT * FROM rss_pautlst_ut WHERE nccu_id='#{nccu_id}' LIMIT 1").first rescue nil
+ # # rss_paunit = client.query("SELECT * FROM rss_paunit LIMIT 1").first rescue nil
+ # user = User.find_or_create_by(:nccu_id => nccu_id)
+ # p user
+ # # p rss_paunit
+ #
+ end
end
\ No newline at end of file
diff --git a/app/models/user/user.rb b/app/models/user/user.rb
index 6796b47e..585ed3e1 100644
--- a/app/models/user/user.rb
+++ b/app/models/user/user.rb
@@ -22,6 +22,9 @@ class User
has_and_belongs_to_many :sub_roles
accepts_nested_attributes_for :attribute_values, :allow_destroy => true
+ scope :remote_account, where(:nccu_id.ne => nil)
+
+
def avb_apps
sub_role_ids_ary=self.sub_roles.collect{|t| t.id}
query1 = AppAuth.any_in({sub_role_ids: sub_role_ids_ary}).excludes(blocked_user_ids: self.id)
diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb
index 6e608309..ea19b137 100644
--- a/config/initializers/devise.rb
+++ b/config/initializers/devise.rb
@@ -141,7 +141,4 @@ Devise.setup do |config|
# end
# manager.default_strategies(:scope => :user).unshift :twitter_oauth
# end
- config.warden do |manager|
- manager.default_strategies.unshift :check_nccu_ldap
- end
end
diff --git a/config/initializers/middle_site_connection.rb b/config/initializers/middle_site_connection.rb
new file mode 100644
index 00000000..cbe87392
--- /dev/null
+++ b/config/initializers/middle_site_connection.rb
@@ -0,0 +1,14 @@
+#encoding: utf-8
+
+require 'mysql2'
+
+
+mid_host = {
+ :host => '127.0.0.1', #mruling.nccu.edu.tw
+ :port => 8005,
+ :username => "root",
+ :password => "a3G6yWd9",
+ :database => "RSS23_NCCU_MIDDLE",
+ :encoding => "UTF8"
+}
+MID_CLIENT = Mysql2::Client.new(mid_host)
diff --git a/lib/tasks/mid_site_sync.rake b/lib/tasks/mid_site_sync.rake
new file mode 100644
index 00000000..745483d0
--- /dev/null
+++ b/lib/tasks/mid_site_sync.rake
@@ -0,0 +1,106 @@
+# encoding: utf-8
+
+namespace :mid_site do
+ attr_from_mid = %w{nccu_id psn_nam ut_chi_m eml_adr off_tel_ext sta_num}
+ officer_posgrp_code = %w{02 06 10 05} #from RSS2
+ admin_role = nil
+ sub_role = nil
+
+ task :sync => :environment do
+ users_from_mid = MID_CLIENT.query("SELECT #{attr_from_mid.join(',')} FROM rss_pautlst_ut WHERE posgrp_cod IN (#{officer_posgrp_code.join(',')})")
+ remote_list = users_from_mid.collect{|t| t["nccu_id"]}
+
+ #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
+ local_need_remove.each{|user_id| (User.find user_id).destroy}
+
+ #starting update user
+ users_from_mid.each do |mid_user|
+ local_user = User.find_or_initialize_by(:nccu_id => mid_user["nccu_id"])
+ local_user.update_attributes(mid_user)
+ local_user.save!
+ end
+ end
+
+ task :install_admin => :before_instll_admin do
+ admins_nccu_id = '2772'
+ # admin_role = Role.find_or_create_by( key: 'administrator')
+ # sub_role = admin_role.sub_roles.find_or_create_by(:key => 'computer_center')
+ info_profile = Info.first(conditions: {:key => 'profile'})
+
+ user_from_mid = MID_CLIENT.query("SELECT #{attr_from_mid.join(',')} FROM rss_pautlst_ut WHERE posgrp_cod IN (#{officer_posgrp_code.join(',')}) AND nccu_id = '#{admins_nccu_id}' limit 1")
+ admin_at_mid = user_from_mid.first
+ user_first_name = admin_at_mid["psn_nam"].size > 3 ? admin_at_mid["psn_nam"][3..-1] : admin_at_mid["psn_nam"][1..-1]
+ user_last_name = admin_at_mid["psn_nam"].size > 3 ? admin_at_mid["psn_nam"][1..2] : admin_at_mid["psn_nam"][0]
+ local_user = User.find_or_initialize_by(:nccu_id => admin_at_mid["nccu_id"])
+ local_user.update_attributes(:email => admin_at_mid["eml_adr"], :admin => true, :role_id => admin_role.id, :sub_role_ids => [sub_role.id])
+
+ # local_user.role = admin_role
+ # local_user.sub_roles <<
+ AttributeValue.create( :user => local_user, :attribute_field => info_profile.attribute_fields[0], :key => 'first_name', :en => user_first_name, :zh_tw => user_first_name )
+ AttributeValue.create( :user_id => local_user.id, :attribute_field_id => info_profile.attribute_fields[1].id, :key => 'last_name', :en => user_last_name, :zh_tw => user_last_name )
+ #AttributeValue.create( :user_id => local_user.id, :attribute_field_id => sr_1_2.attribute_fields[0].id, :key => 'field', :en => 'Computer Architecture', :zh_tw => '計算機系統結構' )
+ #AttributeValue.create( :user_id => local_user.id, :attribute_field_id => sr_1_2.attribute_fields[1].id, :key => 'department', :en => user_from_mid["ut_chi_m"], :zh_tw => user_from_mid["ut_chi_m"] )
+ #AttributeValue.create( :user_id => local_user.id, :attribute_field_id => sr_1_2.attribute_fields[2].id, :key => 'speciality', :en => 'HSR', :zh_tw => '高鐵' )
+
+ end
+
+ task :install_test => :before_instll_admin do
+ admins_nccu_id = '139716'
+ # admin_role = Role.find_or_create_by( key: 'administrator')
+ # sub_role = admin_role.sub_roles.find_or_create_by(:key => 'computer_center')
+ info_profile = Info.first(conditions: {:key => 'profile'})
+
+ user_from_mid = MID_CLIENT.query("SELECT #{attr_from_mid.join(',')} FROM rss_pautlst_ut WHERE nccu_id = '#{admins_nccu_id}' limit 1")
+ admin_at_mid = user_from_mid.first
+ user_first_name = admin_at_mid["psn_nam"].size > 3 ? admin_at_mid["psn_nam"][3..-1] : admin_at_mid["psn_nam"][1..-1]
+ user_last_name = admin_at_mid["psn_nam"].size > 3 ? admin_at_mid["psn_nam"][1..2] : admin_at_mid["psn_nam"][0]
+ local_user = User.find_or_initialize_by(:nccu_id => admin_at_mid["nccu_id"])
+ local_user.update_attributes(:email => admin_at_mid["eml_adr"], :admin => true, :role_id => admin_role.id, :sub_role_ids => [sub_role.id])
+
+ AttributeValue.create( :user => local_user, :attribute_field => info_profile.attribute_fields[0], :key => 'first_name', :en => user_first_name, :zh_tw => user_first_name )
+ AttributeValue.create( :user_id => local_user.id, :attribute_field_id => info_profile.attribute_fields[1].id, :key => 'last_name', :en => user_last_name, :zh_tw => user_last_name )
+
+ end
+
+ task :before_instll_admin => :environment do
+
+ var_1 = I18nVariable.find_or_create_by( :document_class => 'Role', :key => 'administrator', :en => 'Administrator', :zh_tw => '管理員' )
+ var_1_1 = I18nVariable.find_or_create_by( :document_class => 'SubRole', :key => 'computer_center', :en => 'Computer Center', :zh_tw => '計算機中心', :parent_id => var_1.id )
+
+ admin_role = Role.find_or_create_by( :key => 'administrator',:built_in => true)
+ admin_role.i18n_variable =var_1
+ admin_role.save!
+
+ sub_role = admin_role.sub_roles.find_or_create_by(:key => 'computer_center', :built_in => true)
+ sub_role.i18n_variable =var_1_1
+ sub_role.save!
+
+ #var_1_1_1 = I18nVariable.create!( :document_class => 'Attribute', :key => 'field', :en => 'Field', :zh_tw => '領域', :parent_id => var_1_1.id )
+ #var_1_1_2 = I18nVariable.create!( :document_class => 'Attribute', :key => 'department', :en => 'Department', :zh_tw => '學系', :parent_id => var_1_1.id )
+
+ end
+
+
+ task :clean_local_account => :environment do
+ User.remote_account.each{|user| user.destroy}
+ end
+
+ task :claen_cc => [:clean_i18n_vars,:clean_admin_role_and_sub_role] do
+
+ end
+
+ task :clean_i18n_vars => :environment do
+ i18ns = I18nVariable.any_in( key: ['administrator','computer_center'])
+ i18ns.each { |var| var.destroy }
+ end
+
+ task :clean_admin_role_and_sub_role => :environment do
+ data = Role.any_in( key: ['administrator','computer_center'])
+ data.each { |var| var.destroy }
+
+ data = SubRole.any_in( key: ['administrator','computer_center'])
+ data.each { |var| var.destroy }
+
+ end
+end
diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/_announcement_secondary.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/_announcement_secondary.html.erb
new file mode 100644
index 00000000..40f5e871
--- /dev/null
+++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/_announcement_secondary.html.erb
@@ -0,0 +1,14 @@
+
+
+
+
+
+
<%= t('bulletin.status') %> | +<%= t('bulletin.category') %> | +<%= t('bulletin.title') %> | +<%= t('bulletin.postdate') %> | +<%= t('bulletin.deadline') %> | +<%= t('bulletin.action') %> | +
---|