Sha256: 11a4ee54ca1c5f9301b9fcf4aea8d289f152753c686d986549e8c581044e1897

Contents?: true

Size: 947 Bytes

Versions: 1

Compression:

Stored size: 947 Bytes

Contents

require 'console_creep/authenticators/authenticator'

module ConsoleCreep
  module Authenticators
    class DeviseAuthenticator < Authenticator
      def initialize(options = {class: 'User'})
        @options = options
      end

      def collection
        @options[:class].to_s.constantize
      end

      def call
        ActiveRecord::Base.logger.silence do
          print 'Email address: '
          email = gets
          user = collection.find_by(email: email.strip.downcase)
          unless user
            puts 'Email not found in database! Exiting...'
            die
          end

          print 'Password: '
          pass = $stdin.noecho(&:gets)
          if user.valid_password?(pass.strip)
            set_current_user(user)
            ConsoleCreep.config.welcome.call(user)
          else
            puts 'Provided password is not correct! Exiting...'
            die
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
console_creep-0.1.0 lib/console_creep/authenticators/devise_authenticator.rb