Skip to content

Commit

Permalink
Released v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
binarylogic committed Nov 13, 2008
1 parent b83abca commit 4bdf3fd
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 57 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.rdoc
@@ -1,7 +1,7 @@
== 1.1.0 released 2008-11-05

* Moved Rack standards into abstract_adapter for the controllers.
* Added logging_in_with_credentials?, logging_in_with_unauthorized_record?
* Added authenticating_with_credentials?, authenticating_with_unauthorized_record?
* Fixed typo in abstract_adapter, black to block.
* Cleaned up / reorganized tests.
* Moved ActiveRecord additions to ORM Adapters name space to make way for Data Mapper.
Expand All @@ -13,8 +13,9 @@
* Added last_request_at_threshold configuration option.
* Changed Scoped class to AuthenticatesManyAssociation, like AR has HasManyAssociation, etc.
* Added should_be_authentic shoulda macro.
* Removed some magic from how sessions are initialized. See the initialize documentation, this method is a little more structured now, which was require for adding in openid.
* Removed some magic from how sessions are initialized. See the initialize documentation, this method is a little more structured now, which was required for adding in openid.
* Added in logging via a params token, which is friendly for feed URLs. Works just like cookies and sessions when persisting the session.
* Added the option to use session.user, instead of session.record. This is based off of what model your session is authenticating with.

== 1.0.0 released 2008-11-05

Expand Down
44 changes: 29 additions & 15 deletions Manifest
@@ -1,37 +1,51 @@
CHANGELOG.rdoc
init.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/merb_adapter.rb
lib/authlogic/controller_adapters/rails_adapter.rb
lib/authlogic/crypto_providers/sha1.rb
lib/authlogic/crypto_providers/sha512.rb
lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/credentials.rb
lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/logged_in.rb
lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/persistence.rb
lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/session_maintenance.rb
lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic.rb
lib/authlogic/orm_adapters/active_record_adapter/authenticates_many.rb
lib/authlogic/session/active_record_trickery.rb
lib/authlogic/session/authenticates_many_association.rb
lib/authlogic/session/base.rb
lib/authlogic/session/callbacks.rb
lib/authlogic/session/config.rb
lib/authlogic/session/cookies.rb
lib/authlogic/session/errors.rb
lib/authlogic/session/openid.rb
lib/authlogic/session/params.rb
lib/authlogic/session/scopes.rb
lib/authlogic/sha512_crypto_provider.rb
lib/authlogic/session/session.rb
lib/authlogic/testing/shoulda_macros.rb
lib/authlogic/version.rb
lib/authlogic.rb
Manifest
MIT-LICENSE
Rakefile
README.rdoc
test/active_record_acts_as_authentic_test.rb
test/active_record_authenticates_many_test.rb
test/fixtures/companies.yml
test/fixtures/employees.yml
test/fixtures/projects.yml
test/fixtures/users.yml
test/libs/aes128_crypto_provider.rb
test/libs/mock_controller.rb
test/libs/mock_cookie_jar.rb
test/libs/mock_request.rb
test/libs/ordered_hash.rb
test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_test.rb
test/orm_adapters_tests/active_record_adapter_tests/authenticates_many_test.rb
test/session_tests/active_record_trickery_test.rb
test/session_tests/authenticates_many_association_test.rb
test/session_tests/base_test.rb
test/session_tests/config_test.rb
test/session_tests/cookies_test.rb
test/session_tests/params_test.rb
test/session_tests/scopes_test.rb
test/session_tests/session_test.rb
test/test_helper.rb
test/user_session_active_record_trickery_test.rb
test/user_session_base_test.rb
test/user_session_config_test.rb
test/user_session_scopes_test.rb
test_libs/aes128_crypto_provider.rb
test_libs/mock_controller.rb
test_libs/mock_cookie_jar.rb
test_libs/mock_request.rb
test_libs/ordered_hash.rb
2 changes: 1 addition & 1 deletion README.rdoc
Expand Up @@ -56,7 +56,7 @@ Or how about persisting the session...
protected
def load_user
@user_session = UserSession.find
@current_user = @user_session && @user_session.record
@current_user = @user_session && @user_session.user
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/authlogic.rb
Expand Up @@ -24,7 +24,7 @@
require File.dirname(__FILE__) + "/authlogic/session/config"
require File.dirname(__FILE__) + "/authlogic/session/cookies"
require File.dirname(__FILE__) + "/authlogic/session/errors"
require File.dirname(__FILE__) + "/authlogic/session/openid"
#require File.dirname(__FILE__) + "/authlogic/session/openid"
require File.dirname(__FILE__) + "/authlogic/session/params"
require File.dirname(__FILE__) + "/authlogic/session/session"
require File.dirname(__FILE__) + "/authlogic/session/scopes"
Expand Down
62 changes: 32 additions & 30 deletions lib/authlogic/session/base.rb
Expand Up @@ -47,7 +47,7 @@ def create!(*args)
#
# def load_user
# @user_session = UserSession.find
# @current_user = @user_session && @user_session.record
# @current_user = @user_session && @user_session.user
# end
#
# Accepts a single parameter as the id. See initialize for more information on ids. Lastly, how it finds the session can be modified via configuration.
Expand Down Expand Up @@ -82,7 +82,7 @@ def controllers

attr_accessor :new_session
attr_reader :record, :unauthorized_record
attr_writer :id, :login_with
attr_writer :authenticating_with, :id

# You can initialize a session by doing any of the following:
#
Expand Down Expand Up @@ -117,6 +117,28 @@ def initialize(*args)
end
end

# A flag for how the user is logging in. Possible values:
#
# * :password - username and password
# * :unauthorized_record - an actual ActiveRecord object
# * :openid - OpenID
#
# By default this is :password
def authenticating_with
@authenticating_with ||= :password
end

# Returns true if logging in with credentials. Credentials mean username and password.
def authenticating_with_password?
authenticating_with == :password
end

# Returns true if logging in with an unauthorized record
def authenticating_with_unauthorized_record?
authenticating_with == :unauthorized_record
end
alias_method :authenticating_with_record?, :authenticating_with_unauthorized_record?

# Your login credentials in hash format. Usually {:login => "my login", :password => "<protected>"} depending on your configuration.
# Password is protected as a security measure. The raw password should never be publicly accessible.
def credentials
Expand Down Expand Up @@ -197,7 +219,7 @@ def id

def inspect # :nodoc:
details = {}
case login_with
case authenticating_with
when :unauthorized_record
details[:unauthorized_record] = "<protected>"
else
Expand All @@ -207,28 +229,6 @@ def inspect # :nodoc:
"#<#{self.class.name} #{details.inspect}>"
end

# A flag for how the user is logging in. Possible values:
#
# * :credentials - username and password
# * :unauthorized_record - an actual ActiveRecord object
# * :openid - OpenID
#
# By default this is :credentials
def login_with
@login_with ||= :credentials
end

# Returns true if logging in with credentials. Credentials mean username and password.
def logging_in_with_credentials?
login_with == :credentials
end

# Returns true if logging in with an unauthorized record
def logging_in_with_unauthorized_record?
login_with == :unauthorized_record
end
alias_method :logging_in_with_record?, :logging_in_with_unauthorized_record?

# Similar to ActiveRecord's new_record? Returns true if the session has not been saved yet.
def new_session?
new_session != false
Expand Down Expand Up @@ -293,7 +293,7 @@ def save!
# Sometimes you don't want to create a session via credentials (login and password). Maybe you already have the record. Just set this record to this and it will be authenticated when you try to validate
# the session. Basically this is another form of credentials, you are just skipping username and password validation.
def unauthorized_record=(value)
self.login_with = :unauthorized_record
self.authenticating_with = :unauthorized_record
@unauthorized_record = value
end

Expand Down Expand Up @@ -337,15 +337,17 @@ def create_configurable_methods!
return if respond_to?(login_field) # already created these methods

self.class.class_eval <<-"end_eval", __FILE__, __LINE__
alias_method :#{klass_name.underscore}, :record
attr_reader :#{login_field}
def #{login_field}=(value)
self.login_with = :credentials
self.authenticating_with = :password
@#{login_field} = value
end
def #{password_field}=(value)
self.login_with = :credentials
self.authenticating_with = :password
@#{password_field} = value
end
Expand Down Expand Up @@ -378,8 +380,8 @@ def search_for_record(method, value)
def valid_credentials?
unchecked_record = nil

case login_with
when :credentials
case authenticating_with
when :password
errors.add(login_field, "can not be blank") if send(login_field).blank?
errors.add(password_field, "can not be blank") if send("protected_#{password_field}").blank?
return false if errors.count > 0
Expand Down
16 changes: 10 additions & 6 deletions lib/authlogic/session/openid.rb
Expand Up @@ -13,7 +13,7 @@ def self.included(klass)

def initialize_with_openid(*args)
initialize_without_openid(*args)
self.login_with = :openid if openid_verification_complete?
self.authenticating_with = :openid if openid_verification_complete?
end

def credentials_with_openid=(values)
Expand All @@ -24,11 +24,15 @@ def credentials_with_openid=(values)
end

# Returns true if logging in with openid. Credentials mean username and password.
def logging_in_with_openid?
login_with == :openid
def authenticating_with_openid?
authenticating_with == :openid
end

def openid_verification_complete?
def verify_openid?
authenticating_with_openid? && controller.params[:openid_complete] != "1"
end

def openid_verified?
controller.params[:openid_complete] == "1"
end

Expand All @@ -47,7 +51,7 @@ def valid_openid?
errors.add_to_Base("OpenID authentication needs setup.")
end
else
if logging_in_with_openid?
if authenticating_with_openid?
if send(openid_field).blank?
errors.add(openid_field, "can not be blank")
return false
Expand Down Expand Up @@ -87,7 +91,7 @@ def create_configurable_methods_with_openid!
attr_reader :#{openid_field}
def #{openid_field}=(value)
self.login_with = :openid
self.authenticating_with = :openid
@#{openid_field} = value
end
end_eval
Expand Down
2 changes: 1 addition & 1 deletion lib/authlogic/version.rb
Expand Up @@ -43,7 +43,7 @@ def to_a
end

MAJOR = 1
MINOR = 0
MINOR = 1
TINY = 0

# The current version as a Version instance
Expand Down
10 changes: 9 additions & 1 deletion test/session_tests/base_test.rb
Expand Up @@ -58,6 +58,14 @@ def test_klass_name
assert_equal "User", UserSession.klass_name
end

def test_record_method
ben = users(:ben)
set_session_for(ben)
session = UserSession.find
assert_equal ben, session.record
assert_equal ben, session.user
end

def test_init
UserSession.reset_controllers!
assert_raise(Authlogic::Session::NotActivated) { UserSession.new }
Expand Down Expand Up @@ -223,7 +231,7 @@ def test_unauthorized_record
ben = users(:ben)
session.unauthorized_record = ben
assert_equal ben, session.unauthorized_record
assert_equal :unauthorized_record, session.login_with
assert_equal :unauthorized_record, session.authenticating_with
end

def test_valid
Expand Down

0 comments on commit 4bdf3fd

Please sign in to comment.