Class: CmAdmin::Generators::AddAuthenticationGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/cm_admin/add_authentication_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_authenticationObject

This generator is used to add authentication, if no auth system is present. Adds authentication through devise and sets up the current user.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/generators/cm_admin/add_authentication_generator.rb', line 10

def add_authentication
  gem "devise"
  generate "devise:install"
  model_name = ask("What would you like the user model to be called? [user]")
  generate "devise", model_name
  rake "db:migrate"
  copy_file 'application_controller.rb', 'app/controllers/cm_admin/application_controller.rb'
  gsub_file 'app/controllers/cm_admin/application_controller.rb', 'authenticate_user', "authenticate_#{model_name}"
  copy_file 'authentication.rb', 'app/controllers/concerns/authentication.rb'
  gsub_file 'app/controllers/concerns/authentication.rb', 'current_user', "current_#{model_name}"
  copy_file 'current.rb', 'app/models/current.rb'
  inject_into_file "app/models/#{model_name.underscore}.rb", before: "end\n" do <<-'RUBY'
  # Remove this once role is setup and mentioned in zcm_admin.rb
  def super_admin?
    true
  end
  RUBY
  end
end