Sha256: d02e998e36ea333383434bd7d826b58db98587e7ac1a33bf188b0276b22abed0

Contents?: true

Size: 1.91 KB

Versions: 7

Compression:

Stored size: 1.91 KB

Contents

require 'thor'
require 'eucalypt/helpers'
require 'eucalypt/eucalypt-security/helpers'
require 'eucalypt/eucalypt-security/namespaces/security-warden/generators/user'
require 'eucalypt/eucalypt-security/namespaces/security-warden/generators/auth_controller'

module Eucalypt
  class SecurityWarden < Thor
    include Thor::Actions
    include Eucalypt::Helpers
    include Eucalypt::Helpers::Messages
    include Eucalypt::Helpers::Gemfile
    include Eucalypt::Security::Helpers
    using Colorize

    def self.source_root
      File.join File.dirname(__dir__), 'templates'
    end

    option :controller, type: :boolean, default: true, desc: "Include an authentication controller"
    desc "setup", "Set up Warden authentication".colorize(:grey)
    def setup
      directory = File.expand_path('.')
      if Eucalypt.app? directory
        Out.setup "Setting up Warden authentication..."

        # Add Warden and BCrypt to Gemfile
        gemfile_add('Authentication and encryption', {warden: '~> 1.2', bcrypt: '~> 3.1'}, directory)

        # Create Warden config file
        create_config_file(:warden, directory)

        user = Eucalypt::Generators::User.new

        # Create user migration
        user.generate_migration

        # Create user model
        user.generate_model(directory)

        if options[:controller]
          auth_controller = Eucalypt::Generators::AuthController.new
          auth_controller.destination_root = directory
          auth_controller.generate
        end

        Out.info "Ensure you run `#{'rake db:migrate'.colorize(:bold)}` to create the necessary tables for Warden."
      else
        Eucalypt::Error.wrong_directory
      end
    end

    class << self
      require 'eucalypt/list'
      include Eucalypt::List
      def banner(task, namespace = false, subcommand = true)
        "#{basename} security #{task.formatted_usage(self, true, subcommand).split(':').join(' ')}"
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
eucalypt-0.2.2 lib/eucalypt/eucalypt-security/namespaces/security-warden/cli/security-warden.rb
eucalypt-0.2.1 lib/eucalypt/eucalypt-security/namespaces/security-warden/cli/security-warden.rb
eucalypt-0.2.0 lib/eucalypt/eucalypt-security/namespaces/security-warden/cli/security-warden.rb
eucalypt-0.1.3 lib/eucalypt/eucalypt-security/namespaces/security-warden/cli/security-warden.rb
eucalypt-0.1.2 lib/eucalypt/eucalypt-security/namespaces/security-warden/cli/security-warden.rb
eucalypt-0.1.1 lib/eucalypt/eucalypt-security/namespaces/security-warden/cli/security-warden.rb
eucalypt-0.1.0 lib/eucalypt/eucalypt-security/namespaces/security-warden/cli/security-warden.rb