Sha256: 2137aef59b35fc6da4ec539114974ad515a3d8c8bc2235a07764bb75685f8f5b

Contents?: true

Size: 1.36 KB

Versions: 2

Compression:

Stored size: 1.36 KB

Contents

class <%= session_plural_class_name %>Controller < ApplicationController
<%- if options[:authlogic] -%>
  def new
    @<%= session_singular_name %> = <%= session_class_name %>.new
  end
  
  def create
    @<%= session_singular_name %> = <%= session_class_name %>.new(params[:<%= session_singular_name %>])
    if @<%= session_singular_name %>.save
      flash[:notice] = t('flash_notice_logged_in')
      redirect_to_target_or_default(root_path)
    else
      flash.now[:error] = t('flash_error_invalid_login')
      render :action => 'new'
    end
  end
  
  def destroy
    @<%= session_singular_name %> = <%= session_class_name %>.find
    @<%= session_singular_name %>.destroy
    flash[:notice] = t('flash_notice_logged_out')
    redirect_to root_path
  end
<%- else -%>
  def new
  end
  
  def create
    <%= user_singular_name %> = <%= user_class_name %>.authenticate(params[:login], params[:password])
    if <%= user_singular_name %>
      session[:<%= user_singular_name %>_id] = <%= user_singular_name %>.id
      flash[:notice] = t('flash_notice_logged_in')
      redirect_to_target_or_default(root_path)
    else
      flash.now[:error] = t('flash_error_invalid_login')
      render :action => 'new'
    end
  end
  
  def destroy
    session[:<%= user_singular_name %>_id] = nil
    flash[:notice] = t('flash_notice_logged_out')
    redirect_to root_path
  end
<%- end -%>
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
splendeo-generators-0.3.1 rails_generators/splendeo_authentication/templates/sessions_controller.rb
splendeo-generators-0.3.0 rails_generators/splendeo_authentication/templates/sessions_controller.rb