2016-07-11 2 views
0

Devise를 통해 LDAP 인증을 받았으며 데이터베이스에 사용자를 생성하기 전에 (사용자와 관련된 비즈니스 규칙으로 인해 추가 정보가 있음) 회사의 서버에있는 다른 정보를 수집하고 싶습니다.레일 4 - 컨트롤러에서 유효성 검사 작업을 올바르게 설정하는 방법?

<div class="modal-dialog"> 
    <div class="modal-content"> 
    <div class="modal-header"> 
     <button type="button" class="close" data-dismiss="modal">&times;</button> 
     <h3>Find User by Email</h3> 
    </div> 
    <div class="modal-body"> 
     <% flash.each do |name, msg| -%> 
      <%= content_tag :div, msg, class: name %> 
     <% end -%> 
     <%= form_tag('/users/new', method: :get, remote: true) do -%> 
      <%= text_field_tag 'user_email', nil, placeholder: 'Insert user email', class: 'form-control' %> 
      <%= submit_tag 'Get user information', remote: true, class: 'btn btn-default' %> 
     <% end -%> 
    </div> 
    </div> 
</div> 

그것은 사용자가 서버를 조회하고 해당 사용자가 존재하는지 여부를 확인하기 위해 이메일을 입력하는 텍스트 상자를 가지고 그것을 않는 경우, : 나는 다음과 모달을 표시 할 수 있도록

은 내가 user_query 행동이 , new 사용자 작업으로 리디렉션하고, 발견 된 사용자 정보를 전송합니다. 그렇지 않으면, 사용자 정보 전자 메일을 찾을 수 없다는 오류를 표시하고 싶습니다.

다음과 같이 사용자가 email을 통보 한 후 나는이 검증을 수행하기 위해 만든 동작은,의 authenticate_user_email입니다 :

def authenticate_user_email 
    respond_to do |format| 
    if authenticated_user = Devise::LDAP::Adapter.get_ldap_entry(params[:user_email]) 
     format.html { redirect_to action: :new, authenticated_user: authenticated_user } 
    else 
     format.json { render json: 'User email not found', status: :not_found } 
    end 
    end 
end 

을하지만 나는이의 after_actionauthenticate_user_email를 설정하는 작업을 얻을 수 없었다, user_query이 올바른 접근 방법인지는 알 수 없으므로 물어 보는 이유는 무엇입니까?이 유효성 검사를 설정하는 올바른 방법은 무엇입니까 (모든 동작이 모달 내에서 렌더링된다는 것을 명심하십시오)?

감사합니다.

+0

당신이 봤어 제안 된 변경

또한 authenticated_user == Devise::LDAP::Adapter.get_ldap_entry(params[:user_email])

authenticated_user = Devise::LDAP::Adapter.get_ldap_entry(params[:user_email])

에서 authenticate_user_email 방법에 if 조건이있다 [ Active Record Validations] (http : //guides.rub yonrails.org/v4.2/active_record_validations.html)? – lurker

+0

예, 그렇지만 AR 유효성 검사는 데이터를 데이터베이스에 저장하기 전에 유효성을 검사하는 것이 아닙니다. 이 경우 실제로 데이터를 저장하지 않고 사용자가 회사에 있는지 확인한 다음 응용 프로그램 측에서 추가 정보를 얻을 수 있습니다 (또는 아님). –

답변

0

는 @lurker로 Active Record Validation에서 보면

+0

'authenticated_user'가'LDAP :: Adapter'에 의해 발견 된 (또는 그렇지 않은) 사용자와 동일한지를 검증하는 것이 아니라,'LDAP :: Adapter'에 의해 사용자가 발견되었는지를 검사하는 것입니다 그 결과를'authenticated_user' 변수에 할당합니다. –

관련 문제