laredotornado-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org
2008-Jan-30 15:40 UTC
Where can I get "authenticate_with_http_basic"?
Hi,
I just installed Rails 2.0.2
[root@mymachine easyx]# ruby --version
ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-linux]
[root@mymachine easyrx]# gem install rails --include-dependencies
Need to update 16 gems from http://gems.rubyforge.org
................
complete
Successfully installed rails-2.0.2
[root@remandev easyrx]#
But I''m getting this error in my restful_authentication plugin:
NoMethodError in RegisterController#start
undefined method `authenticate_with_http_basic'' for
#<RegisterController:0xb7578750>
RAILS_ROOT: ./script/../config/..
Application Trace | Framework Trace | Full Trace
/usr/local/apache2/htdocs/easyrx/lib/authenticated_system.rb:102:in
`login_from_basic_auth''
/usr/local/apache2/htdocs/easyrx/lib/authenticated_system.rb:12:in
`current_user''
/usr/local/apache2/htdocs/easyrx/lib/authenticated_system.rb:6:in
`logged_in?''
/usr/local/apache2/htdocs/easyrx/app/controllers/
register_controller.rb:41:in `start''
How can I troubleshoot this? Below is the code for my
autehnticated_system.rb file, installed by the plugin. - Dave
====================begin
authenticated_system.rb===========================module AuthenticatedSystem
protected
# Returns true or false if the user is logged in.
# Preloads @current_user with the user model if they''re logged in.
def logged_in?
current_user != :false
end
# Accesses the current user from the session. Set it to :false if
login fails
# so that future calls do not hit the database.
def current_user
@current_user ||= (login_from_session || login_from_basic_auth
|| login_from_cookie || :false)
end
# Store the given user id in the session.
def current_user=(new_user)
session[:user_id] = (new_user.nil? || new_user.is_a?(Symbol)) ?
nil : new_user.id
@current_user = new_user || :false
end
# Check if the user is authorized
#
# Override this method in your controllers if you want to restrict
access
# to only a few actions or if you want to check if the user
# has the correct rights.
#
# Example:
#
# # only allow nonbobs
# def authorized?
# current_user.login != "bob"
# end
def authorized?
logged_in?
end
# Filter method to enforce a login requirement.
#
# To require logins for all actions, use this in your controllers:
#
# before_filter :login_required
#
# To require logins for specific actions, use this in your
controllers:
#
# before_filter :login_required, :only => [ :edit, :update ]
#
# To skip this in a subclassed controller:
#
# skip_before_filter :login_required
#
def login_required
authorized? || access_denied
end
# Redirect as appropriate when an access request fails.
#
# The default action is to redirect to the login screen.
#
# Override this method in your controllers if you want to have
special
# behavior in case the user is not authorized
# to access the requested action. For example, a popup window
might
# simply close itself.
def access_denied
respond_to do |format|
format.html do
store_location
redirect_to new_session
end
format.xml do
request_http_basic_authentication ''Web Password''
end
end
end
# Store the URI of the current request in the session.
#
# We can return to this location by calling
#redirect_back_or_default.
def store_location
session[:return_to] = request.request_uri
end
# Redirect to the URI stored by the most recent store_location
call or
# to the passed default.
def redirect_back_or_default(default)
redirect_to(session[:return_to] || default)
session[:return_to] = nil
end
# Inclusion hook to make #current_user and #logged_in?
# available as ActionView helper methods.
def self.included(base)
base.send :helper_method, :current_user, :logged_in?
end
# Called from #current_user. First attempt to login by the user
id stored in the session.
def login_from_session
self.current_user = User.find(session[:user_id]) if
session[:user_id]
end
# Called from #current_user. Now, attempt to login by basic
authentication information.
def login_from_basic_auth
authenticate_with_http_basic do |username, password|
self.current_user = User.authenticate(username, password)
end
end
# Called from #current_user. Finaly, attempt to login by an
expiring token in the cookie.
def login_from_cookie
user = cookies[:auth_token] &&
User.find_by_remember_token(cookies[:auth_token])
if user && user.remember_token?
user.remember_me
cookies[:auth_token] = { :value =>
user.remember_token, :expires => user.remember_token_expires_at }
self.current_user = user
end
end
end
==========================end authenticated_system.rb
file=======================
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Is RAILS_GEM_VERSION (in environment.rb) is pointing to an older version of Rails? That could be the source of your troubles. On Jan 30, 10:40 am, "laredotorn...-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org" <laredotorn...-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org> wrote:> Hi, > > I just installed Rails 2.0.2 > > [root@mymachine easyx]# ruby --version > ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-linux] > [root@mymachine easyrx]# gem install rails --include-dependencies > Need to update 16 gems fromhttp://gems.rubyforge.org > ................ > complete > Successfully installed rails-2.0.2 > [root@remandev easyrx]# > > But I''m getting this error in my restful_authentication plugin: > > NoMethodError in RegisterController#start > undefined method `authenticate_with_http_basic'' for > #<RegisterController:0xb7578750> > RAILS_ROOT: ./script/../config/.. > Application Trace | Framework Trace | Full Trace > /usr/local/apache2/htdocs/easyrx/lib/authenticated_system.rb:102:in > `login_from_basic_auth'' > /usr/local/apache2/htdocs/easyrx/lib/authenticated_system.rb:12:in > `current_user'' > /usr/local/apache2/htdocs/easyrx/lib/authenticated_system.rb:6:in > `logged_in?'' > /usr/local/apache2/htdocs/easyrx/app/controllers/ > register_controller.rb:41:in `start'' > > How can I troubleshoot this? Below is the code for my > autehnticated_system.rb file, installed by the plugin. - Dave > > ====================begin > authenticated_system.rb===========================> module AuthenticatedSystem > protected > # Returns true or false if the user is logged in. > # Preloads @current_user with the user model if they''re logged in. > def logged_in? > current_user != :false > end > > # Accesses the current user from the session. Set it to :false if > login fails > # so that future calls do not hit the database. > def current_user > @current_user ||= (login_from_session || login_from_basic_auth > || login_from_cookie || :false) > end > > # Store the given user id in the session. > def current_user=(new_user) > session[:user_id] = (new_user.nil? || new_user.is_a?(Symbol)) ? > nil : new_user.id > @current_user = new_user || :false > end > > # Check if the user is authorized > # > # Override this method in your controllers if you want to restrict > access > # to only a few actions or if you want to check if the user > # has the correct rights. > # > # Example: > # > # # only allow nonbobs > # def authorized? > # current_user.login != "bob" > # end > def authorized? > logged_in? > end > > # Filter method to enforce a login requirement. > # > # To require logins for all actions, use this in your controllers: > # > # before_filter :login_required > # > # To require logins for specific actions, use this in your > controllers: > # > # before_filter :login_required, :only => [ :edit, :update ] > # > # To skip this in a subclassed controller: > # > # skip_before_filter :login_required > # > def login_required > authorized? || access_denied > end > > # Redirect as appropriate when an access request fails. > # > # The default action is to redirect to the login screen. > # > # Override this method in your controllers if you want to have > special > # behavior in case the user is not authorized > # to access the requested action. For example, a popup window > might > # simply close itself. > def access_denied > respond_to do |format| > format.html do > store_location > redirect_to new_session > end > format.xml do > request_http_basic_authentication ''Web Password'' > end > end > end > > # Store the URI of the current request in the session. > # > # We can return to this location by calling > #redirect_back_or_default. > def store_location > session[:return_to] = request.request_uri > end > > # Redirect to the URI stored by the most recent store_location > call or > # to the passed default. > def redirect_back_or_default(default) > redirect_to(session[:return_to] || default) > session[:return_to] = nil > end > > # Inclusion hook to make #current_user and #logged_in? > # available as ActionView helper methods. > def self.included(base) > base.send :helper_method, :current_user, :logged_in? > end > > # Called from #current_user. First attempt to login by the user > id stored in the session. > def login_from_session > self.current_user = User.find(session[:user_id]) if > session[:user_id] > end > > # Called from #current_user. Now, attempt to login by basic > authentication information. > def login_from_basic_auth > authenticate_with_http_basic do |username, password| > self.current_user = User.authenticate(username, password) > end > end > > # Called from #current_user. Finaly, attempt to login by an > expiring token in the cookie. > def login_from_cookie > user = cookies[:auth_token] && > User.find_by_remember_token(cookies[:auth_token]) > if user && user.remember_token? > user.remember_me > cookies[:auth_token] = { :value => > user.remember_token, :expires => user.remember_token_expires_at } > self.current_user = user > end > end > end > ==========================end authenticated_system.rb > file=======================--~--~---------~--~----~------------~-------~--~----~You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
laredotornado-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org
2008-Jan-30 18:51 UTC
Re: Where can I get "authenticate_with_http_basic"?
That was it. RAILS_GEM_VERSION was pointing to 1.2. 5 stars, - Dave On Jan 30, 9:43 am, Pat Nakajima <patnakaj...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Is RAILS_GEM_VERSION (in environment.rb) is pointing to an older > version of Rails? That could be the source of your troubles. > > On Jan 30, 10:40 am, "laredotorn...-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org" > > > > <laredotorn...-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org> wrote: > > Hi, > > > I just installed Rails 2.0.2 > > > [root@mymachine easyx]# ruby --version > > ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-linux] > > [root@mymachine easyrx]# gem install rails --include-dependencies > > Need to update 16 gems fromhttp://gems.rubyforge.org > > ................ > > complete > > Successfully installed rails-2.0.2 > > [root@remandev easyrx]# > > > But I''m getting this error in my restful_authentication plugin: > > > NoMethodError in RegisterController#start > > undefined method `authenticate_with_http_basic'' for > > #<RegisterController:0xb7578750> > > RAILS_ROOT: ./script/../config/.. > > Application Trace | Framework Trace | Full Trace > > /usr/local/apache2/htdocs/easyrx/lib/authenticated_system.rb:102:in > > `login_from_basic_auth'' > > /usr/local/apache2/htdocs/easyrx/lib/authenticated_system.rb:12:in > > `current_user'' > > /usr/local/apache2/htdocs/easyrx/lib/authenticated_system.rb:6:in > > `logged_in?'' > > /usr/local/apache2/htdocs/easyrx/app/controllers/ > > register_controller.rb:41:in `start'' > > > How can I troubleshoot this? Below is the code for my > > autehnticated_system.rb file, installed by the plugin. - Dave > > > ====================begin > > authenticated_system.rb===========================> > module AuthenticatedSystem > > protected > > # Returns true or false if the user is logged in. > > # Preloads @current_user with the user model if they''re logged in. > > def logged_in? > > current_user != :false > > end > > > # Accesses the current user from the session. Set it to :false if > > login fails > > # so that future calls do not hit the database. > > def current_user > > @current_user ||= (login_from_session || login_from_basic_auth > > || login_from_cookie || :false) > > end > > > # Store the given user id in the session. > > def current_user=(new_user) > > session[:user_id] = (new_user.nil? || new_user.is_a?(Symbol)) ? > > nil : new_user.id > > @current_user = new_user || :false > > end > > > # Check if the user is authorized > > # > > # Override this method in your controllers if you want to restrict > > access > > # to only a few actions or if you want to check if the user > > # has the correct rights. > > # > > # Example: > > # > > # # only allow nonbobs > > # def authorized? > > # current_user.login != "bob" > > # end > > def authorized? > > logged_in? > > end > > > # Filter method to enforce a login requirement. > > # > > # To require logins for all actions, use this in your controllers: > > # > > # before_filter :login_required > > # > > # To require logins for specific actions, use this in your > > controllers: > > # > > # before_filter :login_required, :only => [ :edit, :update ] > > # > > # To skip this in a subclassed controller: > > # > > # skip_before_filter :login_required > > # > > def login_required > > authorized? || access_denied > > end > > > # Redirect as appropriate when an access request fails. > > # > > # The default action is to redirect to the login screen. > > # > > # Override this method in your controllers if you want to have > > special > > # behavior in case the user is not authorized > > # to access the requested action. For example, a popup window > > might > > # simply close itself. > > def access_denied > > respond_to do |format| > > format.html do > > store_location > > redirect_to new_session > > end > > format.xml do > > request_http_basic_authentication ''Web Password'' > > end > > end > > end > > > # Store the URI of the current request in the session. > > # > > # We can return to this location by calling > > #redirect_back_or_default. > > def store_location > > session[:return_to] = request.request_uri > > end > > > # Redirect to the URI stored by the most recent store_location > > call or > > # to the passed default. > > def redirect_back_or_default(default) > > redirect_to(session[:return_to] || default) > > session[:return_to] = nil > > end > > > # Inclusion hook to make #current_user and #logged_in? > > # available as ActionView helper methods. > > def self.included(base) > > base.send :helper_method, :current_user, :logged_in? > > end > > > # Called from #current_user. First attempt to login by the user > > id stored in the session. > > def login_from_session > > self.current_user = User.find(session[:user_id]) if > > session[:user_id] > > end > > > # Called from #current_user. Now, attempt to login by basic > > authentication information. > > def login_from_basic_auth > > authenticate_with_http_basic do |username, password| > > self.current_user = User.authenticate(username, password) > > end > > end > > > # Called from #current_user. Finaly, attempt to login by an > > expiring token in the cookie. > > def login_from_cookie > > user = cookies[:auth_token] && > > User.find_by_remember_token(cookies[:auth_token]) > > if user && user.remember_token? > > user.remember_me > > cookies[:auth_token] = { :value => > > user.remember_token, :expires => user.remember_token_expires_at } > > self.current_user = user > > end > > end > > end > > ==========================end authenticated_system.rb > > file========================- Hide quoted text - > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Reasonably Related Threads
- Re: Re stful_authentication, Internet Explorer, and unwanted http basic dialog
- Facebooker and existing website?
- Restful Authentication Uninitialized Constant in Production...
- why is authenticate_with_http_basic undefined?
- Help with error - uninitialized constant AuthenticatedSystem::Base64