2012-06-21 5 views
0

저는 개발중인 웹 앱용 API를 구축하고 있으며 API 인증/로그인에 사용하려는 다음 코드는 인증시 false를 반환합니다. 내 API 사용자 컨트롤러에서Ruby on rails .authentication fail

나는이 : 그것은 항상 유효한 이메일 주소와 암호가 제공되는 경우에도, 거짓 @auth로 응답

def login 
    if params[:user] 
    # Find the user by email first 
    @user = User.where(email: params[:user][:email]).first 
    if [email protected] 
     respond_with nil 
    else 
     @auth = @user.authenticate(params[:user][:password]) 
     if @auth 
     respond_with @user 
     else 
     respond_with @auth 
     end 
    end 
    end 
end 

. Mongo db에서 사용자 정보를 가져 오는 데는 아무런 문제가 없습니다.

나는 .authenticate가하는 일에 대해 명확하지 않다. 내가 본 Railscast.com 비디오에 따르면, 사용자 암호를 입력 한 암호와 비교해야합니다. 사용자에게 유효한 암호가 제공되면 @auth는 항상 false입니다.

+0

은 railscast # 250에서 가져온 것입니까? 그렇다면 인증 기능에 전자 메일을 전달할 필요도 없습니까? –

답변

0

이 방법은 실제로 작동했습니다. 데이터베이스의 테스트 데이터는 내가 생각한 것과 다릅니다.