Class: AutoAuth::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- AutoAuth::InstallGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/auto_auth/install_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_gems ⇒ Object
- #create_controller_files ⇒ Object
- #create_mailer_files ⇒ Object
- #create_migration_files ⇒ Object
- #create_model_files ⇒ Object
- #create_routes ⇒ Object
- #create_view_files ⇒ Object
- #include_authentication ⇒ Object
Class Method Details
.next_migration_number(dirname) ⇒ Object
:nodoc:
12 13 14 15 16 17 18 |
# File 'lib/generators/auto_auth/install_generator.rb', line 12 def self.next_migration_number(dirname) #:nodoc: if ActiveRecord::Base. Time.now.utc.strftime("%Y%m%d%H%M%S") else "%.3d" % (current_migration_number(dirname) + 1) end end |
.source_root ⇒ Object
8 9 10 |
# File 'lib/generators/auto_auth/install_generator.rb', line 8 def self.source_root File.(File.join(File.dirname(__FILE__), "..", "templates")) end |
Instance Method Details
#add_gems ⇒ Object
25 26 27 28 |
# File 'lib/generators/auto_auth/install_generator.rb', line 25 def add_gems gem "bcrypt" gem "responders" end |
#create_controller_files ⇒ Object
37 38 39 40 41 |
# File 'lib/generators/auto_auth/install_generator.rb', line 37 def create_controller_files template "controllers/sessions_controller.rb", "app/controllers/sessions_controller.rb" template "controllers/passwords_controller.rb", "app/controllers/passwords_controller.rb" template "controllers/registrations_controller.rb", "app/controllers/registrations_controller.rb" end |
#create_mailer_files ⇒ Object
43 44 45 46 47 48 |
# File 'lib/generators/auto_auth/install_generator.rb', line 43 def create_mailer_files template "mailers/identity_mailer.rb", "app/mailers/#{identity_model}_mailer.rb" template "views/mailers/reset_password.html.erb", "app/views/#{identity_model}_mailer/reset_password.html.erb" template "views/mailers/confirm_email.html.erb", "app/views/#{identity_model}_mailer/confirm_email.html.erb" end |
#create_migration_files ⇒ Object
64 65 66 |
# File 'lib/generators/auto_auth/install_generator.rb', line 64 def create_migration_files migration_template "migration.rb", "db/migrate/create_#{domain_model}_and_#{identity_model}.rb" end |
#create_model_files ⇒ Object
30 31 32 33 34 35 |
# File 'lib/generators/auto_auth/install_generator.rb', line 30 def create_model_files template "models/domain_model.rb", "app/models/#{domain_model}.rb" template "models/identity_model.rb", "app/models/#{identity_model}.rb" template "models/registration.rb", "app/models/registration.rb" template "models/concerns/token_verification.rb", "app/models/concerns/token_verification.rb" end |
#create_routes ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/generators/auto_auth/install_generator.rb', line 50 def create_routes route "resources :registrations, only: [:create] do\nget :confirm, on: :collection\n end\n REGISTRATION_ROUTE\n route \"resources :passwords, only: [:edit, :create, :update]\"\n route \"resources :sessions, only: [:create]\"\n route \"get :forgot_password, to: 'passwords#new'\"\n route \"get :sign_up, to: 'registrations#new'\"\n route \"get :sign_out, to: 'sessions#destroy'\"\n route \"get :sign_in, to: 'sessions#new'\"\nend\n" |
#create_view_files ⇒ Object
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/generators/auto_auth/install_generator.rb', line 90 def create_view_files template "views/sessions/new.html.erb", "app/views/sessions/new.html.erb" template "views/passwords/new.html.erb", "app/views/passwords/new.html.erb" template "views/passwords/edit.html.erb", "app/views/passwords/edit.html.erb" template "views/registrations/new.html.erb", "app/views/registrations/new.html.erb" template "config/locales/auto_auth.en.yml", "config/locales/auto_auth.en.yml" end |
#include_authentication ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/generators/auto_auth/install_generator.rb', line 68 def include_authentication template "controllers/concerns/authentication.rb", "app/controllers/concerns/authentication.rb" inject_into_file "app/controllers/application_controller.rb", after: /protect_from_forgery.*$/ do "\n\n include Authentication\n\n before_action :authenticate!\n\n rescue_from ActiveSupport::MessageVerifier::InvalidSignature, with: :handle_invalid_signature\n\n\n private\n\n def handle_invalid_signature\nredirect_to(root_path, alert: t(:'auto_auth.application.invalid_signature'))\n end\n AUTOAUTH\n end\nend\n" |