rulingcom帳號不透過LDAP認證
This commit is contained in:
parent
d0632b2e4c
commit
9607b5bbfd
|
@ -12,42 +12,53 @@ class SessionsController < Devise::SessionsController
|
||||||
login_uid = params[:user][:nccu_ldap_uid]
|
login_uid = params[:user][:nccu_ldap_uid]
|
||||||
result = false
|
result = false
|
||||||
ldap_filter = "(uid=#{login_uid})"
|
ldap_filter = "(uid=#{login_uid})"
|
||||||
if $nccu_ldap_connection.bind
|
if User.first({conditions:{ email: login_uid}}).nil?
|
||||||
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._type.downcase
|
|
||||||
sign_in(resource_name, resource)
|
|
||||||
respond_with resource, :location => redirect_location(resource_name, resource)
|
|
||||||
end
|
|
||||||
elsif resource = User.first(conditions:{email: login_uid})
|
|
||||||
|
|
||||||
resource_name = resource._type.downcase
|
if ($nccu_ldap_connection.bind rescue false)
|
||||||
sign_in(resource_name, resource)
|
logger.info "=LDAP Binded password ok..."
|
||||||
respond_with resource, :location => redirect_location(resource_name, resource)
|
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._type.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
|
else
|
||||||
logger.error "==password LDAP fail..."
|
logger.error "=LDAP fail..."
|
||||||
flash[:notice] = t('devise.failure.ldap_invalid')
|
flash[:notice] = t('devise.failure.ldap_connection_failed')
|
||||||
render :action => "new"
|
render :action => "new"
|
||||||
end
|
end
|
||||||
else
|
else #if rulingcom account
|
||||||
logger.error "=LDAP fail..."
|
logger.info "=======Rulingcom account======"
|
||||||
flash[:notice] = t('devise.failure.ldap_connection_failed')
|
resource = User.first(conditions:{email: login_uid})
|
||||||
render :action => "new"
|
if resource.valid_password?(params[:user][:password])
|
||||||
end
|
resource_name = resource._type.downcase
|
||||||
logger.info "=======End Debugging======"
|
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======"
|
||||||
|
|
||||||
end
|
end
|
||||||
private
|
private
|
||||||
def check_auth_with_ldap(login_uid,login_password)
|
def check_auth_with_ldap(login_uid,login_password)
|
||||||
|
|
Loading…
Reference in New Issue