Class: SessionsController

Inherits:
BaseController show all
Defined in:
app/controllers/sessions_controller.rb

Overview

This controller handles the login/logout function of the site.

Instance Method Summary collapse

Methods inherited from BaseController

#advertise, #cache_action?, #css_help, #footer_content, #homepage_features, #plaxo, #rss_site_index, #site_index

Methods included from LocalizedApplication

#get_matching_ui_locale, #get_sorted_langs_from_accept_header, #get_valid_lang_from_accept_header, #set_locale

Methods included from AuthenticatedSystem

#login_by_token, #update_last_seen_at

Instance Method Details

#createObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/sessions_controller.rb', line 15

def create
  @user_session = UserSession.new(:login => params[:email], :password => params[:password], :remember_me => params[:remember_me])

  if @user_session.save

    current_user = @user_session.record #if current_user has been called before this, it will ne nil, so we have to make to reset it
    
    flash[:notice] = :thanks_youre_now_logged_in.l
    redirect_back_or_default(dashboard_user_path(current_user))
  else
    flash[:notice] = :uh_oh_we_couldnt_log_you_in_with_the_username_and_password_you_entered_try_again.l
    render :action => :new
  end
end

#destroyObject



30
31
32
33
34
35
# File 'app/controllers/sessions_controller.rb', line 30

def destroy
  current_user_session.destroy
  reset_session
  flash[:notice] = :youve_been_logged_out_hope_you_come_back_soon.l
  redirect_to new_session_path
end

#indexObject



6
7
8
# File 'app/controllers/sessions_controller.rb', line 6

def index
  redirect_to :action => "new"
end

#newObject



10
11
12
13
# File 'app/controllers/sessions_controller.rb', line 10

def new
  redirect_to user_path(current_user) and return if current_user
  @user_session = UserSession.new
end