rulingcom帳號不透過LDAP認證
This commit is contained in:
		
							parent
							
								
									d0632b2e4c
								
							
						
					
					
						commit
						9607b5bbfd
					
				|  | @ -12,7 +12,9 @@ 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? | ||||||
|  | 
 | ||||||
|  |       if ($nccu_ldap_connection.bind rescue false) | ||||||
|           logger.info "=LDAP Binded password ok..." |           logger.info "=LDAP Binded password ok..." | ||||||
|           result =check_auth_with_ldap(login_uid,login_password)  |           result =check_auth_with_ldap(login_uid,login_password)  | ||||||
|           if result && login_password!='' |           if result && login_password!='' | ||||||
|  | @ -32,11 +34,6 @@ class SessionsController < Devise::SessionsController | ||||||
|               sign_in(resource_name, resource) |               sign_in(resource_name, resource) | ||||||
|               respond_with resource, :location => redirect_location(resource_name, resource) |               respond_with resource, :location => redirect_location(resource_name, resource) | ||||||
|             end |             end | ||||||
|            elsif resource = User.first(conditions:{email: login_uid}) |  | ||||||
| 
 |  | ||||||
|              resource_name = resource._type.downcase |  | ||||||
|              sign_in(resource_name, resource) |  | ||||||
|              respond_with resource, :location => redirect_location(resource_name, resource) |  | ||||||
|           else |           else | ||||||
|             logger.error "==password LDAP fail..." |             logger.error "==password LDAP fail..." | ||||||
|             flash[:notice] = t('devise.failure.ldap_invalid') |             flash[:notice] = t('devise.failure.ldap_invalid') | ||||||
|  | @ -47,7 +44,21 @@ class SessionsController < Devise::SessionsController | ||||||
|           flash[:notice] = t('devise.failure.ldap_connection_failed') |           flash[:notice] = t('devise.failure.ldap_connection_failed') | ||||||
|           render :action => "new" |           render :action => "new" | ||||||
|         end |         end | ||||||
|  |         else #if rulingcom account | ||||||
|  |           logger.info "=======Rulingcom account======" | ||||||
|  |           resource = User.first(conditions:{email: login_uid}) | ||||||
|  |           if resource.valid_password?(params[:user][:password]) | ||||||
|  |               resource_name = resource._type.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======" |       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