Permalink
Browse files

Released v0.10.4

  • Loading branch information...
1 parent 38b6e9b commit 43e849c6cadf9e0fa93fe2295f86ec16c935f374 @binarylogic binarylogic committed Nov 3, 2008
Showing with 611 additions and 270 deletions.
  1. +1 −0 CHANGELOG.rdoc
  2. +27 −11 Manifest
  3. +113 −82 README.rdoc
  4. +5 −5 Rakefile
  5. +1 −1 init.rb
  6. +0 −21 lib/authgasm.rb
  7. +25 −0 lib/authlogic.rb
  8. +36 −40 lib/{authgasm → authlogic/active_record}/acts_as_authentic.rb
  9. +19 −0 lib/authlogic/active_record/authenticates_many.rb
  10. +28 −0 lib/authlogic/active_record/scoped_session.rb
  11. +2 −2 lib/{authgasm → authlogic}/controller_adapters/abstract_adapter.rb
  12. +5 −5 lib/{authgasm → authlogic}/controller_adapters/rails_adapter.rb
  13. +3 −3 lib/{authgasm → authlogic}/session/active_record_trickery.rb
  14. +107 −21 lib/{authgasm → authlogic}/session/base.rb
  15. +2 −2 lib/{authgasm → authlogic}/session/callbacks.rb
  16. +10 −6 lib/{authgasm → authlogic}/session/config.rb
  17. +2 −2 lib/{authgasm → authlogic}/session/errors.rb
  18. +2 −2 lib/{authgasm → authlogic}/sha512_crypto_provider.rb
  19. +2 −2 lib/{authgasm → authlogic}/version.rb
  20. +29 −3 test_app/app/controllers/application.rb
  21. +2 −0 test_app/app/controllers/companies_controller.rb
  22. +4 −4 test_app/app/controllers/user_sessions_controller.rb
  23. +7 −7 test_app/app/controllers/users_controller.rb
  24. +2 −0 test_app/app/helpers/companies_helper.rb
  25. +0 −3 test_app/app/models/account.rb
  26. +4 −0 test_app/app/models/company.rb
  27. +3 −0 test_app/app/models/project.rb
  28. +2 −1 test_app/app/models/user.rb
  29. +1 −1 test_app/app/models/user_session.rb
  30. +7 −5 test_app/app/views/layouts/application.html.erb
  31. +1 −1 test_app/app/views/user_sessions/new.html.erb
  32. +1 −1 test_app/app/views/users/edit.html.erb
  33. +1 −1 test_app/app/views/users/new.html.erb
  34. +1 −1 test_app/app/views/users/show.html.erb
  35. +1 −1 test_app/config/environment.rb
  36. +5 −0 test_app/config/routes.rb
  37. +0 −1 test_app/db/migrate/20081023040052_create_users.rb
  38. +0 −12 test_app/db/migrate/20081101190907_create_accounts.rb
  39. +14 −0 test_app/db/migrate/20081103003828_create_companies.rb
  40. +18 −0 test_app/db/migrate/20081103003834_create_projects.rb
  41. 0 test_app/test/fixtures/{accounts.yml → companies.yml}
  42. +4 −0 test_app/test/fixtures/projects.yml
  43. +6 −4 test_app/test/fixtures/users.yml
  44. +8 −0 test_app/test/functional/companies_controller_test.rb
  45. +46 −0 test_app/test/integration/company_user_session_stories_test.rb
  46. +1 −1 test_app/test/integration/user_sesion_stories_test.rb
  47. +1 −1 test_app/test/integration/user_session_test.rb
  48. +35 −16 test_app/test/test_helper.rb
  49. +8 −0 test_app/test/unit/company_test.rb
  50. +8 −0 test_app/test/unit/project_test.rb
  51. +1 −1 test_app/test/unit/user_test.rb
View
@@ -2,6 +2,7 @@
* Changed configuration to use inheritable attributes
* Cleaned up requires to be in their proper files
+* Added in scope support.
== 0.10.3 released 2008-10-31
View
@@ -1,26 +1,32 @@
CHANGELOG.rdoc
init.rb
-lib/authgasm/acts_as_authentic.rb
-lib/authgasm/controller_adapters/abstract_adapter.rb
-lib/authgasm/controller_adapters/rails_adapter.rb
-lib/authgasm/session/active_record_trickery.rb
-lib/authgasm/session/base.rb
-lib/authgasm/session/callbacks.rb
-lib/authgasm/session/config.rb
-lib/authgasm/session/errors.rb
-lib/authgasm/sha512_crypto_provider.rb
-lib/authgasm/version.rb
-lib/authgasm.rb
+lib/authlogic/active_record/acts_as_authentic.rb
+lib/authlogic/active_record/authenticates_many.rb
+lib/authlogic/active_record/scoped_session.rb
+lib/authlogic/controller_adapters/abstract_adapter.rb
+lib/authlogic/controller_adapters/rails_adapter.rb
+lib/authlogic/session/active_record_trickery.rb
+lib/authlogic/session/base.rb
+lib/authlogic/session/callbacks.rb
+lib/authlogic/session/config.rb
+lib/authlogic/session/errors.rb
+lib/authlogic/sha512_crypto_provider.rb
+lib/authlogic/version.rb
+lib/authlogic.rb
Manifest
MIT-LICENSE
Rakefile
README.rdoc
test_app/app/controllers/application.rb
+test_app/app/controllers/companies_controller.rb
test_app/app/controllers/user_sessions_controller.rb
test_app/app/controllers/users_controller.rb
test_app/app/helpers/application_helper.rb
+test_app/app/helpers/companies_helper.rb
test_app/app/helpers/user_sessions_helper.rb
test_app/app/helpers/users_helper.rb
+test_app/app/models/company.rb
+test_app/app/models/project.rb
test_app/app/models/user.rb
test_app/app/models/user_session.rb
test_app/app/views/layouts/application.html.erb
@@ -41,6 +47,8 @@ test_app/config/initializers/new_rails_defaults.rb
test_app/config/routes.rb
test_app/db/development.sqlite3
test_app/db/migrate/20081023040052_create_users.rb
+test_app/db/migrate/20081103003828_create_companies.rb
+test_app/db/migrate/20081103003834_create_projects.rb
test_app/db/schema.rb
test_app/db/test.sqlite3
test_app/doc/README_FOR_APP
@@ -75,10 +83,18 @@ test_app/script/process/reaper
test_app/script/process/spawner
test_app/script/runner
test_app/script/server
+test_app/test/fixtures/companies.yml
+test_app/test/fixtures/projects.yml
test_app/test/fixtures/users.yml
+test_app/test/functional/companies_controller_test.rb
test_app/test/functional/user_sessions_controller_test.rb
test_app/test/functional/users_controller_test.rb
+test_app/test/integration/company_user_session_stories_test.rb
test_app/test/integration/user_sesion_stories_test.rb
+test_app/test/integration/user_session_config_test.rb
test_app/test/integration/user_session_test.rb
test_app/test/test_helper.rb
+test_app/test/unit/account_test.rb
+test_app/test/unit/company_test.rb
+test_app/test/unit/project_test.rb
test_app/test/unit/user_test.rb
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -1,15 +1,15 @@
require 'rubygems'
require 'echoe'
-require File.dirname(__FILE__) << "/lib/authgasm/version"
+require File.dirname(__FILE__) << "/lib/authlogic/version"
-Echoe.new 'authgasm' do |p|
- p.version = Authgasm::Version::STRING
+Echoe.new 'authlogic' do |p|
+ p.version = Authlogic::Version::STRING
p.author = "Ben Johnson of Binary Logic"
p.email = 'bjohnson@binarylogic.com'
- p.project = 'authgasm'
+ p.project = 'authlogic'
p.summary = "Rails authentication done right"
- p.url = "http://github.com/binarylogic/authgasm"
+ p.url = "http://github.com/binarylogic/authlogic"
p.dependencies = %w(activesupport activerecord)
p.include_rakefile = true
end
View
@@ -1 +1 @@
-require "authgasm"
+require "authlogic"
View
@@ -1,21 +0,0 @@
-require File.dirname(__FILE__) + "/authgasm/version"
-
-require File.dirname(__FILE__) + "/authgasm/controller_adapters/abstract_adapter"
-require File.dirname(__FILE__) + "/authgasm/controller_adapters/rails_adapter" if defined?(Rails)
-
-require File.dirname(__FILE__) + "/authgasm/sha512_crypto_provider"
-require File.dirname(__FILE__) + "/authgasm/acts_as_authentic"
-require File.dirname(__FILE__) + "/authgasm/session/active_record_trickery"
-require File.dirname(__FILE__) + "/authgasm/session/callbacks"
-require File.dirname(__FILE__) + "/authgasm/session/config"
-require File.dirname(__FILE__) + "/authgasm/session/errors"
-require File.dirname(__FILE__) + "/authgasm/session/base"
-
-module Authgasm
- module Session
- class Base
- include ActiveRecordTrickery
- include Callbacks
- end
- end
-end
View
@@ -0,0 +1,25 @@
+require File.dirname(__FILE__) + "/authlogic/version"
+
+require File.dirname(__FILE__) + "/authlogic/controller_adapters/abstract_adapter"
+require File.dirname(__FILE__) + "/authlogic/controller_adapters/rails_adapter" if defined?(Rails)
+
+require File.dirname(__FILE__) + "/authlogic/sha512_crypto_provider"
+
+require File.dirname(__FILE__) + "/authlogic/active_record/acts_as_authentic"
+require File.dirname(__FILE__) + "/authlogic/active_record/authenticates_many"
+require File.dirname(__FILE__) + "/authlogic/active_record/scoped_session"
+
+require File.dirname(__FILE__) + "/authlogic/session/active_record_trickery"
+require File.dirname(__FILE__) + "/authlogic/session/callbacks"
+require File.dirname(__FILE__) + "/authlogic/session/config"
+require File.dirname(__FILE__) + "/authlogic/session/errors"
+require File.dirname(__FILE__) + "/authlogic/session/base"
+
+module Authlogic
+ module Session
+ class Base
+ include ActiveRecordTrickery
+ include Callbacks
+ end
+ end
+end
@@ -1,13 +1,9 @@
-module Authgasm
- module ActsAsAuthentic # :nodoc:
- def self.included(base)
- base.extend(ClassMethods)
- end
-
+module Authlogic
+ module ActiveRecord # :nodoc:
# = Acts As Authentic
# Provides and "acts_as" method to include in your models to help with authentication. See method below.
- module ClassMethods
- # Call this method in your model to add in basic authentication madness that your authgasm session expects.
+ module ActsAsAuthentic
+ # Call this method in your model to add in basic authentication madness that your authlogic session expects.
#
# <b>Please keep in mind</b> that based on your configuration the method names could change. For example, if you pass the option:
#
@@ -37,17 +33,17 @@ module ClassMethods
#
# === Options
# * <tt>session_class:</tt> default: "#{name}Session", the related session class. Used so that you don't have to repeat yourself here. A lot of the configuration will be based off of the configuration values of this class.
- # * <tt>crypto_provider:</tt> default: Authgasm::Sha256CryptoProvider, class that provides Sha256 encryption. What ultimately encrypts your password.
- # * <tt>crypto_provider_type:</tt> default: options[:crypto_provider].respond_to?(:decrypt) ? :encryption : :hash. You can explicitly set this if you wish. Since encryptions and hashes are handled different this is the flag Authgasm uses.
+ # * <tt>crypto_provider:</tt> default: Authlogic::Sha512CryptoProvider, class that provides Sha512 encryption. What ultimately encrypts your password.
+ # * <tt>crypto_provider_type:</tt> default: options[:crypto_provider].respond_to?(:decrypt) ? :encryption : :hash. You can explicitly set this if you wish. Since encryptions and hashes are handled different this is the flag Authlogic uses.
# * <tt>login_field:</tt> default: options[:session_class].login_field, the name of the field used for logging in
- # * <tt>login_field_type:</tt> default: options[:login_field] == :email ? :email : :login, tells authgasm how to validation the field, what regex to use, etc.
+ # * <tt>login_field_type:</tt> default: options[:login_field] == :email ? :email : :login, tells authlogic how to validation the field, what regex to use, etc.
# * <tt>password_field:</tt> default: options[:session_class].password_field, the name of the field to set the password, *NOT* the field the encrypted password is stored
# * <tt>crypted_password_field:</tt> default: depends on which columns are present, checks: crypted_password, encrypted_password, password_hash, pw_hash, if none are present defaults to crypted_password. This is the name of column that your encrypted password is stored.
# * <tt>password_salt_field:</tt> default: depends on which columns are present, checks: password_salt, pw_salt, salt, if none are present defaults to password_salt. This is the name of the field your salt is stored, only relevant for a hash crypto provider.
# * <tt>remember_token_field:</tt> default: options[:session_class].remember_token_field, the name of the field your remember token is stored. What the cookie stores so the session can be "remembered"
# * <tt>scope:</tt> default: nil, if all of your users belong to an account you might want to scope everything to the account. Just pass :account_id
# * <tt>logged_in_timeout:</tt> default: 10.minutes, this allows you to specify a time the determines if a user is logged in or out. Useful if you want to count how many users are currently logged in.
- # * <tt>session_ids:</tt> default: [nil], the sessions that we want to automatically reset when a user is created or updated so you don't have to worry about this. Set to [] to disable. Should be an array of ids. See Authgasm::Session::Base#initialize for information on ids. The order is important. The first id should be your main session, the session they need to log into first. This is generally nil, meaning so explicitly set id.
+ # * <tt>session_ids:</tt> default: [nil], the sessions that we want to automatically reset when a user is created or updated so you don't have to worry about this. Set to [] to disable. Should be an array of ids. See Authlogic::Session::Base#initialize for information on ids. The order is important. The first id should be your main session, the session they need to log into first. This is generally nil, meaning so explicitly set id.
def acts_as_authentic(options = {})
# Setup default options
options[:session_class] ||= "#{name}Session".constantize
@@ -70,7 +66,7 @@ def acts_as_authentic(options = {})
options[:remember_token_field] ||= options[:session_class].remember_token_field
options[:logged_in_timeout] ||= 10.minutes
options[:session_ids] ||= [nil]
-
+
# Validations
case options[:login_field_type]
when :email
@@ -84,34 +80,34 @@ def acts_as_authentic(options = {})
validates_length_of options[:login_field], :within => 2..100
validates_format_of options[:login_field], :with => /\A\w[\w\.\-_@]+\z/, :message => "use only letters, numbers, and .-_@ please."
end
-
+
validates_uniqueness_of options[:login_field], :scope => options[:scope]
validates_uniqueness_of options[:remember_token_field]
validate :validate_password
validates_numericality_of :login_count, :only_integer => :true, :greater_than_or_equal_to => 0, :allow_nil => true if column_names.include?("login_count")
-
+
if column_names.include?("last_request_at")
named_scope :logged_in, lambda { {:conditions => ["last_request_at > ?", options[:logged_in_timeout].ago]} }
named_scope :logged_out, lambda { {:conditions => ["last_request_at <= ?", options[:logged_in_timeout].ago]} }
end
-
+
before_save :get_session_information, :if => :update_sessions?
after_save :maintain_sessions!, :if => :update_sessions?
-
+
# Attributes
attr_writer "confirm_#{options[:password_field]}"
attr_accessor "tried_to_set_#{options[:password_field]}"
-
+
# Class methods
class_eval <<-"end_eval", __FILE__, __LINE__
def self.unique_token
crypto_provider.encrypt(Time.now.to_s + (1..10).collect{ rand.to_s }.join)
end
-
+
def self.crypto_provider
#{options[:crypto_provider]}
end
-
+
def self.forget_all!
# Paginate these to save on memory
records = nil
@@ -123,7 +119,7 @@ def self.forget_all!
end while !records.blank?
end
end_eval
-
+
# Instance methods
if column_names.include?("last_request_at")
class_eval <<-"end_eval", __FILE__, __LINE__
@@ -132,7 +128,7 @@ def logged_in?
end
end_eval
end
-
+
case options[:crypto_provider_type]
when :hash
class_eval <<-"end_eval", __FILE__, __LINE__
@@ -144,7 +140,7 @@ def #{options[:password_field]}=(pass)
self.#{options[:password_salt_field]} = self.class.unique_token
self.#{options[:crypted_password_field]} = crypto_provider.encrypt(@#{options[:password_field]} + #{options[:password_salt_field]})
end
-
+
def valid_#{options[:password_field]}?(attempted_password)
return false if attempted_password.blank?
attempted_password == #{options[:crypted_password_field]} || #{options[:crypted_password_field]} == crypto_provider.encrypt(attempted_password + #{options[:password_salt_field]})
@@ -159,27 +155,27 @@ def #{options[:password_field]}=(pass)
self.#{options[:remember_token_field]} = self.class.unique_token
self.#{options[:crypted_password_field]} = crypto_provider.encrypt(@#{options[:password_field]})
end
-
+
def valid_#{options[:password_field]}?(attemtped_password)
return false if attempted_password.blank?
attempted_password == #{options[:crypted_password_field]} || #{options[:crypted_password_field]} = crypto_provider.decrypt(attempted_password)
end
end_eval
end
-
+
class_eval <<-"end_eval", __FILE__, __LINE__
def #{options[:password_field]}; end
def confirm_#{options[:password_field]}; end
-
+
def crypto_provider
self.class.crypto_provider
end
-
+
def forget!
self.#{options[:remember_token_field]} = self.class.unique_token
save_without_session_maintenance(false)
end
-
+
def reset_#{options[:password_field]}!
chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
newpass = ""
@@ -189,24 +185,24 @@ def reset_#{options[:password_field]}!
save_without_session_maintenance(false)
end
alias_method :randomize_password!, :reset_password!
-
+
def save_without_session_maintenance(*args)
@skip_session_maintenance = true
result = save(*args)
@skip_session_maintenance = false
result
end
-
+
protected
def update_sessions?
!@skip_session_maintenance && #{options[:session_class]}.activated? && !#{options[:session_ids].inspect}.blank? && #{options[:remember_token_field]}_changed?
end
-
+
def get_session_information
# Need to determine if we are completely logged out, or logged in as another user
@_sessions = []
@_logged_out = true
-
+
#{options[:session_ids].inspect}.each do |session_id|
session = #{options[:session_class]}.find(*[session_id].compact)
if session
@@ -217,40 +213,40 @@ def get_session_information
end
end
end
-
+
def maintain_sessions!
if @_logged_out
create_session!
elsif !@_sessions.blank?
update_sessions!
end
end
-
+
def create_session!
# We only want to automatically login into the first session, since this is the main session. The other sessions are sessions
# that need to be created after logging into the main session.
session_id = #{options[:session_ids].inspect}.first
-
+
# If we are already logged in, ignore this completely. All that we care about is updating ourself.
next if #{options[:session_class]}.find(*[session_id].compact)
-
+
# Log me in
args = [self, session_id].compact
#{options[:session_class]}.create(*args)
end
-
+
def update_sessions!
# We found sessions above, let's update them with the new info
@_sessions.each do |stale_session|
stale_session.unauthorized_record = self
stale_session.save
end
end
-
+
def tried_to_set_password?
tried_to_set_password == true
end
-
+
def validate_password
if new_record? || tried_to_set_#{options[:password_field]}?
if @#{options[:password_field]}.blank?
@@ -266,4 +262,4 @@ def validate_password
end
end
-ActiveRecord::Base.send(:include, Authgasm::ActsAsAuthentic)
+ActiveRecord::Base.extend Authlogic::ActiveRecord::ActsAsAuthentic
Oops, something went wrong.

0 comments on commit 43e849c

Please sign in to comment.