2014-04-12 4 views
0

페이스 북을 성공적으로 통합했습니다. 로그인하십시오. 문제는 페이스 북을 통해 사용자가 로그인 할 때 등록되지 않은 경우 DB에 사용자를 생성한다는 것입니다. 이것은 좋을 것이지만 그들이 정기적으로 (즉, 내 페이지에 로그인 할 때) 로그인 할 수 없다면 실제로는 암호를 생성하지 않았기 때문에 불가능합니다.페이스 북과 보통 로그인 충돌

저도 저장했기 때문에 페이스 북 이메일로 계정을 만들 수 없습니다.

@ magnum2002 님의 도움 덕분에 며칠 후, before_filter를 사용하여 비밀번호가 있는지 확인하고 싶습니다. 문제는 그들이 페이스 북을 통해 로그인 한 경우에도 하나가 있습니다. 그래서 내가 가진 아이디어는 "create_pw"라는 사용자 db에 다른 열을 만드는 것이 었습니다. 사용자가 실제로 암호를 만든 양식의 숨겨진 필드를 사용하고이를 true로 설정합니다. 이렇게하면 사용자가 기존의 방법을 사용하여 서명하면 내 DB에서 암호를 생성했음을 알게됩니다. 그런 다음 before_filter를 설정하여이 열이 채워 졌는지 확인하십시오. 이 테스트를 통해 크롬 개발자 도구에서 숨겨진 필드를 편집 할 수 있다는 것을 알았습니다. 이 정보를 실제로 편집 할 수 없으면 서버에 전달할 수 있습니까?

그럼 난

class OmniauthCallbacksController < Devise::OmniauthCallbacksController 
    def facebook  
    @user = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user)  
    if @user.persisted?  
    sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated 
     set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format? 
    else 
     session["devise.facebook_data"] = request.env["omniauth.auth"] 
     redirect_to new_user_registration_url 
    end 
    end 
end 

다음은 주석겠습니까 내 응용 프로그램 컨트롤러

class ApplicationController < ActionController::Base 
protect_from_forgery with: :exception 
def after_sign_in_path_for(resource) 
    #if current_user haspassword_from_previous_registration? 
    request.env['omniauth.origin'] || stored_location_for(resource) || root_path 
    #else 
     # request.env['omniauth.origin'] || stored_location_for(resource) || current_user_edit_path 
    #end 
end 
end 

의 ...

user.rb 
    def self.find_for_facebook_oauth(auth, signed_in_resource=nil) 
    user = User.where(:provider => auth.provider, :uid => auth.uid).first 
    if user 
     return user 
    else 
     registered_user = User.where(:email => auth.info.email).first 
     if registered_user 
     return registered_user 
     else 
     user = User.create( 
          name:auth.extra.raw_info.name, 
          provider:auth.provider, 
          uid:auth.uid, 
          email:auth.info.email, 
          password:Devise.friendly_token[0,20], 
         ) 
     end  
    end 
end 

end 

어쩌면 내가 콜백에서 그렇게 할 수 매그넘의 제안을 계속한다 위의 코드는 응용 프로그램 컨트롤러에서 올바른 아이디어일까요?

+1

암호를 넣으려는 페이지로 이동하는 응용 프로그램 컨트롤러에서 필터를 작성하면 암호를 사용하여 계정을 업데이트 할 때까지 어떤 페이지로도 이동할 수 없습니다. – rmagnum2002

+0

어떻게하면됩니까? devise friendly 토큰과 사용자 설정 암호를 구분하는 if 문 – Peege151

답변

1

before_filterapplication_controller 사용자가 암호가없는 경우 사용자를 update_password 페이지로 리디렉션합니다.

http://apidock.com/rails/ActionController/Filters/ClassMethods/before_filter

또한 우리가 암호를 업데이트 할 양식을 표시 할 수 있습니다 방법에 대한 skip_before_filter가 필요합니다.

예 :

application_controller.rb

before_filter :redirect_if_no_password 


def redirect_if_no_password 
    redirect_to update_password_path if current_user.password.empty 
end 

home_controller.rb

skip_before_filter :redirect_if_no_password, only: :update_password 

def update_password 
end 

는 관련이없는 행동이 필터를 건너도해야합니다 연락처 페이지 또는 의견 보내기 페이지와 같은 현재 사용자 이자형.

+0

그러나이 장치는 친숙한 토큰을 비밀로 받아 들일 수 있습니까? – Peege151

+0

친절한 토큰을 만드는 것이 무엇을 의미합니까? – rmagnum2002

+0

또한 CodeClimate가 할 수있는 것처럼 github에 가입 한 후 로그인 할 때 사용할 수있는 생성 된 비밀번호가 포함 된 전자 메일을 보내고 나중에 계정 설정에서 변경하도록 권합니다. – rmagnum2002

관련 문제