class ConsoleCreep::Authenticators::DeviseAuthenticator
Public Class Methods
new(options = {class: 'User'})
click to toggle source
# File lib/console_creep/authenticators/devise_authenticator.rb, line 6 def initialize(options = {class: 'User'}) @options = options end
Public Instance Methods
call()
click to toggle source
# File lib/console_creep/authenticators/devise_authenticator.rb, line 14 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) if @options[:if] if @options[:if].call(user) set_current_user(user) ConsoleCreep.config.welcome.call(user) else puts "User not admin." die end else set_current_user(user) ConsoleCreep.config.welcome.call(user) end else puts 'Provided password is not correct! Exiting...' die end end end
collection()
click to toggle source
# File lib/console_creep/authenticators/devise_authenticator.rb, line 10 def collection @options[:class].to_s.constantize end