Sha256: 04d9615a095c5060b9bc85346d26f635878439c824856d0f10d4705a5cdf15ea

Contents?: true

Size: 1.26 KB

Versions: 147

Compression:

Stored size: 1.26 KB

Contents

require 'rails/generators'

module CmAdmin
  module Generators
    class AddAuthenticationGenerator < Rails::Generators::Base
      source_root File.expand_path('templates', __dir__)

      # This generator is used to add authentication, if no auth system is present.
      # Adds authentication through devise and sets up the current user.
      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
    end
  end
end

Version data entries

147 entries across 147 versions & 1 rubygems

Version Path
cm-admin-1.5.6 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.5.1 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.5.0 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.4.9 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.4.8 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.4.7 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.4.6 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.4.5 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.4.4 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.4.3 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.4.2 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.4.1 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.4.0 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.3.9 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.3.8 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.3.7 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.3.6 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.3.5 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.3.4 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.3.3 lib/generators/cm_admin/add_authentication_generator.rb