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.55 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.5.54 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.5.53 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.5.52 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.5.51 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.5.50 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.5.49 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.5.48 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.5.47 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.5.46 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.5.45 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.5.44 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.5.43 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.5.42 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.5.41 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.5.40 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.5.39 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.5.38 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.5.37 lib/generators/cm_admin/add_authentication_generator.rb
cm-admin-1.5.36 lib/generators/cm_admin/add_authentication_generator.rb