Skip to content

Instantly share code, notes, and snippets.

@JohnPlummer
Created January 21, 2011 14:36
Show Gist options
  • Save JohnPlummer/789743 to your computer and use it in GitHub Desktop.
Save JohnPlummer/789743 to your computer and use it in GitHub Desktop.
Add authentication with devise - install and configure
!!! XML
!!!
%html
%head
%title haml page
= stylesheet_link_tag :all
= javascript_include_tag :defaults
%body
%p.notice #{notice}
%p.alert #{alert}
= yield
Agate::Application.configure do
...
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
end
...
Devise.setup do |config|
...
config.mailer_sender = "john@furld.com"
...
config.mailer = "Devise::Mailer"
...
require 'devise/orm/active_record'
...
config.authentication_keys = [ :username ]
...
config.case_insensitive_keys = [ :email, :username ]
...
config.stretches = 10
...
config.confirmation_keys = [ :username ]
...
config.remember_for = 2.weeks
...
config.use_salt_as_remember_token = true
...
config.timeout_in = 30.minutes
...
config.lock_strategy = :failed_attempts
...
config.unlock_keys = [ :username ]
...
config.unlock_strategy = :both
...
config.maximum_attempts = 20
...
config.unlock_in = 1.hour
...
config.reset_password_keys = [ :username ]
...
end
class DeviseCreateUsers < ActiveRecord::Migration
def self.up
create_table(:users) do |t|
t.database_authenticatable :null => false
t.recoverable
t.rememberable
t.trackable
# t.encryptable
t.confirmable
t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both
# t.token_authenticatable
t.timestamps
end
add_column :users, :username, :string, {:default=>"", :null=>false}
add_index :users, :email
add_index :users, :username, :unique => true
add_index :users, :reset_password_token, :unique => true
add_index :users, :confirmation_token, :unique => true
add_index :users, :unlock_token, :unique => true
# add_index :users, :authentication_token, :unique => true
end
def self.down
drop_table :users
end
end
source 'http://rubygems.org'
gem 'rails', '3.0.3'
gem 'sqlite3-ruby', :require => 'sqlite3'
gem 'haml'
gem 'jquery-rails'
# Authentication
gem 'devise', :git => "git://github.com/JohnPlummer/devise.git"
group :development, :test do
gem 'rspec-rails'
gem 'cucumber-rails'
gem 'shoulda'
gem 'capybara'
gem 'launchy'
gem 'spork'
gem 'autotest-standalone'
gem 'autotest-growl'
gem 'autotest-fsevent'
gem 'autotest-rails-pure'
gem 'factory_girl_rails'
gem 'annotate-models'
gem 'haml-rails'
gem 'hpricot'
gem 'ruby_parser'
end
Agate::Application.routes.draw do
...
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
root :to => "home#index"
...
end
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :validatable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable,
:confirmable, :lockable, :timeoutable
# Setup accessible (or protected) attributes for your model
attr_accessible :username, :email, :password, :password_confirmation, :remember_me
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment