To Implement Remember me functionality

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.

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 P.

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 #

Dhaval P. 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 S…

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

Ruchita S. wrote:

Dhaval P. 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 S…

Hi,

The above code is giving error :undefined method `redirect_back’ for
login controller.

Please help me out.

`redirect_back’ is defined in authenticated_system.rb check it out

Dhaval P. wrote:

`redirect_back’ is defined in authenticated_system.rb check it out

Yeah… 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 S…

can you please put the code here which you are using? or which is giving
error

instead of this redirect_back(:controller => “login” , :action =>
“index”)

write redirect_back(:controller => ‘login’ , :action => ‘index’)
problem with quotes…

Dhaval P. wrote:

can you please put the code here which you are using? or which is giving
error
yeah 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 *
(606024)) }
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

Dhaval P. 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.

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… :frowning:

Dhaval P. 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… :frowning:

Okie…Not an issue.

Thanks for the help… :frowning: