以系统中的任何用户身份登录的简单方法
Demo available on: https://any-login.herokuapp.com (source code for demo https://github.com/igorkasyanchuk/any_login_test)
Video Demo: https://youtu.be/978DlHvufSY
AnyLogin was created to speed up the development process by allowing developers to quickly log in as any user.
Give it a try; if you like it please share AnyLogin with friends. If you have any suggestions please feel free to contact me.
Ruby: >= 3.0, Rails: >= 6.1. Pre-configured to work with Devise, Authlogic, Clearance or Sorcery gems.
For Rails User.admins.limit(10), 'moderator' => User.moderators.limit(10), 'user' => User.users.limit(10) } end end
Or another sample:
```ruby
# Initializer: config/initializers/any_login.rb
AnyLogin.setup do |config|
config.collection_method = :grouped_users
# to format user name in dropdown list
config.name_method = :any_login_name
end
# User class: app/models/user.rb
class User < ActiveRecord::Base
def any_login_name
[full_name + ' - ' + email + " Domains: #{domains.collect(&:short_code).join(',').presence || 'none'}; Role: #{role}; ID: #{id}", id]
end
def self.grouped_users
Organization.ordered.includes(:employees).inject({}) do |res, org|
res[org.name] = org.employees.ordered.includes([:domains, :organization])
res
end
end
endIf you want to completely disable gem in production add following code in your config/environments/production.rb file.
AnyLogin.setup do |config|
config.enabled = false
endYou can also try to debug your application in production and secure AnyLogin with HTTP_BASIC authentication. See Options sections for more details.
Update gemspec:
BUNDLE_GEMFILE=./gemfiles/rails_8_0.gemfile bundleTo setup test apps:
./prepare.sh
and
bundle exec appraisal install
To run tests:
bundle exec appraisal rails-8-0 bundle exec test_devise
bundle exec appraisal rails-8-0 bundle exec test_clearance
bundle exec appraisal rails-8-0 bundle exec test_authlogic
bundle exec appraisal rails-8-0 bundle exec test_sorcery
# or
bundle exec appraisal rails-8-0 bundle exec rails test test/devise/
bundle exec appraisal rails-8-0 bundle exec rails test test/authlogic/
bundle exec appraisal rails-8-0 bundle exec rails test test/clearance/
bundle exec appraisal rails-8-0 bundle exec rails test test/sorcery/
If you want to manually tests open test/rails_apps/devise/ and run BUNDLE_GEMFILE=../../../gemfiles/rails_8_0.gemfile bundle exec rails s and open http://localhost:3000 (and with other gems)
Note: with Devise it can glitch in dummy app so I suggest to connect to real app using:
gem 'any_login', path: '../any_login'暂无开放 Issues,或尚未同步最近议题。