Code Monkey home page Code Monkey logo

any_login's Introduction

AnyLogin Gem

Build Status Gem Version

Description

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 is created to speedup development process and allow developer's quickly login as any user in DB.

Give it a try and if you like it share with friends. In case you have any suggestions please feel free to contact me.

Requirements

Ruby: 1.9.3, 2.X, Rails: >= 4.0. Works in pair with Devise, Authlogic, Clearance or Sorcery gems.

Installation

  1. List Add to your Gemfile:

    gem 'any_login'
    
  2. Execute in console:

    bundle install
    
  3. In application layout (for example app/views/layouts/application.html.erb) add in the bottom of the page:

    <%= any_login_here %>
    
  4. Open your app and on the bottom left corner you will see semi-transparent user icon. Click on it and now you can select any user to login without password.

Integrations

Devise

By default doesn't require any additional steps to make it works with Devise gem. If you have model User everything should works fine. In case you have other model you need to set it in options (see Customization section).

Authlogic

By default doesn't require any additional steps to make it works with Authlogic gem. If you have model User and you have current_user method in application controller everything should works fine. In case you have other model you need to set it in options (see Customization section).

Clearance

By default doesn't require any additional steps to make it works with Clearance gem. If you have model User everything should works fine. In case you have other model you need to set it in options (see Customization section).

Sorcery

By default doesn't require any additional steps to make it works with Sorcery gem. If you have model User everything should works fine. In case you have other model you need to set it in options (see Customization section).

Customization

If you want to customize gem run in console:

rails g any_login initializer

If will create file config/initializers/any_login.rb.

Options

  • enabled - enable of disable gem (by default this gem is enabled only in development mode).
  • klass_name - class name for "User" object. Default to User.
  • collection_method - method which returns collection of users. Sample: .all, .active, .admins, .groupped_users. Value is a simple. Default to :all.
  • name_method - default value is proc { |e| [e.email, e.id] }. You can change label for select in dropdown. For example you can add roles, permissions and any other important information.
  • limit - limit number of records in dropdown. Default 10. You can put :none if you don't want to limit number of users for select.
  • redirect_path_after_login - redirect user to path. Default is :root_path.
  • login_on - you can enable login with select field, ID input or both. Default: :both.
  • position - position of any_login box on page. Possible values: top_left, top_right, bottom_left, bottom_right. Default: bottom_left.
  • login_button_label - login button label.
  • select_prompt - select prompt message.
  • auto_show - automatically show any_login box.
  • http_basic_authentication_enabled - Enable HTTP_BASIC authentication.
  • http_basic_authentication_user_name - HTTP_BASIC authentication user name.
  • http_basic_authentication_password - HTTP_BASIC authentication password.
  • verify_access_proc - controller based access (condition on request.remote_ip, current_user, etc.)

Advanced Options

If you want to add collection grouped for example by role you can do it with:

    def self.groped_collection_by_role
      {
        'admin' => User.limit(10),
        'moderator' => User.limit(10),
        'user' => User.limit(10)
      }
    end

Or another sample:

    # Initializer
    config.collection_method = :grouped_users
    # # to format user name in dropdown list
    config.name_method = :any_login_name    
 
    # User class
    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

And in config/initializers/any_login.rb add config.collection_method = :groped_collection_by_role.

Production

If 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
end

You can also try to debug you application in production and secure any_login with HTTP_BASIC authentication. See Options sections for more details.

Future Plans

  1. Add tests
  2. Add support for more authentication gems like Devise, Authlogic, Clearance (restful_authentication, monban, letmein)

any_login's People

Contributors

alextakitani avatar bbenezech avatar igorkasyanchuk avatar incubus avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.