0
我在Rails上有應用程序。我的身份驗證系統工作正常,但: 1)總是在授權後我去THIS_path 2)如果我沒有通過身份驗證的用戶,但得到,例如/研究頁面,我扔到授權頁後,我拋出pm_root_path,而不是reasearch_root_path。Rails上的身份驗證系統
爲什麼?爲什麼store_location方法不起作用?
我的lib/authenticated_system.rb:
module AuthenticatedSystem
protected
def logged_in?
!!current_user
end
def current_user
@current_user ||= login_from_session unless @current_user == false
@current_user
end
def current_user=(new_user)
session[:user_id] = new_user ? new_user.id : nil
@current_user = new_user || false
end
def authorized?
logged_in?
end
def login_required
authorized? || access_denied
end
def access_denied
respond_to do |format|
format.html do
store_location
redirect_to root_path
end
end
end
def store_location
session[:return_to] = request.request_uri
end
def redirect_back_or_default(default)
redirect_to(session[:return_to] || default)
session[:return_to] = nil
end
def self.included(base)
base.send :helper_method, :current_user, :logged_in?
end
def login_from_session
if session[:user_id]
self.current_user = User.find_by_id(session[:user_id])
self.current_user.last_logged_in = Time.now
self.current_user.save
self.current_user
end
end
末
和我session_controller方法:如果你改變你的redirect_back_to_default提高會話[什麼是顯示
def open_id_authentication(domain=nil)
domain = "" if domain.nil?
complete_identity_url = IDENTITY_URL + domain
authenticate_with_open_id(complete_identity_url, OPENID_OPTS) do |openid_result, identity_url, registration|
if openid_result.successful?
matches = /\/a\/(.*)\/o8/.match(params["openid.op_endpoint"])
google_domain = matches[1] if matches[1]
if valid_account?(google_domain)
account = Account.find_by_google_domain(google_domain)
session[:account_id] = account.id
self.current_user = User.openid_registration(registration, identity_url, account.id)
else
flash[:error] = t('flash.session.domain_not_registered')
redirect_to accounts_path
return false
end
redirect_back_or_default(THIS_path)
else
flash[:error] = t('flash.open_id.authentication_failed')
redirect_to accounts_path
end
end
end