Sha256: d4b254b5aece45801b97a38dd13610c9659f3c5eaacf31254703ba348773e49e

Contents?: true

Size: 1.84 KB

Versions: 14

Compression:

Stored size: 1.84 KB

Contents

#    This file is part of Branston.
#
#    Branston is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as published by
#    the Free Software Foundation.
#
#    Branston is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with Branston.  If not, see <http://www.gnu.org/licenses/>.

# This controller handles the login/logout function of the site.
class SessionsController < ApplicationController

  layout 'main'

  # render new.rhtml
  def new
  end

  def create
    logout_keeping_session!
    user = User.authenticate(params[:login], params[:password])
    if user
      # Protects against session fixation attacks, causes request forgery
      # protection if user resubmits an earlier form using back
      # button. Uncomment if you understand the tradeoffs.
      # reset_session
      self.current_user = user
      new_cookie_flag = (params[:remember_me] == "1")
      handle_remember_cookie! new_cookie_flag
      redirect_back_or_default('/')
      flash[:notice] = "Logged in successfully"
    else
      note_failed_signin
      @login       = params[:login]
      @remember_me = params[:remember_me]
      render :action => 'new'
    end
  end

  def destroy
    logout_killing_session!
    flash[:notice] = "You have been logged out."
    redirect_back_or_default('/')
  end

protected
  # Track failed login attempts
  def note_failed_signin
    flash[:error] = "Couldn't log you in as '#{params[:login]}'"
    logger.warn "Failed login for '#{params[:login]}' from #{request.remote_ip} at #{Time.now.utc}"
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
branston-0.6.6 lib/branston/app/controllers/sessions_controller.rb
branston-0.6.5 lib/branston/app/controllers/sessions_controller.rb
branston-0.6.4 lib/branston/app/controllers/sessions_controller.rb
branston-0.6.3 lib/branston/app/controllers/sessions_controller.rb
branston-0.6.2 lib/branston/app/controllers/sessions_controller.rb
branston-0.6.1 lib/branston/app/controllers/sessions_controller.rb
branston-0.6.0 lib/branston/app/controllers/sessions_controller.rb
branston-0.5.2 lib/branston/app/controllers/sessions_controller.rb
branston-0.5.1 lib/branston/app/controllers/sessions_controller.rb
branston-0.5.0 lib/branston/app/controllers/sessions_controller.rb
branston-0.4.6 lib/branston/app/controllers/sessions_controller.rb
branston-0.4.5 lib/branston/app/controllers/sessions_controller.rb
branston-0.4.4 lib/branston/app/controllers/sessions_controller.rb
branston-0.4.3 lib/branston/app/controllers/sessions_controller.rb