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?, #footer_content, #homepage_features, #plaxo, #rss_site_index, #site_index

Methods included from BaseHelper

#add_friend_link, #ajax_spinner_for, #avatar_for, #block_to_partial, #box, #city_cloud, #clippings_link, #commentable_url, #container_title, #excerpt_with_jump, #flash_class, #forum_page?, #is_current_user_and_featured?, #jumbotron, #last_active, #more_comments_links, #page_title, #paginating_links, #possesive, #profile_completeness, #render_jumbotron, #render_widgets, #rounded, #search_posts_title, #search_user_posts_path, #show_footer_content?, #tag_auto_complete_field, #time_ago_in_words, #time_ago_in_words_or_date, #topnav_tab, #truncate_words, #truncate_words_with_highlight, #widget

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
# 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
    self.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, :email => params[:email]
  end
end

#destroyObject



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

def destroy
  redirect_to new_session_path and return if current_user_session.nil?
  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