authgasm 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/Manifest +85 -0
  3. data/README.rdoc +164 -0
  4. data/Rakefile +15 -0
  5. data/authgasm.gemspec +183 -0
  6. data/init.rb +2 -0
  7. data/lib/authgasm.rb +18 -0
  8. data/lib/authgasm/acts_as_authentic.rb +200 -0
  9. data/lib/authgasm/controller.rb +16 -0
  10. data/lib/authgasm/session/active_record_trickery.rb +30 -0
  11. data/lib/authgasm/session/base.rb +365 -0
  12. data/lib/authgasm/session/callbacks.rb +47 -0
  13. data/lib/authgasm/session/config.rb +193 -0
  14. data/lib/authgasm/session/errors.rb +12 -0
  15. data/lib/authgasm/sha256_crypto_provider.rb +13 -0
  16. data/lib/authgasm/version.rb +56 -0
  17. data/test_app/README +256 -0
  18. data/test_app/Rakefile +10 -0
  19. data/test_app/app/controllers/application.rb +46 -0
  20. data/test_app/app/controllers/user_sessions_controller.rb +25 -0
  21. data/test_app/app/controllers/users_controller.rb +37 -0
  22. data/test_app/app/helpers/application_helper.rb +3 -0
  23. data/test_app/app/helpers/user_sessions_helper.rb +2 -0
  24. data/test_app/app/helpers/users_helper.rb +2 -0
  25. data/test_app/app/models/user.rb +3 -0
  26. data/test_app/app/models/user_session.rb +3 -0
  27. data/test_app/app/views/asses/edit.html.erb +12 -0
  28. data/test_app/app/views/asses/index.html.erb +18 -0
  29. data/test_app/app/views/asses/new.html.erb +11 -0
  30. data/test_app/app/views/asses/show.html.erb +3 -0
  31. data/test_app/app/views/layouts/application.html.erb +25 -0
  32. data/test_app/app/views/user_sessions/new.html.erb +13 -0
  33. data/test_app/app/views/users/_form.erb +15 -0
  34. data/test_app/app/views/users/edit.html.erb +8 -0
  35. data/test_app/app/views/users/new.html.erb +8 -0
  36. data/test_app/app/views/users/show.html.erb +19 -0
  37. data/test_app/config/boot.rb +109 -0
  38. data/test_app/config/database.yml +19 -0
  39. data/test_app/config/environment.rb +69 -0
  40. data/test_app/config/environments/development.rb +17 -0
  41. data/test_app/config/environments/production.rb +22 -0
  42. data/test_app/config/environments/test.rb +22 -0
  43. data/test_app/config/initializers/inflections.rb +10 -0
  44. data/test_app/config/initializers/mime_types.rb +5 -0
  45. data/test_app/config/initializers/new_rails_defaults.rb +17 -0
  46. data/test_app/config/routes.rb +7 -0
  47. data/test_app/db/development.sqlite3 +0 -0
  48. data/test_app/db/migrate/20081023040052_create_users.rb +17 -0
  49. data/test_app/db/schema.rb +25 -0
  50. data/test_app/db/test.sqlite3 +0 -0
  51. data/test_app/doc/README_FOR_APP +2 -0
  52. data/test_app/public/404.html +30 -0
  53. data/test_app/public/422.html +30 -0
  54. data/test_app/public/500.html +30 -0
  55. data/test_app/public/dispatch.cgi +10 -0
  56. data/test_app/public/dispatch.fcgi +24 -0
  57. data/test_app/public/dispatch.rb +10 -0
  58. data/test_app/public/favicon.ico +0 -0
  59. data/test_app/public/images/rails.png +0 -0
  60. data/test_app/public/javascripts/application.js +2 -0
  61. data/test_app/public/javascripts/controls.js +963 -0
  62. data/test_app/public/javascripts/dragdrop.js +972 -0
  63. data/test_app/public/javascripts/effects.js +1120 -0
  64. data/test_app/public/javascripts/prototype.js +4225 -0
  65. data/test_app/public/robots.txt +5 -0
  66. data/test_app/public/stylesheets/scaffold.css +62 -0
  67. data/test_app/script/about +4 -0
  68. data/test_app/script/console +3 -0
  69. data/test_app/script/dbconsole +3 -0
  70. data/test_app/script/destroy +3 -0
  71. data/test_app/script/generate +3 -0
  72. data/test_app/script/performance/benchmarker +3 -0
  73. data/test_app/script/performance/profiler +3 -0
  74. data/test_app/script/performance/request +3 -0
  75. data/test_app/script/plugin +3 -0
  76. data/test_app/script/process/inspector +3 -0
  77. data/test_app/script/process/reaper +3 -0
  78. data/test_app/script/process/spawner +3 -0
  79. data/test_app/script/runner +3 -0
  80. data/test_app/script/server +3 -0
  81. data/test_app/test/fixtures/users.yml +6 -0
  82. data/test_app/test/functional/user_sessions_controller_test.rb +15 -0
  83. data/test_app/test/functional/users_controller_test.rb +8 -0
  84. data/test_app/test/test_helper.rb +38 -0
  85. data/test_app/test/unit/ass_test.rb +8 -0
  86. data/test_app/test/unit/user_test.rb +8 -0
  87. metadata +182 -0
data/test_app/Rakefile ADDED
@@ -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,46 @@
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
+ before_filter :load_current_user
7
+
8
+ private
9
+ def load_current_user
10
+ @user_session = UserSession.find
11
+ @current_user = @user_session && @user_session.record
12
+ end
13
+
14
+ def require_user
15
+ unless @current_user
16
+ store_location
17
+ flash[:notice] = "You must be logged in to access this page"
18
+ redirect_to new_user_session_url
19
+ return false
20
+ end
21
+ end
22
+
23
+ def require_no_user
24
+ if @current_user
25
+ store_location
26
+ flash[:notice] = "You must be logged out to access this page"
27
+ redirect_to account_url
28
+ return false
29
+ end
30
+ end
31
+
32
+ def prevent_store_location
33
+ @prevent_store_location = true
34
+ end
35
+
36
+ def store_location
37
+ return if @prevent_store_location == true
38
+ session[:return_to] = request.request_uri
39
+ end
40
+
41
+ def redirect_back_or_default(default)
42
+ raise (session[:return_to] || default).inspect if (session[:return_to] || default) == nil
43
+ redirect_to(session[:return_to] || default)
44
+ session[:return_to] = nil
45
+ end
46
+ 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 = UserSession.new
8
+ end
9
+
10
+ def create
11
+ @user_session = UserSession.new(params[:user_session])
12
+ if @user_session.create
13
+ flash[:notice] = "Login successful!"
14
+ redirect_back_or_default(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(new_user_session_url)
24
+ end
25
+ end
@@ -0,0 +1,37 @@
1
+ class UsersController < ApplicationController
2
+ before_filter :require_no_user, :only => [:new, :create]
3
+ before_filter :require_user, :only => [:show, :edit, :update]
4
+
5
+ def new
6
+ @user = User.new
7
+ end
8
+
9
+ def create
10
+ @user = User.new(params[:user])
11
+ if @user.save
12
+ flash[:notice] = "Account registered!"
13
+ redirect_to account_path
14
+ else
15
+ render :action => :new
16
+ end
17
+ end
18
+
19
+ def show
20
+ @user = @current_user
21
+ end
22
+
23
+ def edit
24
+ @user = @current_user
25
+ end
26
+
27
+ def update
28
+ @user = @current_user
29
+ @user.attributes = params[:user]
30
+ if @user.save
31
+ flash[:notice] = "Account updated!"
32
+ redirect_to account_path
33
+ else
34
+ render :action => :edit
35
+ end
36
+ end
37
+ 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 UserSessionsHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module UsersHelper
2
+ end
@@ -0,0 +1,3 @@
1
+ class User < ActiveRecord::Base
2
+ acts_as_authentic
3
+ end
@@ -0,0 +1,3 @@
1
+ class UserSession < Authgasm::Session::Base
2
+
3
+ end
@@ -0,0 +1,12 @@
1
+ <h1>Editing ass</h1>
2
+
3
+ <% form_for(@ass) do |f| %>
4
+ <%= f.error_messages %>
5
+
6
+ <p>
7
+ <%= f.submit "Update" %>
8
+ </p>
9
+ <% end %>
10
+
11
+ <%= link_to 'Show', @ass %> |
12
+ <%= link_to 'Back', asses_path %>
@@ -0,0 +1,18 @@
1
+ <h1>Listing asses</h1>
2
+
3
+ <table>
4
+ <tr>
5
+ </tr>
6
+
7
+ <% for ass in @asses %>
8
+ <tr>
9
+ <td><%= link_to 'Show', ass %></td>
10
+ <td><%= link_to 'Edit', edit_ass_path(ass) %></td>
11
+ <td><%= link_to 'Destroy', ass, :confirm => 'Are you sure?', :method => :delete %></td>
12
+ </tr>
13
+ <% end %>
14
+ </table>
15
+
16
+ <br />
17
+
18
+ <%= link_to 'New ass', new_ass_path %>
@@ -0,0 +1,11 @@
1
+ <h1>New ass</h1>
2
+
3
+ <% form_for(@ass) do |f| %>
4
+ <%= f.error_messages %>
5
+
6
+ <p>
7
+ <%= f.submit "Create" %>
8
+ </p>
9
+ <% end %>
10
+
11
+ <%= link_to 'Back', asses_path %>
@@ -0,0 +1,3 @@
1
+
2
+ <%= link_to 'Edit', edit_ass_path(@ass) %> |
3
+ <%= link_to 'Back', asses_path %>
@@ -0,0 +1,25 @@
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 !@current_user %>
13
+ <%= link_to "Register", new_user_path %> |
14
+ <%= link_to "Log In", new_user_session_path %>
15
+ <% else %>
16
+ <%= link_to "My Account", account_path %> |
17
+ <%= link_to "Logout", logout_path, :confirm => "Are you sure you want to logout?" %>
18
+ <% end %>
19
+
20
+ <p style="color: green"><%= flash[:notice] %></p>
21
+
22
+ <%= yield %>
23
+
24
+ </body>
25
+ </html>
@@ -0,0 +1,13 @@
1
+ <h1>Login</h1>
2
+
3
+ <%= error_messages_for "user_session", :header_message => nil %>
4
+
5
+ <% form_for @user_session 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.submit "Login" %>
13
+ <% 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 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 do |f| %>
6
+ <%= render :partial => "form", :object => f %>
7
+ <%= f.submit "Register" %>
8
+ <% end %>
@@ -0,0 +1,19 @@
1
+ <h1><%= @current_user.login %></h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <td>Login:</td>
6
+ <td><%= @current_user.login %></td>
7
+ </tr>
8
+ <tr>
9
+ <td>First name:</td>
10
+ <td><%= @current_user.first_name %></td>
11
+ </tr>
12
+ <tr>
13
+ <td>Last name:</td>
14
+ <td><%= @current_user.last_name %></td>
15
+ </tr>
16
+ </table>
17
+ <br />
18
+
19
+ <%= link_to "Edit", edit_account_path %><br />
@@ -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
@@ -0,0 +1,69 @@
1
+ # Be sure to restart your server when you modify this file
2
+
3
+ # Uncomment below to force Rails into production mode when
4
+ # you don't control web/app server and can't set it the proper way
5
+ # ENV['RAILS_ENV'] ||= 'production'
6
+
7
+ # Specifies gem version of Rails to use when vendor/rails is not present
8
+ RAILS_GEM_VERSION = '2.1.1' unless defined? RAILS_GEM_VERSION
9
+
10
+ # Bootstrap the Rails environment, frameworks, and default configuration
11
+ require File.join(File.dirname(__FILE__), 'boot')
12
+
13
+ Rails::Initializer.run do |config|
14
+ # Settings in config/environments/* take precedence over those specified here.
15
+ # Application configuration should go into files in config/initializers
16
+ # -- all .rb files in that directory are automatically loaded.
17
+ # See Rails::Configuration for more options.
18
+
19
+ # Skip frameworks you're not going to use. To use Rails without a database
20
+ # you must remove the Active Record framework.
21
+ # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
22
+
23
+ # Specify gems that this application depends on.
24
+ # They can then be installed with "rake gems:install" on new installations.
25
+ # config.gem "bj"
26
+ # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
27
+ # config.gem "aws-s3", :lib => "aws/s3"
28
+
29
+ # Only load the plugins named here, in the order given. By default, all plugins
30
+ # in vendor/plugins are loaded in alphabetical order.
31
+ # :all can be used as a placeholder for all plugins not explicitly named
32
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
33
+ config.plugin_paths += ["#{RAILS_ROOT}/../.."]
34
+ config.plugins = [:authgasm]
35
+
36
+ # Add additional load paths for your own custom dirs
37
+ # config.load_paths += %W( #{RAILS_ROOT}/extras )
38
+
39
+ # Force all environments to use the same logger level
40
+ # (by default production uses :info, the others :debug)
41
+ # config.log_level = :debug
42
+
43
+ # Make Time.zone default to the specified zone, and make Active Record store time values
44
+ # in the database in UTC, and return them converted to the specified local zone.
45
+ # Run "rake -D time" for a list of tasks for finding time zone names. Comment line to use default local time.
46
+ config.time_zone = 'UTC'
47
+
48
+ # Your secret key for verifying cookie session data integrity.
49
+ # If you change this key, all old sessions will become invalid!
50
+ # Make sure the secret is at least 30 characters and all random,
51
+ # no regular words or you'll be exposed to dictionary attacks.
52
+ config.action_controller.session = {
53
+ :session_key => '_test_app_session',
54
+ :secret => '2077420310120803c5ab6afbe99b0f51e1e9c6fd2bc931920dd5b33c1526c889ef379d31f7d87c31878c3356aaf020d1b541c40567e870ff4e363bd34b73fb8b'
55
+ }
56
+
57
+ # Use the database for sessions instead of the cookie-based default,
58
+ # which shouldn't be used to store highly confidential information
59
+ # (create the session table with "rake db:sessions:create")
60
+ # config.action_controller.session_store = :active_record_store
61
+
62
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
63
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
64
+ # like if you have constraints or database-specific column types
65
+ # config.active_record.schema_format = :sql
66
+
67
+ # Activate observers that should always be running
68
+ #config.active_record.observers = [:user_observer]
69
+ end