cours0708/P5B/ruby/mon_projet/app/controllers/sessions_controller.rb

32 lines
974 B
Ruby
Raw Permalink Normal View History

2008-11-25 21:11:16 +00:00
# This controller handles the login/logout function of the site.
class SessionsController < ApplicationController
# Be sure to include AuthenticationSystem in Application Controller instead
include AuthenticatedSystem
# render new.rhtml
def new
end
def create
self.current_utilisateur = Utilisateur.authenticate(params[:login], params[:password])
if logged_in?
if params[:remember_me] == "1"
self.current_utilisateur.remember_me
cookies[:auth_token] = { :value => self.current_utilisateur.remember_token , :expires => self.current_utilisateur.remember_token_expires_at }
end
redirect_back_or_default('/')
flash[:notice] = "Logged in successfully"
else
render :action => 'new'
end
end
def destroy
self.current_utilisateur.forget_me if logged_in?
cookies.delete :auth_token
reset_session
flash[:notice] = "You have been logged out."
redirect_back_or_default('/')
end
end