Sha256: 75cfd5eacd4cba41907bc2cdffd02115b34703f3458d7fde58834416d3f4fff8

Contents?: true

Size: 937 Bytes

Versions: 8

Compression:

Stored size: 937 Bytes

Contents

class SessionsController < ApplicationController

  def new
    redirect_to root_path if current_user
  end

  def create
    user = User.find_by_email(params[:email])
    set_target_page
    if user && user.authenticate(params[:password])
      if params[:remember_me]
        cookies.permanent[:auth_token] = user.auth_token
      else
        cookies[:auth_token] = user.auth_token
      end
      redirect_to (session[:target_page] || safe_root_url), notice: t('authentication.login_confirmation')
      session[:target_page] = nil
    else
      flash.now.alert = t('authentication.warning.email_or_password_invalid')
      render "new"
    end
  end

  def destroy
    cookies.delete(:auth_token)
    redirect_to safe_root_url, notice: t('authentication.logout_confirmation')
  end
  
  private
  
  def set_target_page
    session[:target_page] = request.referer unless session[:target_page] # && !request.referer.nil?
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
tkh_authentication-0.1.8 app/controllers/sessions_controller.rb
tkh_authentication-0.9.2 app/controllers/sessions_controller.rb
tkh_authentication-0.9.1 app/controllers/sessions_controller.rb
tkh_authentication-0.9 app/controllers/sessions_controller.rb
tkh_authentication-0.1.7 app/controllers/sessions_controller.rb
tkh_authentication-0.1.6 app/controllers/sessions_controller.rb
tkh_authentication-0.1.5 app/controllers/sessions_controller.rb
tkh_authentication-0.1.3 app/controllers/sessions_controller.rb