-
Notifications
You must be signed in to change notification settings - Fork 0
/
deviser.rb
67 lines (52 loc) · 1.33 KB
/
deviser.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env ruby
require 'readline'
require ::File.expand_path('../config/environment', __FILE__)
require 'application_controller'
class ApplicationController
prepend_around_filter do
sign_in $resource, bypass: true
end
end
class String
def gray
"\e[90m#{self}\e[0m"
end
def red
"\e[91m#{self}\e[0m"
end
end
def key
Rails.configuration.session_options[:key]
end
def cookie
session = ActionDispatch::Integration::Session.new(Rails.application)
session.https!
session.get('/')
session.cookies[key]
end
puts 'Provide Deviser with an authenticatable resource to impersonate.'
puts 'Use Ruby (e.g. User.first) in the following prompt:'
loop do
begin
input = Readline.readline("\n> ", true)
# Exit cleanly when ^D is pressed
# See: http://ruby-doc.org/stdlib-2.2.2/libdoc/readline/rdoc/Readline.html#method-c-readline
unless input
puts
exit
end
$resource = eval(input)
puts $resource.inspect.gray
unless $resource.respond_to? :active_for_authentication?
raise 'That does not seem like an authenticatable resource :('.red
end
session_key = cookie
puts
puts "For cookie '#{key}' use the following session key:"
puts
puts session_key
puts
rescue SyntaxError, StandardError => e
puts "#{e.class.name}: #{e.message}".red
end
end