<commit_before>h1. Clearance

Simple, complete Ruby web app authentication. 

"We have clearance, Clarence.":http://www.youtube.com/v/mNRXJEE3Nz8

h2. Gem installation (Rails 2.1+)

Specify the gem dependency in your config/environment.rb file:

    Rails::Initializer.run do |config|
      # ...
      config.gem 'thoughtbot-shoulda', :lib => 'shoulda', :source => "http://gems.github.com"
      config.gem 'thoughtbot-factory_girl', :lib => 'factory_girl', :source => "http://gems.github.com"
      config.gem "thoughtbot-clearance", :lib => 'clearance', :source => 'http://gems.github.com/'
    end

Then:

    rake gems:install
    rake gems:unpack

h2. Generator

In a greenfield application, just run the generator:

    script/generate clearance

This will create:

    app/controllers/confirmations_controller.rb
    app/controllers/passwords_controller.rb
    app/controllers/sessions_controller.rb
    app/controllers/users_controller.rb
    app/models/user.rb
    app/models/user_mailer.rb
    app/views/confirmations/new.html.erb
    app/views/passwords/edit.html.erb
    app/views/passwords/new.html.erb
    app/views/sessions/new.html.erb
    app/views/user_mailer/change_password.html.erb
    app/views/user_mailer/confirmation.html.erb
    app/views/users/_form.html.erb
    app/views/users/edit.html.erb
    app/views/users/new.html.erb
    test/functional/confirmations_controller_test.rb
    test/functional/passwords_controller_test.rb
    test/functional/sessions_controller_test.rb
    test/functional/users_controller_test.rb
    test/unit/user_mailer_test.rb
    test/unit/user_test.rb

Add the corresponding Clearance module for any file(s) you don't want to override. They are namespaced exactly like the directory structure of a Rails app: 

    app/models/user.rb already exists.
    include Clearance::App::Models::User

h2. Tests

The tests use "Shoulda":http://thoughtbot.com/projects/shoulda >= 2.0.4 and "Factory Girl":http://thoughtbot.com/projects/factory_girl. You should create a User Factory:

    Factory.sequence :email do |n|
      "<EMAIL>"
    end

    Factory.define :user do |user|
      user.email { Factory.next :email }
      user.password "password"
      user.password_confirmation "password"
    end

In test/test_helper.rb: 

    class Test::Unit::TestCase
      self.use_transactional_fixtures = true
      self.use_instantiated_fixtures  = false
      include Clearance::Test::TestHelper
    end

h2. Controllers

In app/controllers/application_controller.rb:

    class ApplicationController < ActionController::Base
      helper :all
      protect_from_forgery
      include Clearance::App::Controllers::ApplicationController
    end

h2. Migration

Your users table needs a few columns.

    create_table(:users) do |t|
      t.string :email
      t.string :crypted_password, :limit => 40
      t.string :salt, :limit => 40
      t.string :remember_token
      t.datetime :remember_token_expires_at
      t.boolean :confirmed, :default => false, :null => false
    end

    add_index :users, [:email, :crypted_password]

h2. Routes

    ActionController::Routing::Routes.draw do |map|
      
      map.resources :users
		  map.resource :session
		  map.resources :users, :has_one => :password
		  map.resources :users, :has_one => :confirmation
		  map.resources :passwords
		  map.root :controller => 'sessions', :action => 'new'
      
    end

h2. Environments

In config/environments/test.rb and config/environments/development.rb:<commit_msg>Reformatting a bit of indentation in the README<commit_after>h1. Clearance

Simple, complete Ruby web app authentication. 

"We have clearance, Clarence.":http://www.youtube.com/v/mNRXJEE3Nz8

h2. Gem installation (Rails 2.1+)

Specify the gem dependency in your config/environment.rb file:

    Rails::Initializer.run do |config|
      # ...
      config.gem 'thoughtbot-shoulda', :lib => 'shoulda', :source => "http://gems.github.com"
      config.gem 'thoughtbot-factory_girl', :lib => 'factory_girl', :source => "http://gems.github.com"
      config.gem "thoughtbot-clearance", :lib => 'clearance', :source => 'http://gems.github.com/'
    end

Then:

    rake gems:install
    rake gems:unpack

h2. Generator

In a greenfield application, just run the generator:

    script/generate clearance

This will create:

    app/controllers/confirmations_controller.rb
    app/controllers/passwords_controller.rb
    app/controllers/sessions_controller.rb
    app/controllers/users_controller.rb
    app/models/user.rb
    app/models/user_mailer.rb
    app/views/confirmations/new.html.erb
    app/views/passwords/edit.html.erb
    app/views/passwords/new.html.erb
    app/views/sessions/new.html.erb
    app/views/user_mailer/change_password.html.erb
    app/views/user_mailer/confirmation.html.erb
    app/views/users/_form.html.erb
    app/views/users/edit.html.erb
    app/views/users/new.html.erb
    test/functional/confirmations_controller_test.rb
    test/functional/passwords_controller_test.rb
    test/functional/sessions_controller_test.rb
    test/functional/users_controller_test.rb
    test/unit/user_mailer_test.rb
    test/unit/user_test.rb

Add the corresponding Clearance module for any file(s) you don't want to override. They are namespaced exactly like the directory structure of a Rails app: 

    app/models/user.rb already exists.
    include Clearance::App::Models::User

h2. Tests

The tests use "Shoulda":http://thoughtbot.com/projects/shoulda >= 2.0.4 and "Factory Girl":http://thoughtbot.com/projects/factory_girl. You should create a User Factory:

    Factory.sequence :email do |n|
      "<EMAIL>"
    end

    Factory.define :user do |user|
      user.email { Factory.next :email }
      user.password "password"
      user.password_confirmation "password"
    end

In test/test_helper.rb: 

    class Test::Unit::TestCase
      self.use_transactional_fixtures = true
      self.use_instantiated_fixtures  = false
      include Clearance::Test::TestHelper
    end

h2. Controllers

In app/controllers/application_controller.rb:

    class ApplicationController < ActionController::Base
      helper :all
      protect_from_forgery
      include Clearance::App::Controllers::ApplicationController
    end

h2. Migration

Your users table needs a few columns.

    create_table(:users) do |t|
      t.string :email
      t.string :crypted_password, :limit => 40
      t.string :salt, :limit => 40
      t.string :remember_token
      t.datetime :remember_token_expires_at
      t.boolean :confirmed, :default => false, :null => false
    end

    add_index :users, [:email, :crypted_password]

h2. Routes

    map.resources :users
    map.resource :session
    map.resources :users, :has_one => :password
    map.resources :users, :has_one => :confirmation
    map.resources :passwords
    map.root :controller => 'sessions', :action => 'new'

h2. Environments

In config/environments/test.rb and config/environments/development.rb:
{'fraction_non_alphanumeric': 0.10551248923341947, 'fraction_numerical': 0.005455067470571347, 'mean_word_length': 3.417882054533925, 'pattern_counts': {'":': 6, '<': 7, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1402079', 'n_tokens_mistral': 2280, 'n_tokens_neox': 2172, 'n_words': 490}