Hi all, I am trying to implement the functionality of Remember Me. The requirement is that once the user closes the browser after checking the remember me check box, it should return to the login page with username and password fields to be filled into the text boxes and the checkbox button checked, so that there is no need to fill all the fields. I am not able to fill the text boxes with user name and password fields. Any help would be greatly appreciated. Thanks, Ruchita. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
this facility is provided in act_as_authenticated plugin if u want to do it by defining that in a method then u can do something like return unless request.post? self.current_user = User.authenticate(params[:login], params[:password]) flash[:notice] = "Logged in successfully" if current_user # if params[:remember_me] == "1" # self.current_user.remember_me #cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at } # end #@session[:user]=params[:login] #redirect_to[''REQUEST_URI''] redirect_back_or_default(:controller => ''/projects'', :action => ''list'') flash.now[:notice] = "Incorrect login!" end flash.now[:notice] = "Incorrect login!" end hope this helps Dhaval Parikh -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
return unless request.post? self.current_user = User.authenticate(params[:login], params[:password]) flash[:notice] = "Logged in successfully" if current_user if params[:remember_me] == "1" self.current_user.remember_me cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at } end @session[:user]=params[:login] redirect_to[''REQUEST_URI''] redirect_back_or_default(:controller => ''/projects'', :action => ''list'') flash.now[:notice] = "Incorrect login!" end flash.now[:notice] = "Incorrect login!" end this is the one..i just posted the one with # -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Dhaval Parikh wrote:> return unless request.post? > self.current_user = User.authenticate(params[:login], > params[:password]) > flash[:notice] = "Logged in successfully" > if current_user > if params[:remember_me] == "1" > self.current_user.remember_me > cookies[:auth_token] = { :value => > self.current_user.remember_token , :expires => > self.current_user.remember_token_expires_at } > end > > @session[:user]=params[:login] > redirect_to[''REQUEST_URI''] > redirect_back_or_default(:controller => ''/projects'', :action => > ''list'') > flash.now[:notice] = "Incorrect login!" > end > flash.now[:notice] = "Incorrect login!" > end > > this is the one..i just posted the one with #Hi, Okie.... it means i need to implement plugin acts_as_authenticated. Not able to understand the code redirect_to[''REQUEST_URI'']> redirect_back_or_default(:controller => ''/projects'', :action => > ''list'') > flash.now[:notice] = "Incorrect login!" > end > flash.now[:notice] = "Incorrect login!" > end.Why it is always giving Incorrect login? Can you plz explain me little more. Thanks, Ruchita Sharma. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ruchita Sharma wrote:> Dhaval Parikh wrote: >> return unless request.post? >> self.current_user = User.authenticate(params[:login], >> params[:password]) >> flash[:notice] = "Logged in successfully" >> if current_user >> if params[:remember_me] == "1" >> self.current_user.remember_me >> cookies[:auth_token] = { :value => >> self.current_user.remember_token , :expires => >> self.current_user.remember_token_expires_at } >> end >> >> @session[:user]=params[:login] >> redirect_to[''REQUEST_URI''] >> redirect_back_or_default(:controller => ''/projects'', :action => >> ''list'') >> flash.now[:notice] = "Incorrect login!" >> end >> flash.now[:notice] = "Incorrect login!" >> end >> >> this is the one..i just posted the one with # > > Hi, > > Okie.... it means i need to implement plugin acts_as_authenticated. Not > able to understand the code > redirect_to[''REQUEST_URI''] >> redirect_back_or_default(:controller => ''/projects'', :action => >> ''list'') >> flash.now[:notice] = "Incorrect login!" >> end >> flash.now[:notice] = "Incorrect login!" >> end. > > Why it is always giving Incorrect login? > Can you plz explain me little more. > > Thanks, > Ruchita Sharma.Hi, The above code is giving error :undefined method `redirect_back'' for login controller. Please help me out. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Well first of all i would suggest you to download the plugin from http://agilewebdevelopment.com/plugins/acts_as_authenticated and then implement it. You will better understand the whole concept for it once you implement it. do look @ the authenticated_user.rb under the lib folder -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
`redirect_back'' is defined in authenticated_system.rb check it out -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Dhaval Parikh wrote:> `redirect_back'' is defined in authenticated_system.rb check it outYeah... I have installed the plugin acts_as_authenticated, and i got the method redirect_back in authenticated_system.rb. But still it is giving the error :undefined method `redirect_back''. Shall i need to include plugin in some file? Please do tell me. The plugin is installed in vendor\plugin directory. Thanks, Ruchita Sharma. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
can you please put the code here which you are using? or which is giving error -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Dhaval Parikh wrote:> can you please put the code here which you are using? or which is giving > erroryeah sure.... The code of login method in login controller: def login if user = User.authenticate(params[:user][:login],params[:user][:password]) set_current_user user @userid = current_user.id @user = User.find_by_id(@userid) #render_text @user.login if params[''login''][''secure''] == "1" pid = UUID.random_create.to_s current_user.secure = pid cookies[:secure] = { :value => pid, :expires => Time.now + ( 90 * (60*60*24)) } current_user.save else cookies.delete :secure current_user.secure = nil current_user.save end destination = session[:return_to] || { :controller => ''project'', :action => ''list''} redirect_to destination else flash[:notice] = ''Invalid UserName or Password'' redirect_to :action => ''index'' end end In login controller there is a method named login_form_cookie. if !current_user.nil? && !cookies[:secure].nil? if user = User.find_by_secure(cookies[:secure]) set_current_user user session[:user]=params[:login] redirect_to[''REQUEST_URI''] redirect_back(:controller => "login" , :action => "index") flash.now[:notice] = "Incorrect login!" end flash.now[:notice] = "Incorrect login!" end I am calling this method in index method i.e def index login_from_cookie end -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
instead of this redirect_back(:controller => "login" , :action => "index") write redirect_back(:controller => ''login'' , :action => ''index'') problem with quotes.. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Dhaval Parikh wrote:> instead of this redirect_back(:controller => "login" , :action => > "index") > > write redirect_back(:controller => ''login'' , :action => ''index'') > problem with quotes..Its again giving the same error. What should be done. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I m using the same plugin but then dont know there might be some minor mistake which has occurred which i m not able to figure it out... :( -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Dhaval Parikh wrote:> I m using the same plugin but then dont know there might be some minor > mistake which has occurred which i m not able to figure it out... :(Okie....Not an issue. Thanks for the help..... :( -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---