authlogic 0.10.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of authlogic might be problematic. Click here for more details.

Files changed (102) hide show
  1. data/CHANGELOG.rdoc +47 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Manifest +100 -0
  4. data/README.rdoc +292 -0
  5. data/Rakefile +15 -0
  6. data/authlogic.gemspec +38 -0
  7. data/init.rb +1 -0
  8. data/lib/authlogic.rb +25 -0
  9. data/lib/authlogic/active_record/acts_as_authentic.rb +265 -0
  10. data/lib/authlogic/active_record/authenticates_many.rb +19 -0
  11. data/lib/authlogic/active_record/scoped_session.rb +28 -0
  12. data/lib/authlogic/controller_adapters/abstract_adapter.rb +25 -0
  13. data/lib/authlogic/controller_adapters/rails_adapter.rb +39 -0
  14. data/lib/authlogic/session/active_record_trickery.rb +26 -0
  15. data/lib/authlogic/session/base.rb +510 -0
  16. data/lib/authlogic/session/callbacks.rb +56 -0
  17. data/lib/authlogic/session/config.rb +237 -0
  18. data/lib/authlogic/session/errors.rb +18 -0
  19. data/lib/authlogic/sha512_crypto_provider.rb +18 -0
  20. data/lib/authlogic/version.rb +56 -0
  21. data/test_app/README +256 -0
  22. data/test_app/Rakefile +10 -0
  23. data/test_app/app/controllers/application.rb +72 -0
  24. data/test_app/app/controllers/companies_controller.rb +2 -0
  25. data/test_app/app/controllers/user_sessions_controller.rb +25 -0
  26. data/test_app/app/controllers/users_controller.rb +61 -0
  27. data/test_app/app/helpers/application_helper.rb +3 -0
  28. data/test_app/app/helpers/companies_helper.rb +2 -0
  29. data/test_app/app/helpers/user_sessions_helper.rb +2 -0
  30. data/test_app/app/helpers/users_helper.rb +2 -0
  31. data/test_app/app/models/company.rb +4 -0
  32. data/test_app/app/models/project.rb +3 -0
  33. data/test_app/app/models/user.rb +5 -0
  34. data/test_app/app/models/user_session.rb +3 -0
  35. data/test_app/app/views/layouts/application.html.erb +27 -0
  36. data/test_app/app/views/user_sessions/new.html.erb +15 -0
  37. data/test_app/app/views/users/_form.erb +15 -0
  38. data/test_app/app/views/users/edit.html.erb +8 -0
  39. data/test_app/app/views/users/new.html.erb +8 -0
  40. data/test_app/app/views/users/show.html.erb +29 -0
  41. data/test_app/config/boot.rb +109 -0
  42. data/test_app/config/database.yml +19 -0
  43. data/test_app/config/environment.rb +69 -0
  44. data/test_app/config/environments/development.rb +17 -0
  45. data/test_app/config/environments/production.rb +22 -0
  46. data/test_app/config/environments/test.rb +22 -0
  47. data/test_app/config/initializers/inflections.rb +10 -0
  48. data/test_app/config/initializers/mime_types.rb +5 -0
  49. data/test_app/config/initializers/new_rails_defaults.rb +17 -0
  50. data/test_app/config/routes.rb +11 -0
  51. data/test_app/db/development.sqlite3 +0 -0
  52. data/test_app/db/migrate/20081023040052_create_users.rb +20 -0
  53. data/test_app/db/migrate/20081103003828_create_companies.rb +14 -0
  54. data/test_app/db/migrate/20081103003834_create_projects.rb +18 -0
  55. data/test_app/db/schema.rb +46 -0
  56. data/test_app/db/test.sqlite3 +0 -0
  57. data/test_app/doc/README_FOR_APP +2 -0
  58. data/test_app/public/404.html +30 -0
  59. data/test_app/public/422.html +30 -0
  60. data/test_app/public/500.html +30 -0
  61. data/test_app/public/dispatch.cgi +10 -0
  62. data/test_app/public/dispatch.fcgi +24 -0
  63. data/test_app/public/dispatch.rb +10 -0
  64. data/test_app/public/favicon.ico +0 -0
  65. data/test_app/public/images/rails.png +0 -0
  66. data/test_app/public/javascripts/application.js +2 -0
  67. data/test_app/public/javascripts/controls.js +963 -0
  68. data/test_app/public/javascripts/dragdrop.js +972 -0
  69. data/test_app/public/javascripts/effects.js +1120 -0
  70. data/test_app/public/javascripts/prototype.js +4225 -0
  71. data/test_app/public/robots.txt +5 -0
  72. data/test_app/public/stylesheets/scaffold.css +62 -0
  73. data/test_app/script/about +4 -0
  74. data/test_app/script/console +3 -0
  75. data/test_app/script/dbconsole +3 -0
  76. data/test_app/script/destroy +3 -0
  77. data/test_app/script/generate +3 -0
  78. data/test_app/script/performance/benchmarker +3 -0
  79. data/test_app/script/performance/profiler +3 -0
  80. data/test_app/script/performance/request +3 -0
  81. data/test_app/script/plugin +3 -0
  82. data/test_app/script/process/inspector +3 -0
  83. data/test_app/script/process/reaper +3 -0
  84. data/test_app/script/process/spawner +3 -0
  85. data/test_app/script/runner +3 -0
  86. data/test_app/script/server +3 -0
  87. data/test_app/test/fixtures/companies.yml +7 -0
  88. data/test_app/test/fixtures/projects.yml +4 -0
  89. data/test_app/test/fixtures/users.yml +21 -0
  90. data/test_app/test/functional/companies_controller_test.rb +8 -0
  91. data/test_app/test/functional/user_sessions_controller_test.rb +36 -0
  92. data/test_app/test/functional/users_controller_test.rb +8 -0
  93. data/test_app/test/integration/company_user_session_stories_test.rb +46 -0
  94. data/test_app/test/integration/user_sesion_stories_test.rb +105 -0
  95. data/test_app/test/integration/user_session_config_test.rb +24 -0
  96. data/test_app/test/integration/user_session_test.rb +161 -0
  97. data/test_app/test/test_helper.rb +81 -0
  98. data/test_app/test/unit/account_test.rb +8 -0
  99. data/test_app/test/unit/company_test.rb +8 -0
  100. data/test_app/test/unit/project_test.rb +8 -0
  101. data/test_app/test/unit/user_test.rb +80 -0
  102. metadata +201 -0
@@ -0,0 +1,10 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require(File.join(File.dirname(__FILE__), 'config', 'boot'))
5
+
6
+ require 'rake'
7
+ require 'rake/testtask'
8
+ require 'rake/rdoctask'
9
+
10
+ require 'tasks/rails'
@@ -0,0 +1,72 @@
1
+ class ApplicationController < ActionController::Base
2
+ helper :all # include all helpers, all the time
3
+ protect_from_forgery # :secret => '3e944977657f54e55cb20d83a418ff65'
4
+ filter_parameter_logging :password, :confirm_password
5
+
6
+ helper_method :scoped_url
7
+
8
+ before_filter :load_company
9
+ before_filter :load_current_user
10
+
11
+ private
12
+ def load_company
13
+ if params[:company_id]
14
+ @current_company = Company.find_by_id(params[:company_id])
15
+ if @current_company.blank?
16
+ flash[:notice] = "The company specified could not be found"
17
+ redirect_to default_url
18
+ return false
19
+ end
20
+ end
21
+ end
22
+
23
+ def load_current_user
24
+ @session_owner = (@current_company && @current_company.user_sessions) || UserSession
25
+ @user_owner = (@current_company && @current_company.users) || User
26
+ @user_session = @session_owner.find
27
+ @current_user = @user_session && @user_session.record
28
+ end
29
+
30
+ def require_user
31
+ unless @current_user
32
+ store_location
33
+ flash[:notice] = "You must be logged in to access this page"
34
+ redirect_to scoped_url("new_user_session_url")
35
+ return false
36
+ end
37
+ end
38
+
39
+ def require_no_user
40
+ if @current_user
41
+ store_location
42
+ flash[:notice] = "You must be logged out to access this page"
43
+ redirect_to scoped_url("account_url")
44
+ return false
45
+ end
46
+ end
47
+
48
+ def prevent_store_location
49
+ @prevent_store_location = true
50
+ end
51
+
52
+ def scoped_url(unscoped_url, *args)
53
+ if @current_company
54
+ regex = /^(new|edit)_/
55
+ prefix = unscoped_url =~ regex ? "#{$1}_" : ""
56
+ send("#{prefix}company_#{unscoped_url.gsub(regex, "")}", @current_company.id, *args)
57
+ else
58
+ send(unscoped_url, *args)
59
+ end
60
+ end
61
+
62
+ def store_location
63
+ return if @prevent_store_location == true
64
+ session[:return_to] = request.request_uri
65
+ end
66
+
67
+ def redirect_back_or_default(default)
68
+ raise (session[:return_to] || default).inspect if (session[:return_to] || default) == nil
69
+ redirect_to(session[:return_to] || default)
70
+ session[:return_to] = nil
71
+ end
72
+ end
@@ -0,0 +1,2 @@
1
+ class CompaniesController < ApplicationController
2
+ end
@@ -0,0 +1,25 @@
1
+ class UserSessionsController < ApplicationController
2
+ before_filter :prevent_store_location, :only => [:destroy, :create]
3
+ before_filter :require_no_user, :only => [:new, :create]
4
+ before_filter :require_user, :only => :destroy
5
+
6
+ def new
7
+ @user_session = @session_owner.new
8
+ end
9
+
10
+ def create
11
+ @user_session = @session_owner.new(params[:user_session])
12
+ if @user_session.save
13
+ flash[:notice] = "Login successful!"
14
+ redirect_back_or_default(scoped_url("account_url"))
15
+ else
16
+ render :action => :new
17
+ end
18
+ end
19
+
20
+ def destroy
21
+ @user_session.destroy
22
+ flash[:notice] = "Logout successful!"
23
+ redirect_back_or_default(scoped_url("new_user_session_url"))
24
+ end
25
+ end
@@ -0,0 +1,61 @@
1
+ class UsersController < ApplicationController
2
+ before_filter :require_no_user, :only => [:new, :create]
3
+ before_filter :require_user, :only => [:edit, :update]
4
+ before_filter :load_user, :except => [:new, :create]
5
+
6
+ def new
7
+ @user = @user_owner.new
8
+ end
9
+
10
+ def create
11
+ @user = @user_owner.new(params[:user])
12
+ if @user.save
13
+ flash[:notice] = "Account registered!"
14
+ redirect_to scoped_url("account_path")
15
+ else
16
+ render :action => :new
17
+ end
18
+ end
19
+
20
+ def show
21
+ if @user
22
+ @user.update_attribute(:profile_views, @user.profile_views + 1) if @user && params[:id]
23
+ else
24
+ flash[:notice] = "We're sorry, but no user was found"
25
+ redirect_to scoped_url("new_user_session_url")
26
+ end
27
+ end
28
+
29
+ # This is a method created for tests only, to make sure users logged out get logged in when changing passwords
30
+ def reset_password
31
+ if @user
32
+ @user.password = "saweet"
33
+ @user.confirm_password = "saweet"
34
+ @user.save
35
+ else
36
+ flash[:notice] = "We're sorry, but no user was found"
37
+ redirect_to scoped_url("new_user_session_url")
38
+ end
39
+ end
40
+
41
+ def update
42
+ @user = @current_user
43
+ @user.attributes = params[:user]
44
+ if @user.save
45
+ flash[:notice] = "Account updated!"
46
+ redirect_to scoped_url("account_path")
47
+ else
48
+ render :action => :edit
49
+ end
50
+ end
51
+
52
+ private
53
+ def load_user
54
+ if params[:id]
55
+ @user = @user_owner.find_by_id(params[:id])
56
+ @user.update_attribute(:profile_views, @user.profile_views + 1) if @user
57
+ else
58
+ @user = @current_user
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,3 @@
1
+ # Methods added to this helper will be available to all templates in the application.
2
+ module ApplicationHelper
3
+ end
@@ -0,0 +1,2 @@
1
+ module CompaniesHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module UserSessionsHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module UsersHelper
2
+ end
@@ -0,0 +1,4 @@
1
+ class Company < ActiveRecord::Base
2
+ has_many :users, :dependent => :destroy
3
+ authenticates_many :user_sessions, :scope_cookies => true
4
+ end
@@ -0,0 +1,3 @@
1
+ class Project < ActiveRecord::Base
2
+ has_and_belongs_to_many :users
3
+ end
@@ -0,0 +1,5 @@
1
+ class User < ActiveRecord::Base
2
+ acts_as_authentic
3
+ has_and_belongs_to_many :projects
4
+ belongs_to :company
5
+ end
@@ -0,0 +1,3 @@
1
+ class UserSession < Authlogic::Session::Base
2
+ remember_me true
3
+ end
@@ -0,0 +1,27 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
7
+ <title><%= controller.controller_name %>: <%= controller.action_name %></title>
8
+ <%= stylesheet_link_tag 'scaffold' %>
9
+ </head>
10
+ <body>
11
+
12
+ <% if @company %><h1><%= @company.name %></h1><% end %>
13
+
14
+ <% if !@current_user %>
15
+ <%= link_to "Register", scoped_url("new_account_path") %> |
16
+ <%= link_to "Log In", scoped_url("new_user_session_path") %>
17
+ <% else %>
18
+ <%= link_to "My Account", scoped_url("account_path") %> |
19
+ <%= link_to "Logout", scoped_url("user_session_path"), :method => :delete, :confirm => "Are you sure you want to logout?" %>
20
+ <% end %>
21
+
22
+ <p style="color: green"><%= flash[:notice] %></p>
23
+
24
+ <%= yield %>
25
+
26
+ </body>
27
+ </html>
@@ -0,0 +1,15 @@
1
+ <h1>Login</h1>
2
+
3
+ <%= error_messages_for "user_session", :header_message => nil %>
4
+
5
+ <% form_for @user_session, :url => scoped_url("user_session_path") do |f| %>
6
+ <%= f.label :login %><br />
7
+ <%= f.text_field :login %><br />
8
+ <br />
9
+ <%= f.label :password %><br />
10
+ <%= f.password_field :password %><br />
11
+ <br />
12
+ <%= f.check_box :remember_me %><%= f.label :remember_me %><br />
13
+ <br />
14
+ <%= f.submit "Login" %>
15
+ <% end %>
@@ -0,0 +1,15 @@
1
+ <%= form.label :login %><br />
2
+ <%= form.text_field :login %><br />
3
+ <br />
4
+ <%= form.label :password, form.object.new_record? ? nil : "Change password" %><br />
5
+ <%= form.password_field :password %><br />
6
+ <br />
7
+ <%= form.label :confirm_password%><br />
8
+ <%= form.password_field :confirm_password %><br />
9
+ <br />
10
+ <%= form.label :first_name %><br />
11
+ <%= form.text_field :first_name %><br />
12
+ <br />
13
+ <%= form.label :last_name %><br />
14
+ <%= form.text_field :last_name %><br />
15
+ <br />
@@ -0,0 +1,8 @@
1
+ <h1>Edit My Account</h1>
2
+
3
+ <%= error_messages_for "user" %>
4
+
5
+ <% form_for @user, :url => scoped_url("account_path") do |f| %>
6
+ <%= render :partial => "form", :object => f %>
7
+ <%= f.submit "Update" %>
8
+ <% end %>
@@ -0,0 +1,8 @@
1
+ <h1>Register</h1>
2
+
3
+ <%= error_messages_for "user" %>
4
+
5
+ <% form_for @user, :url => scoped_url("account_path") do |f| %>
6
+ <%= render :partial => "form", :object => f %>
7
+ <%= f.submit "Register" %>
8
+ <% end %>
@@ -0,0 +1,29 @@
1
+ <h1><%= @user.login %></h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <td>Login:</td>
6
+ <td><%= @user.login %></td>
7
+ </tr>
8
+ <tr>
9
+ <td>Login count:</td>
10
+ <td><%= @user.login_count %></td>
11
+ </tr>
12
+ <tr>
13
+ <td>Profile views:</td>
14
+ <td><%= @user.profile_views %></td>
15
+ </tr>
16
+ <tr>
17
+ <td>First name:</td>
18
+ <td><%= @user.first_name %></td>
19
+ </tr>
20
+ <tr>
21
+ <td>Last name:</td>
22
+ <td><%= @user.last_name %></td>
23
+ </tr>
24
+ </table>
25
+ <br />
26
+
27
+ <% if @user == @current_user %>
28
+ <%= link_to "Edit", scoped_url("edit_account_path") %><br />
29
+ <% end %>
@@ -0,0 +1,109 @@
1
+ # Don't change this file!
2
+ # Configure your app in config/environment.rb and config/environments/*.rb
3
+
4
+ RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
5
+
6
+ module Rails
7
+ class << self
8
+ def boot!
9
+ unless booted?
10
+ preinitialize
11
+ pick_boot.run
12
+ end
13
+ end
14
+
15
+ def booted?
16
+ defined? Rails::Initializer
17
+ end
18
+
19
+ def pick_boot
20
+ (vendor_rails? ? VendorBoot : GemBoot).new
21
+ end
22
+
23
+ def vendor_rails?
24
+ File.exist?("#{RAILS_ROOT}/vendor/rails")
25
+ end
26
+
27
+ def preinitialize
28
+ load(preinitializer_path) if File.exist?(preinitializer_path)
29
+ end
30
+
31
+ def preinitializer_path
32
+ "#{RAILS_ROOT}/config/preinitializer.rb"
33
+ end
34
+ end
35
+
36
+ class Boot
37
+ def run
38
+ load_initializer
39
+ Rails::Initializer.run(:set_load_path)
40
+ end
41
+ end
42
+
43
+ class VendorBoot < Boot
44
+ def load_initializer
45
+ require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
46
+ Rails::Initializer.run(:install_gem_spec_stubs)
47
+ end
48
+ end
49
+
50
+ class GemBoot < Boot
51
+ def load_initializer
52
+ self.class.load_rubygems
53
+ load_rails_gem
54
+ require 'initializer'
55
+ end
56
+
57
+ def load_rails_gem
58
+ if version = self.class.gem_version
59
+ gem 'rails', version
60
+ else
61
+ gem 'rails'
62
+ end
63
+ rescue Gem::LoadError => load_error
64
+ $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
65
+ exit 1
66
+ end
67
+
68
+ class << self
69
+ def rubygems_version
70
+ Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion
71
+ end
72
+
73
+ def gem_version
74
+ if defined? RAILS_GEM_VERSION
75
+ RAILS_GEM_VERSION
76
+ elsif ENV.include?('RAILS_GEM_VERSION')
77
+ ENV['RAILS_GEM_VERSION']
78
+ else
79
+ parse_gem_version(read_environment_rb)
80
+ end
81
+ end
82
+
83
+ def load_rubygems
84
+ require 'rubygems'
85
+ min_version = '1.1.1'
86
+ unless rubygems_version >= min_version
87
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
88
+ exit 1
89
+ end
90
+
91
+ rescue LoadError
92
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
93
+ exit 1
94
+ end
95
+
96
+ def parse_gem_version(text)
97
+ $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
98
+ end
99
+
100
+ private
101
+ def read_environment_rb
102
+ File.read("#{RAILS_ROOT}/config/environment.rb")
103
+ end
104
+ end
105
+ end
106
+ end
107
+
108
+ # All that for this:
109
+ Rails.boot!
@@ -0,0 +1,19 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3-ruby (not necessary on OS X Leopard)
3
+ development:
4
+ adapter: sqlite3
5
+ database: db/development.sqlite3
6
+ timeout: 5000
7
+
8
+ # Warning: The database defined as "test" will be erased and
9
+ # re-generated from your development database when you run "rake".
10
+ # Do not set this db to the same as development or production.
11
+ test:
12
+ adapter: sqlite3
13
+ database: db/test.sqlite3
14
+ timeout: 5000
15
+
16
+ production:
17
+ adapter: sqlite3
18
+ database: db/production.sqlite3
19
+ timeout: 5000