devise_masquerade 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of devise_masquerade might be problematic. Click here for more details.
- data/.gitignore +19 -0
- data/.rspec +1 -0
- data/.rvmrc +1 -0
- data/Gemfile +22 -0
- data/Guardfile +14 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/app/controllers/devise/masquerades_controller.rb +21 -0
- data/devise_masquerade.gemspec +25 -0
- data/lib/devise_masquerade/controllers/helpers.rb +21 -0
- data/lib/devise_masquerade/controllers/url_helpers.rb +7 -0
- data/lib/devise_masquerade/model.rb +24 -0
- data/lib/devise_masquerade/rails.rb +7 -0
- data/lib/devise_masquerade/routes.rb +15 -0
- data/lib/devise_masquerade/version.rb +3 -0
- data/lib/devise_masquerade.rb +19 -0
- data/spec/controllers/dashboard_controller_spec.rb +20 -0
- data/spec/controllers/devise/masquerades_controller_spec.rb +30 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/dashboard_controller.rb +8 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/models/user.rb +12 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config/application.rb +21 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +22 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +26 -0
- data/spec/dummy/config/environments/production.rb +49 -0
- data/spec/dummy/config/environments/test.rb +35 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/devise.rb +14 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/locales/devise.en.yml +58 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +6 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/migrate/20121119085620_devise_create_users.rb +46 -0
- data/spec/dummy/db/schema.rb +34 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/models/user_spec.rb +27 -0
- data/spec/orm/active_record.rb +5 -0
- data/spec/spec_helper.rb +41 -0
- data/spec/support/authentication.rb +12 -0
- data/spec/support/factories.rb +10 -0
- metadata +176 -0
data/.gitignore
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
spec/dummy/log/*.log
|
18
|
+
spec/dummy/db/*.sqlite3
|
19
|
+
tmp
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use --create 1.9.3@devise_masquerade
|
data/Gemfile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
source :rubygems
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in devise_masquerade.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
group :test do
|
7
|
+
gem 'activerecord', '~> 3.0'
|
8
|
+
gem 'actionmailer', '~> 3.0'
|
9
|
+
gem "bson_ext", "~> 1.3"
|
10
|
+
gem 'sqlite3'
|
11
|
+
gem 'debugger'
|
12
|
+
gem 'guard'
|
13
|
+
gem 'guard-rspec'
|
14
|
+
gem 'guard-bundler'
|
15
|
+
gem 'capybara', '>= 0.4.0'
|
16
|
+
gem 'rspec-rails'
|
17
|
+
gem 'shoulda'
|
18
|
+
gem 'rb-fsevent'
|
19
|
+
gem 'factory_girl_rails'
|
20
|
+
gem 'database_cleaner'
|
21
|
+
end
|
22
|
+
|
data/Guardfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
guard 'rspec', :cli => '--format documentation', :version => 2, :all_after_pass => false, :keep_failed => false do
|
2
|
+
watch(%r{^spec/.+_spec\.rb$})
|
3
|
+
watch(%r{^spec/.+\.rb$})
|
4
|
+
watch(%r{^spec/support/.+\.rb$})
|
5
|
+
watch(%r{^lib/(.+)\.rb$}) { "spec" }
|
6
|
+
watch(%r{^lib/devise_masquerade/(.+)\.rb$}) { "spec" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
end
|
9
|
+
|
10
|
+
guard 'bundler' do
|
11
|
+
watch('Gemfile')
|
12
|
+
watch(/^.+\.gemspec/)
|
13
|
+
end
|
14
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Alexandr Korsak
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# DeviseMasquerade
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'devise_masquerade'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install devise_masquerade
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
class Devise::MasqueradesController < DeviseController
|
2
|
+
prepend_before_filter :authenticate_scope!, :only => :masquerade
|
3
|
+
|
4
|
+
def masquerade
|
5
|
+
self.resource = resource_class.to_adapter.find_first(:id => params[:id])
|
6
|
+
self.resource.masquerade!
|
7
|
+
|
8
|
+
redirect_to(after_masquerade_path_for(self.resource))
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def authenticate_scope!
|
14
|
+
send(:"authenticate_#{resource_name}!", :force => true)
|
15
|
+
end
|
16
|
+
|
17
|
+
def after_masquerade_path_for(resource)
|
18
|
+
"/?masquerade=#{resource.masquerade_key}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'devise_masquerade/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "devise_masquerade"
|
8
|
+
gem.version = DeviseMasquerade::VERSION
|
9
|
+
gem.authors = ["Alexandr Korsak"]
|
10
|
+
gem.email = ["alex.korsak@gmail.com"]
|
11
|
+
gem.description = %q{devise masquerade library}
|
12
|
+
gem.summary = %q{use for login as functionallity on your admin users pages}
|
13
|
+
gem.homepage = "http://github.com/oivoodoo/devise_masquerade/"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency('bundler', '>= 1.1.0')
|
21
|
+
|
22
|
+
gem.add_runtime_dependency('railties', '~> 3.0')
|
23
|
+
gem.add_runtime_dependency('devise', '>= 2.1.0')
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module DeviseMasquerade
|
2
|
+
module Controllers
|
3
|
+
module Helpers
|
4
|
+
def self.define_helpers(mapping)
|
5
|
+
name = mapping.name
|
6
|
+
|
7
|
+
class_eval <<-METHODS, __FILE__, __LINE__ + 1
|
8
|
+
def masquerade_#{name}!
|
9
|
+
return if params[:masquerade].blank?
|
10
|
+
|
11
|
+
#{name} = #{name.to_s.classify}.find_by_masquerade_key(params[:masquerade])
|
12
|
+
|
13
|
+
sign_in #{name} if #{name}
|
14
|
+
end
|
15
|
+
METHODS
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
ActionController::Base.send(:include, DeviseMasquerade::Controllers::Helpers)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Devise
|
2
|
+
module Models
|
3
|
+
module Masqueradable
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
attr_reader :masquerade_key
|
8
|
+
|
9
|
+
def masquerade!
|
10
|
+
@masquerade_key = SecureRandom.base64(16)
|
11
|
+
|
12
|
+
Rails.cache.write("#{self.class.name.pluralize.downcase}:#{@masquerade_key}:masquerade", id, :expires_in => 10.seconds)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.find_by_masquerade_key(key)
|
16
|
+
id = Rails.cache.read("#{self.name.pluralize.downcase}:#{key}:masquerade")
|
17
|
+
|
18
|
+
self.find_by_id(id)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ActionDispatch::Routing
|
2
|
+
class Mapper
|
3
|
+
protected
|
4
|
+
|
5
|
+
def devise_masquerade(mapping, controllers)
|
6
|
+
resource :masquerade, :only => [],
|
7
|
+
:path => mapping.path_names[:masquerade],
|
8
|
+
:controller => controllers[:masquerades] do
|
9
|
+
|
10
|
+
get :masquerade, :path => mapping.path_names[:accept], :as => :accept
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'devise'
|
2
|
+
|
3
|
+
require 'action_controller'
|
4
|
+
require 'action_controller/base'
|
5
|
+
require 'devise_masquerade/version'
|
6
|
+
require 'devise_masquerade/routes'
|
7
|
+
require 'devise_masquerade/controllers/helpers'
|
8
|
+
require 'devise_masquerade/controllers/url_helpers'
|
9
|
+
require 'devise_masquerade/rails'
|
10
|
+
|
11
|
+
module DeviseMasquerade
|
12
|
+
end
|
13
|
+
|
14
|
+
module Devise
|
15
|
+
@@helpers << DeviseMasquerade::Controllers::Helpers
|
16
|
+
end
|
17
|
+
|
18
|
+
Devise.add_module :masqueradable, :controller => :masquerades, :model => 'devise_masquerade/model', :route => :masquerade
|
19
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DashboardController do
|
4
|
+
context 'when logged in' do
|
5
|
+
before { logged_in }
|
6
|
+
|
7
|
+
context 'and admin masquerade by user' do
|
8
|
+
let!(:user) { create(:user) }
|
9
|
+
|
10
|
+
before do
|
11
|
+
user.masquerade!
|
12
|
+
|
13
|
+
get :index, :masquerade => user.masquerade_key
|
14
|
+
end
|
15
|
+
|
16
|
+
it { current_user.reload.should == user }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Devise::MasqueradesController do
|
4
|
+
context 'with configured devise app' do
|
5
|
+
before { @request.env['devise.mapping'] = Devise.mappings[:user] }
|
6
|
+
|
7
|
+
context 'when logged in' do
|
8
|
+
before { logged_in }
|
9
|
+
|
10
|
+
describe '#masquerade user' do
|
11
|
+
let!(:user) { create(:user) }
|
12
|
+
|
13
|
+
before do
|
14
|
+
SecureRandom.should_receive(:base64).and_return("secure_key")
|
15
|
+
|
16
|
+
get :masquerade, :id => user.to_param
|
17
|
+
end
|
18
|
+
|
19
|
+
it { should redirect_to("/?masquerade=secure_key") }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'when not logged in' do
|
24
|
+
before { get :masquerade, :id => 'any_id' }
|
25
|
+
|
26
|
+
it { should redirect_to(new_user_session_path) }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
|
+
|
4
|
+
require File.expand_path('../config/application', __FILE__)
|
5
|
+
require 'rake'
|
6
|
+
|
7
|
+
Dummy::Application.load_tasks
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class User < ActiveRecord::Base
|
2
|
+
# Include default devise modules. Others available are:
|
3
|
+
# :token_authenticatable, :confirmable,
|
4
|
+
# :lockable, :timeoutable and :omniauthable
|
5
|
+
devise :database_authenticatable, :registerable,
|
6
|
+
:recoverable, :rememberable, :trackable, :validatable,
|
7
|
+
:masqueradable
|
8
|
+
|
9
|
+
# Setup accessible (or protected) attributes for your model
|
10
|
+
attr_accessible :email, :password, :password_confirmation, :remember_me
|
11
|
+
# attr_accessible :title, :body
|
12
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require "active_model/railtie"
|
4
|
+
require "active_record/railtie"
|
5
|
+
require "action_controller/railtie"
|
6
|
+
require "action_view/railtie"
|
7
|
+
require "action_mailer/railtie"
|
8
|
+
|
9
|
+
Bundler.require
|
10
|
+
|
11
|
+
require "devise"
|
12
|
+
require "devise_masquerade"
|
13
|
+
|
14
|
+
module Dummy
|
15
|
+
class Application < Rails::Application
|
16
|
+
config.encoding = "utf-8"
|
17
|
+
|
18
|
+
config.filter_parameters += [:password]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# SQLite version 3.x
|
2
|
+
# gem install sqlite3
|
3
|
+
development:
|
4
|
+
adapter: sqlite3
|
5
|
+
database: db/development.sqlite3
|
6
|
+
pool: 5
|
7
|
+
timeout: 5000
|
8
|
+
|
9
|
+
# Warning: The database defined as "test" will be erased and
|
10
|
+
# re-generated from your development database when you run "rake".
|
11
|
+
# Do not set this db to the same as development or production.
|
12
|
+
test:
|
13
|
+
adapter: sqlite3
|
14
|
+
database: db/test.sqlite3
|
15
|
+
pool: 5
|
16
|
+
timeout: 5000
|
17
|
+
|
18
|
+
production:
|
19
|
+
adapter: sqlite3
|
20
|
+
database: db/production.sqlite3
|
21
|
+
pool: 5
|
22
|
+
timeout: 5000
|
@@ -0,0 +1,26 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# In the development environment your application's code is reloaded on
|
5
|
+
# every request. This slows down response time but is perfect for development
|
6
|
+
# since you don't have to restart the webserver when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Log error messages when you accidentally call methods on nil.
|
10
|
+
config.whiny_nils = true
|
11
|
+
|
12
|
+
# Show full error reports and disable caching
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
config.action_view.debug_rjs = true
|
15
|
+
config.action_controller.perform_caching = false
|
16
|
+
|
17
|
+
# Don't care if the mailer can't send
|
18
|
+
config.action_mailer.raise_delivery_errors = false
|
19
|
+
|
20
|
+
# Print deprecation notices to the Rails logger
|
21
|
+
config.active_support.deprecation = :log
|
22
|
+
|
23
|
+
# Only use best-standards-support built into browsers
|
24
|
+
config.action_dispatch.best_standards_support = :builtin
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# The production environment is meant for finished, "live" apps.
|
5
|
+
# Code is not reloaded between requests
|
6
|
+
config.cache_classes = true
|
7
|
+
|
8
|
+
# Full error reports are disabled and caching is turned on
|
9
|
+
config.consider_all_requests_local = false
|
10
|
+
config.action_controller.perform_caching = true
|
11
|
+
|
12
|
+
# Specifies the header that your server uses for sending files
|
13
|
+
config.action_dispatch.x_sendfile_header = "X-Sendfile"
|
14
|
+
|
15
|
+
# For nginx:
|
16
|
+
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
|
17
|
+
|
18
|
+
# If you have no front-end server that supports something like X-Sendfile,
|
19
|
+
# just comment this out and Rails will serve the files
|
20
|
+
|
21
|
+
# See everything in the log (default is :info)
|
22
|
+
# config.log_level = :debug
|
23
|
+
|
24
|
+
# Use a different logger for distributed setups
|
25
|
+
# config.logger = SyslogLogger.new
|
26
|
+
|
27
|
+
# Use a different cache store in production
|
28
|
+
# config.cache_store = :mem_cache_store
|
29
|
+
|
30
|
+
# Disable Rails's static asset server
|
31
|
+
# In production, Apache or nginx will already do this
|
32
|
+
config.serve_static_assets = false
|
33
|
+
|
34
|
+
# Enable serving of images, stylesheets, and javascripts from an asset server
|
35
|
+
# config.action_controller.asset_host = "http://assets.example.com"
|
36
|
+
|
37
|
+
# Disable delivery errors, bad email addresses will be ignored
|
38
|
+
# config.action_mailer.raise_delivery_errors = false
|
39
|
+
|
40
|
+
# Enable threaded mode
|
41
|
+
# config.threadsafe!
|
42
|
+
|
43
|
+
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
44
|
+
# the I18n.default_locale when a translation can not be found)
|
45
|
+
config.i18n.fallbacks = true
|
46
|
+
|
47
|
+
# Send deprecation notices to registered listeners
|
48
|
+
config.active_support.deprecation = :notify
|
49
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# The test environment is used exclusively to run your application's
|
5
|
+
# test suite. You never need to work with it otherwise. Remember that
|
6
|
+
# your test database is "scratch space" for the test suite and is wiped
|
7
|
+
# and recreated between test runs. Don't rely on the data there!
|
8
|
+
config.cache_classes = true
|
9
|
+
|
10
|
+
# Log error messages when you accidentally call methods on nil.
|
11
|
+
config.whiny_nils = true
|
12
|
+
|
13
|
+
# Show full error reports and disable caching
|
14
|
+
config.consider_all_requests_local = true
|
15
|
+
config.action_controller.perform_caching = false
|
16
|
+
|
17
|
+
# Raise exceptions instead of rendering exception templates
|
18
|
+
config.action_dispatch.show_exceptions = false
|
19
|
+
|
20
|
+
# Disable request forgery protection in test environment
|
21
|
+
config.action_controller.allow_forgery_protection = false
|
22
|
+
|
23
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
24
|
+
# The :test delivery method accumulates sent emails in the
|
25
|
+
# ActionMailer::Base.deliveries array.
|
26
|
+
config.action_mailer.delivery_method = :test
|
27
|
+
|
28
|
+
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
29
|
+
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
30
|
+
# like if you have constraints or database-specific column types
|
31
|
+
# config.active_record.schema_format = :sql
|
32
|
+
|
33
|
+
# Print deprecation notices to the stderr
|
34
|
+
config.active_support.deprecation = :stderr
|
35
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
|
4
|
+
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
|
5
|
+
|
6
|
+
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
|
7
|
+
# Rails.backtrace_cleaner.remove_silencers!
|
@@ -0,0 +1,14 @@
|
|
1
|
+
Devise.setup do |config|
|
2
|
+
config.mailer_sender = "support@example.com"
|
3
|
+
|
4
|
+
require 'devise/orm/active_record'
|
5
|
+
|
6
|
+
config.case_insensitive_keys = [ :email ]
|
7
|
+
config.strip_whitespace_keys = [ :email ]
|
8
|
+
config.skip_session_storage = [:http_auth]
|
9
|
+
config.stretches = Rails.env.test? ? 1 : 10
|
10
|
+
config.reconfirmable = true
|
11
|
+
config.reset_password_within = 6.hours
|
12
|
+
config.sign_out_via = :delete
|
13
|
+
end
|
14
|
+
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Add new inflection rules using the following format
|
4
|
+
# (all these examples are active by default):
|
5
|
+
# ActiveSupport::Inflector.inflections do |inflect|
|
6
|
+
# inflect.plural /^(ox)$/i, '\1en'
|
7
|
+
# inflect.singular /^(ox)en/i, '\1'
|
8
|
+
# inflect.irregular 'person', 'people'
|
9
|
+
# inflect.uncountable %w( fish sheep )
|
10
|
+
# end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key for verifying the integrity of signed cookies.
|
4
|
+
# If you change this key, all old signed cookies will become invalid!
|
5
|
+
# Make sure the secret is at least 30 characters and all random,
|
6
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
7
|
+
Dummy::Application.config.secret_token = 'a6e62bffc6f8b316bec21616dd6789a7cb23b40513a69f857b433b2baba5a75e82f9a89586693e14012a284eb95441885dfa3207757e8df2b63ade9cda9f147f'
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
|
4
|
+
|
5
|
+
# Use the database for sessions instead of the cookie-based default,
|
6
|
+
# which shouldn't be used to store highly confidential information
|
7
|
+
# (create the session table with "rails generate session_migration")
|
8
|
+
# Dummy::Application.config.session_store :active_record_store
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# Additional translations at https://github.com/plataformatec/devise/wiki/I18n
|
2
|
+
|
3
|
+
en:
|
4
|
+
errors:
|
5
|
+
messages:
|
6
|
+
expired: "has expired, please request a new one"
|
7
|
+
not_found: "not found"
|
8
|
+
already_confirmed: "was already confirmed, please try signing in"
|
9
|
+
not_locked: "was not locked"
|
10
|
+
not_saved:
|
11
|
+
one: "1 error prohibited this %{resource} from being saved:"
|
12
|
+
other: "%{count} errors prohibited this %{resource} from being saved:"
|
13
|
+
|
14
|
+
devise:
|
15
|
+
failure:
|
16
|
+
already_authenticated: 'You are already signed in.'
|
17
|
+
unauthenticated: 'You need to sign in or sign up before continuing.'
|
18
|
+
unconfirmed: 'You have to confirm your account before continuing.'
|
19
|
+
locked: 'Your account is locked.'
|
20
|
+
invalid: 'Invalid email or password.'
|
21
|
+
invalid_token: 'Invalid authentication token.'
|
22
|
+
timeout: 'Your session expired, please sign in again to continue.'
|
23
|
+
inactive: 'Your account was not activated yet.'
|
24
|
+
sessions:
|
25
|
+
signed_in: 'Signed in successfully.'
|
26
|
+
signed_out: 'Signed out successfully.'
|
27
|
+
passwords:
|
28
|
+
send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
|
29
|
+
updated: 'Your password was changed successfully. You are now signed in.'
|
30
|
+
updated_not_active: 'Your password was changed successfully.'
|
31
|
+
send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
|
32
|
+
no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
|
33
|
+
confirmations:
|
34
|
+
send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
|
35
|
+
send_paranoid_instructions: 'If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes.'
|
36
|
+
confirmed: 'Your account was successfully confirmed. You are now signed in.'
|
37
|
+
registrations:
|
38
|
+
signed_up: 'Welcome! You have signed up successfully.'
|
39
|
+
signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.'
|
40
|
+
signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.'
|
41
|
+
signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.'
|
42
|
+
updated: 'You updated your account successfully.'
|
43
|
+
update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
|
44
|
+
destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
|
45
|
+
unlocks:
|
46
|
+
send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
|
47
|
+
unlocked: 'Your account has been unlocked successfully. Please sign in to continue.'
|
48
|
+
send_paranoid_instructions: 'If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.'
|
49
|
+
omniauth_callbacks:
|
50
|
+
success: 'Successfully authenticated from %{kind} account.'
|
51
|
+
failure: 'Could not authenticate you from %{kind} because "%{reason}".'
|
52
|
+
mailer:
|
53
|
+
confirmation_instructions:
|
54
|
+
subject: 'Confirmation instructions'
|
55
|
+
reset_password_instructions:
|
56
|
+
subject: 'Reset password instructions'
|
57
|
+
unlock_instructions:
|
58
|
+
subject: 'Unlock Instructions'
|
@@ -0,0 +1,46 @@
|
|
1
|
+
class DeviseCreateUsers < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table(:users) do |t|
|
4
|
+
## Database authenticatable
|
5
|
+
t.string :email, :null => false, :default => ""
|
6
|
+
t.string :encrypted_password, :null => false, :default => ""
|
7
|
+
|
8
|
+
## Recoverable
|
9
|
+
t.string :reset_password_token
|
10
|
+
t.datetime :reset_password_sent_at
|
11
|
+
|
12
|
+
## Rememberable
|
13
|
+
t.datetime :remember_created_at
|
14
|
+
|
15
|
+
## Trackable
|
16
|
+
t.integer :sign_in_count, :default => 0
|
17
|
+
t.datetime :current_sign_in_at
|
18
|
+
t.datetime :last_sign_in_at
|
19
|
+
t.string :current_sign_in_ip
|
20
|
+
t.string :last_sign_in_ip
|
21
|
+
|
22
|
+
## Confirmable
|
23
|
+
# t.string :confirmation_token
|
24
|
+
# t.datetime :confirmed_at
|
25
|
+
# t.datetime :confirmation_sent_at
|
26
|
+
# t.string :unconfirmed_email # Only if using reconfirmable
|
27
|
+
|
28
|
+
## Lockable
|
29
|
+
# t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
|
30
|
+
# t.string :unlock_token # Only if unlock strategy is :email or :both
|
31
|
+
# t.datetime :locked_at
|
32
|
+
|
33
|
+
## Token authenticatable
|
34
|
+
# t.string :authentication_token
|
35
|
+
|
36
|
+
|
37
|
+
t.timestamps
|
38
|
+
end
|
39
|
+
|
40
|
+
add_index :users, :email, :unique => true
|
41
|
+
add_index :users, :reset_password_token, :unique => true
|
42
|
+
# add_index :users, :confirmation_token, :unique => true
|
43
|
+
# add_index :users, :unlock_token, :unique => true
|
44
|
+
# add_index :users, :authentication_token, :unique => true
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# This file is auto-generated from the current state of the database. Instead
|
3
|
+
# of editing this file, please use the migrations feature of Active Record to
|
4
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
5
|
+
#
|
6
|
+
# Note that this schema.rb definition is the authoritative source for your
|
7
|
+
# database schema. If you need to create the application database on another
|
8
|
+
# system, you should be using db:schema:load, not running all the migrations
|
9
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
10
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
11
|
+
#
|
12
|
+
# It's strongly recommended to check this file into your version control system.
|
13
|
+
|
14
|
+
ActiveRecord::Schema.define(:version => 20121119085620) do
|
15
|
+
|
16
|
+
create_table "users", :force => true do |t|
|
17
|
+
t.string "email", :default => "", :null => false
|
18
|
+
t.string "encrypted_password", :default => "", :null => false
|
19
|
+
t.string "reset_password_token"
|
20
|
+
t.datetime "reset_password_sent_at"
|
21
|
+
t.datetime "remember_created_at"
|
22
|
+
t.integer "sign_in_count", :default => 0
|
23
|
+
t.datetime "current_sign_in_at"
|
24
|
+
t.datetime "last_sign_in_at"
|
25
|
+
t.string "current_sign_in_ip"
|
26
|
+
t.string "last_sign_in_ip"
|
27
|
+
t.datetime "created_at", :null => false
|
28
|
+
t.datetime "updated_at", :null => false
|
29
|
+
end
|
30
|
+
|
31
|
+
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
|
32
|
+
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe User do
|
4
|
+
let!(:user) { create(:user) }
|
5
|
+
|
6
|
+
describe '#masquerade!' do
|
7
|
+
it 'should cache special key on masquerade' do
|
8
|
+
SecureRandom.should_receive(:base64).with(16).and_return("secure_key")
|
9
|
+
Rails.cache.should_receive(:write).with("users:secure_key:masquerade", user.id, :expires_in => 10.seconds)
|
10
|
+
|
11
|
+
user.masquerade!
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#find_by_masquerade_key' do
|
16
|
+
it 'should be possible to find user by generate masquerade key' do
|
17
|
+
user.masquerade!
|
18
|
+
|
19
|
+
Rails.cache.should_receive(:read).with("users:#{user.masquerade_key}:masquerade").and_return(user.id)
|
20
|
+
|
21
|
+
new_user = User.find_by_masquerade_key(user.masquerade_key)
|
22
|
+
|
23
|
+
new_user.should == user
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Configure Rails Envinronment
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
|
4
|
+
require 'devise_masquerade'
|
5
|
+
|
6
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
7
|
+
require 'rails/test_help'
|
8
|
+
require 'rspec/rails'
|
9
|
+
require 'factory_girl'
|
10
|
+
require 'database_cleaner'
|
11
|
+
|
12
|
+
Rails.backtrace_cleaner.remove_silencers!
|
13
|
+
|
14
|
+
Dir[File.join(File.dirname(__FILE__), '..', "spec/support/*.rb")].each {|f| require f}
|
15
|
+
Dir[File.join(File.dirname(__FILE__), '..', "spec/orm/*.rb")].each {|f| require f}
|
16
|
+
|
17
|
+
RSpec.configure do |config|
|
18
|
+
require 'rspec/expectations'
|
19
|
+
config.include RSpec::Matchers
|
20
|
+
|
21
|
+
config.include Devise::TestHelpers, :type => :controller
|
22
|
+
config.include Warden::Test::Helpers
|
23
|
+
config.include FactoryGirl::Syntax::Methods
|
24
|
+
config.include Authentication
|
25
|
+
|
26
|
+
config.mock_with :rspec
|
27
|
+
|
28
|
+
config.before(:suite) do
|
29
|
+
DatabaseCleaner.strategy = :transaction
|
30
|
+
DatabaseCleaner.clean_with(:truncation)
|
31
|
+
end
|
32
|
+
|
33
|
+
config.before(:each) do
|
34
|
+
DatabaseCleaner.start
|
35
|
+
end
|
36
|
+
|
37
|
+
config.after(:each) do
|
38
|
+
DatabaseCleaner.clean
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
metadata
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: devise_masquerade
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Alexandr Korsak
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.1.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.1.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: railties
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '3.0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3.0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: devise
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.1.0
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.1.0
|
62
|
+
description: devise masquerade library
|
63
|
+
email:
|
64
|
+
- alex.korsak@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- .rspec
|
71
|
+
- .rvmrc
|
72
|
+
- Gemfile
|
73
|
+
- Guardfile
|
74
|
+
- LICENSE.txt
|
75
|
+
- README.md
|
76
|
+
- Rakefile
|
77
|
+
- app/controllers/devise/masquerades_controller.rb
|
78
|
+
- devise_masquerade.gemspec
|
79
|
+
- lib/devise_masquerade.rb
|
80
|
+
- lib/devise_masquerade/controllers/helpers.rb
|
81
|
+
- lib/devise_masquerade/controllers/url_helpers.rb
|
82
|
+
- lib/devise_masquerade/model.rb
|
83
|
+
- lib/devise_masquerade/rails.rb
|
84
|
+
- lib/devise_masquerade/routes.rb
|
85
|
+
- lib/devise_masquerade/version.rb
|
86
|
+
- spec/controllers/dashboard_controller_spec.rb
|
87
|
+
- spec/controllers/devise/masquerades_controller_spec.rb
|
88
|
+
- spec/dummy/Rakefile
|
89
|
+
- spec/dummy/app/controllers/application_controller.rb
|
90
|
+
- spec/dummy/app/controllers/dashboard_controller.rb
|
91
|
+
- spec/dummy/app/helpers/application_helper.rb
|
92
|
+
- spec/dummy/app/models/user.rb
|
93
|
+
- spec/dummy/app/views/layouts/application.html.erb
|
94
|
+
- spec/dummy/config.ru
|
95
|
+
- spec/dummy/config/application.rb
|
96
|
+
- spec/dummy/config/boot.rb
|
97
|
+
- spec/dummy/config/database.yml
|
98
|
+
- spec/dummy/config/environment.rb
|
99
|
+
- spec/dummy/config/environments/development.rb
|
100
|
+
- spec/dummy/config/environments/production.rb
|
101
|
+
- spec/dummy/config/environments/test.rb
|
102
|
+
- spec/dummy/config/initializers/backtrace_silencers.rb
|
103
|
+
- spec/dummy/config/initializers/devise.rb
|
104
|
+
- spec/dummy/config/initializers/inflections.rb
|
105
|
+
- spec/dummy/config/initializers/mime_types.rb
|
106
|
+
- spec/dummy/config/initializers/secret_token.rb
|
107
|
+
- spec/dummy/config/initializers/session_store.rb
|
108
|
+
- spec/dummy/config/locales/devise.en.yml
|
109
|
+
- spec/dummy/config/locales/en.yml
|
110
|
+
- spec/dummy/config/routes.rb
|
111
|
+
- spec/dummy/db/migrate/20121119085620_devise_create_users.rb
|
112
|
+
- spec/dummy/db/schema.rb
|
113
|
+
- spec/dummy/script/rails
|
114
|
+
- spec/models/user_spec.rb
|
115
|
+
- spec/orm/active_record.rb
|
116
|
+
- spec/spec_helper.rb
|
117
|
+
- spec/support/authentication.rb
|
118
|
+
- spec/support/factories.rb
|
119
|
+
homepage: http://github.com/oivoodoo/devise_masquerade/
|
120
|
+
licenses: []
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
none: false
|
127
|
+
requirements:
|
128
|
+
- - ! '>='
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
none: false
|
133
|
+
requirements:
|
134
|
+
- - ! '>='
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 1.8.23
|
140
|
+
signing_key:
|
141
|
+
specification_version: 3
|
142
|
+
summary: use for login as functionallity on your admin users pages
|
143
|
+
test_files:
|
144
|
+
- spec/controllers/dashboard_controller_spec.rb
|
145
|
+
- spec/controllers/devise/masquerades_controller_spec.rb
|
146
|
+
- spec/dummy/Rakefile
|
147
|
+
- spec/dummy/app/controllers/application_controller.rb
|
148
|
+
- spec/dummy/app/controllers/dashboard_controller.rb
|
149
|
+
- spec/dummy/app/helpers/application_helper.rb
|
150
|
+
- spec/dummy/app/models/user.rb
|
151
|
+
- spec/dummy/app/views/layouts/application.html.erb
|
152
|
+
- spec/dummy/config.ru
|
153
|
+
- spec/dummy/config/application.rb
|
154
|
+
- spec/dummy/config/boot.rb
|
155
|
+
- spec/dummy/config/database.yml
|
156
|
+
- spec/dummy/config/environment.rb
|
157
|
+
- spec/dummy/config/environments/development.rb
|
158
|
+
- spec/dummy/config/environments/production.rb
|
159
|
+
- spec/dummy/config/environments/test.rb
|
160
|
+
- spec/dummy/config/initializers/backtrace_silencers.rb
|
161
|
+
- spec/dummy/config/initializers/devise.rb
|
162
|
+
- spec/dummy/config/initializers/inflections.rb
|
163
|
+
- spec/dummy/config/initializers/mime_types.rb
|
164
|
+
- spec/dummy/config/initializers/secret_token.rb
|
165
|
+
- spec/dummy/config/initializers/session_store.rb
|
166
|
+
- spec/dummy/config/locales/devise.en.yml
|
167
|
+
- spec/dummy/config/locales/en.yml
|
168
|
+
- spec/dummy/config/routes.rb
|
169
|
+
- spec/dummy/db/migrate/20121119085620_devise_create_users.rb
|
170
|
+
- spec/dummy/db/schema.rb
|
171
|
+
- spec/dummy/script/rails
|
172
|
+
- spec/models/user_spec.rb
|
173
|
+
- spec/orm/active_record.rb
|
174
|
+
- spec/spec_helper.rb
|
175
|
+
- spec/support/authentication.rb
|
176
|
+
- spec/support/factories.rb
|