Skip to content

MitinPavel/current_user

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
app
 
 
 
 
 
 
lib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

CurrentUser

Build Status Code Climate

Dev phase auth for Rails.

What it is

  • A simple authentication gem for the development (pre-production) phase
  • Familiar rails conventions: #current_user, #signed_in?
  • A minimalistic signin page with a list of all available users (just click on a user and you will be logged in under the user)
  • An opportunity to replace it with one of the mature solution (assuming Devise)

What it is not

  • An authentication solution for the production phase of the application lifecycle
  • An authorization gem (although in the future it might get some authorization features to mimic Devise)

How it looks like

[Screenshot of the sign in page]

Getting started

CurrentUser works with Rails 3.2 and 4.0 using Ruby 1.9.3 or Ruby 2.0.

Add to your Gemfile:

gem "current_user"

Install it using bundler:

bundle install

Note: CurrentUser assumes your application already has a few users. So if the assumption is false, create User active record class AND/OR add several users to the database. It also assumes User has "email" attribute/method. If it is not the case, add "email" or change configuration in config/initializers/current_user.rb.

Run the generator:

rails generate current_user:install

The generator:

  • creates a file with a unique authentication key for your application
  • creates an initializer
  • inject routing to your application
  • show README

Specify root in config/routes.rb:

root :to => 'dashboards#show'

Add before filter to app/controllers/application_controller.rb:

before_filter :authenticate_user!

Try to visit one of protected pages of your application (for example root). You will see "Unauthorized" error page.

Run a rake task what shows a path to your sign in page:

rake current_user:sign_in_path

Visit your sign in page. You will see a list of users of your application. Click on a user and the link will take you to the root page of the application.

Congratulations. Your application has a simple authentication solution. Send a link to the sign in page to your customer and she/he will love to test your app manually :)

Helpers

CurrentUser creates some helpers to use inside your controllers and views.

To verify if a user is signed in, use the following helper:

signed_in?

For the current signed-in user, this helper is available:

current_user

Logo

CurrentUser on RubyGems

License

It uses MIT license. See MIT-LICENSE file in the root directory.