Class: AutoAuth::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/auto_auth/install_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

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.timestamped_migrations
    Time.now.utc.strftime("%Y%m%d%H%M%S")
  else
    "%.3d" % (current_migration_number(dirname) + 1)
  end
end

.source_rootObject



8
9
10
# File 'lib/generators/auto_auth/install_generator.rb', line 8

def self.source_root
  File.expand_path(File.join(File.dirname(__FILE__), "..", "templates"))
end

Instance Method Details

#add_gemsObject



25
26
27
28
# File 'lib/generators/auto_auth/install_generator.rb', line 25

def add_gems
  gem "bcrypt"
  gem "responders"
end

#create_controller_filesObject



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_filesObject



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_filesObject



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_filesObject



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_routesObject



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_filesObject



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_authenticationObject



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"