Perens::InstantUser

Perens::InstantUser is a Rails Engine that makes it as easy as possible to add user management: logins, authentication, sign-up, etc., to your Rails application.

  • All of the user management services are provided by the Devise gem, but we’ve done most of the work that it would otherwise take to install devise. The engine provides pre-configured routes and a User model.

  • Rails >= 3.1, Devise >= 2.0.0.rc, and Ruby >= 1.9.3 are required. It’s time to make the jump to Ruby 1.9 if you haven’t already done so, as Rails 4.0 will require Ruby 1.9.3 or greater.

  • This engine is in a very early state of development. There is no inline documentation in the code, and there are no tests! But it works (at least for me), and provides a good example of how to use Devise in an engine.

  • My thanks to Devise author and Rails committer José Valim, who upon my request added a set of features to Devise that made it possible to use Devise from an engine.

Installation

  • Edit your Gemfile or gemspec to add a dependency on the perens-instant-user gem.

  • bundle update

  • rake perens_instant_user:install:migrations

  • rake migrate

  • Edit config/routes.rb, adding this line:

    mount Perens::InstantUser::Engine => '/'
    
  • Copy raw.github.com/plataformatec/devise/master/lib/generators/templates/devise.rb into config/initializers/devise.rb and edit it.

    • Change config.mailer_sender to a valid address of yours.

    • Change the ORM configuration line to

      require 'devise/orm/active_record'
      

      if you are using ActiveRecord as your ORM (Rails defaults to this) or

      require 'devise/orm/mongoid'
      

      if you are using Mongoid.

    • Set the value for “config.pepper” to a unique value for your program. It must be unique, this value is used to chaff the encryption of passwords by your application. Security will be compromised if it’s not unique or if it becomes *known to outsiders*. Generate the value by running this program once.

      require 'securerandom'
      print %Q(config.pepper = "#{SecureRandom.hex(64)}"\n)
      
  • Edit one of your environment files, like config/application.rb, to add the URL info to be used in email messages to users from the user management system. While testing, this might be:

    config.action_mailer.default_url_options = { :host => 'localhost:3000' }
    

    but it must be set to the correct external URL when your application is running for real users.

  • Add authenticate_user! and other Devise helpers to your controllers as appropriate. See the Devise README.rdoc for information on the available features.

Bugs

  • Report issues here.

To Do

  • I’m planning to provide a web interface to set the configuration information, removing the need to copy and edit the Devise configuration file and the environment files.

Why Perens::InstantUser instead of InstantUser, and why perens-instant-user instead of instant-user?

Ruby and Rails are large enough that we should not all be sharing the same global namespace. Thus, all of my code will be in the Perens module and my gem names will start with perens-. Forks can just change “Perens” to something else and leave “InstantUser” the same. It turns out that users of this engine only have to type the longer name two times, so the tiny increase in user load seems to be a good trade for avoiding name collisions.