member for THU

This commit is contained in:
Matthew K. Fu JuYuan committed 2012-10-18 18:36:21 +08:00
1 parent 0babd5f302
commit 13ae2602cd
14 files changed
+162 -123

No files matched your search

@@ -33,19 +33,25 @@ class Admin::UsersNewInterfaceController < ApplicationController
@student_data = []
@staff_data = []
@user.attribute_values.each{|att_val|
attribute_values = @user.attribute_values.reject{|att_val|
# binding.pry if(att_val.id.to_s == '507fa1295789b52a540000e0')
!att_val.attribute_field.locale and (att_val.attribute_field.neutral_for != I18n.locale.to_s)
}
attribute_values.each{|att_val|
@profile_data.push({:name => att_val.attribute_field.title,:value =>att_val.get_value_by_locale(I18n.locale)}) if att_val.attribute_field.attribute.key=="profile" rescue false
}
@user.attribute_values.each{|att_val|
attribute_values.each{|att_val|
@teacher_data.push({:name => att_val.attribute_field.title,:value => att_val.get_value_by_locale(I18n.locale) }) if att_val.attribute_field.role.key=="teacher"rescue false
}
@user.attribute_values.each{|att_val|
attribute_values.each{|att_val|
@student_data.push({:name => att_val.attribute_field.title,:value => att_val.get_value_by_locale(I18n.locale) }) if att_val.attribute_field.role.key=="student"rescue false
}
@user.attribute_values.each{|att_val|
attribute_values.each{|att_val|
@staff_data.push({:name => att_val.attribute_field.title,:value => att_val.get_value_by_locale(I18n.locale) }) if att_val.attribute_field.role.key=="staff_data"rescue false
}
@@ -75,19 +81,20 @@ class Admin::UsersNewInterfaceController < ApplicationController
def new
@user = User.new
@disable_all_field = true
@form_index = 0
get_info_and_roles
end
def create
puts params.to_yaml
attribute_valuesp_key = params[:user].has_key?('new_attribute_values') ? 'new_attribute_values' : 'attribute_values'
attribute_values = params[:user].delete(attribute_valuesp_key)
# binding.pry
attribute_values_key = params[:user].has_key?('new_attribute_values') ? 'new_attribute_values' : 'attribute_values'
attribute_values = params[:user].delete(attribute_values_key)
@user = User.new(params["user"])
attribute_values.to_hash.each{|key,value|
@user.attribute_values.build(value)
}
@user.rebuild_sub_roles_from_attribute_values!(attribute_values)
if @user.save
flash[:notice] = t('admin.create_success_user')
redirect_to :action => :index
@@ -104,6 +111,7 @@ class Admin::UsersNewInterfaceController < ApplicationController
end
def edit
@disable_all_field = false
@user = User.find(params[:id])
@form_index = 0
get_info_and_roles
@@ -112,6 +120,9 @@ class Admin::UsersNewInterfaceController < ApplicationController
def update
@user = User.find(params[:id])
@user.update_attributes(params[:user])
attribute_values_key = params[:user].has_key?('new_attribute_values') ? 'new_attribute_values' : 'attribute_values'
attribute_values = params[:user].delete(attribute_values_key)
@user.rebuild_sub_roles_from_attribute_values!(attribute_values)
@user.save
redirect_to :action => :show
# # Update changes to the avatar
+12 -71
View File
@@ -7,79 +7,20 @@ class SessionsController < Devise::SessionsController
# login_password = params[:user][:password]
# login_uid = params[:user][:nccu_ldap_uid]
login_password = params[:user][:password]
login_uid = params[:user][:nccu_ldap_uid]
login_email = params[:user][:login]
result = false
ldap_filter = "(uid=#{login_uid})"
if /@rulingcom.com$/.match(login_uid).nil?
MiddleSiteConnection.establish
NccuLdapConnection.establish
if ($nccu_ldap_connection.bind rescue false)
logger.info "=LDAP Binded password ok..."
result =check_auth_with_ldap(login_uid,login_password)
if result && login_password!=''
logger.info "==LDAP password passed..."
nccu_id = get_nccu_id_from_mid_site(login_uid)
resource = nccu_id.nil? ? nil : (User.first(conditions:{ nccu_ldap_uid: 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?
if (resource.nil? || nccu_id.nil?)
logger.error "===LDAP passed local block... resource:#{resource.inspect}\n nccu_id:#{nccu_id} \t login_uid:#{login_uid}"
flash[:notice] = t('devise.failure.ldap_pass_but_account_not_in_orbit')
render :action => "new"
else
logger.info "===ALL passed"
resource_name = resource.class.to_s.downcase
sign_in(resource_name, resource)
respond_with resource, :location => redirect_location(resource_name, resource)
end
else
logger.error "==password LDAP fail..."
flash[:notice] = t('devise.failure.ldap_invalid')
render :action => "new"
end
else
logger.error "=LDAP fail..."
flash[:notice] = t('devise.failure.ldap_connection_failed')
render :action => "new"
end
else #if rulingcom account
logger.info "=======Rulingcom account======"
resource = User.first(conditions:{email: login_uid})
if resource.valid_password?(login_password)
resource_name = resource.class.to_s.downcase
sign_in(resource_name, resource)
respond_with resource, :location => redirect_location(resource_name, resource)
else
logger.error "==password Local fail..."
flash[:notice] = t('devise.failure.invalid')
render :action => "new"
end
end
logger.info "=======End Debugging======"
resource = User.first(conditions:{ email: login_email })
set_flash_message(:notice, :signed_in) if is_navigational_format?
if resource.nil?
logger.error "Can't find user #{login_email}"
flash[:notice] = t('devise.failure.invalid')
render :action => "new"
else
logger.info "=== passed"
resource_name = resource.class.to_s.downcase
sign_in(resource_name, resource)
respond_with resource, :location => redirect_location(resource_name, resource)
end
private
def check_auth_with_ldap(login_uid,login_password)
ldap_filter = "(uid=#{login_uid})"
$nccu_ldap_connection.bind_as(:base => NccuLdapConnection::BASE,:filter => ldap_filter,:password=> login_password) rescue false
end
def get_nccu_id_from_mid_site(ldap_id)
nccu_id = $mid_site_connection.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_site_connection.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