Sha256: 44e65c004223a17ad331d9e15ca77617e7f67ffb894891af1cb62c670728d866

Contents?: true

Size: 1.71 KB

Versions: 1

Compression:

Stored size: 1.71 KB

Contents

module I0n
  module Generators
    class AuthenticationGenerator < Rails::Generators::Base

      source_root File.expand_path('../templates', __FILE__)

      def gemfile
        gem("bcrypt-ruby")  
      end

      def setup_application
        application do
          '
    # Configure sensitive parameters which will be filtered from the log file.
    config.filter_parameters += [:password, :password_confirmation]

    config.autoload_paths += %W(#{Rails.root}/lib)
          '
        end  
      end

      def create_authentication_lib_and_include_in_application_helper
        copy_file "lib/authentication.rb", "#{Rails.root}/lib/authentication.rb" 
        inject_into_class("app/controllers/application_controller.rb", "include Authentication")
      end

      def create_routes
        route("match 'register' => 'users#new', :as => :register")
        route("resources :users")    
        route("resources :user_sessions, :only => [:new, :create, :destroy]")
        route("match 'login' => 'user_sessions#new', :as => :login")
        route("match 'logout' => 'user_sessions#destroy', :as => :logout")
      end

      def create_models
        generate("model", "user email:string password_hash:string password_salt:string")
      end
      
      def create_controllers
        generate("controller", "user_sessions")   
        generate("controller", "users")
        inject_into_class("app/controllers/users_controller.rb", IO.read("#{AuthenticationGenerator.source_root}/app/controllers/_users_controller.rb")) 
      end

      def create_views
        directory "app/views/users", "#{Rails.root}/app/views/users"
        directory "app/view/user_sessions", "#{Rails.root}/app/views/user_sessions" 
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
i0n_rails3_generators-0.2.13 lib/generators/i0n/authentication/authentication_generator.rb