Normalize the identity_url when it's set.

OpenId uses a specific format for the url it uses which requires the protocol
and trailing slash.  This change will normalize the value to when a user sets it.

  #699

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2453 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Eric Davis 2009-02-12 04:31:28 +00:00
parent 14e445c600
commit 60dc357271
2 changed files with 28 additions and 0 deletions

View File

@ -80,6 +80,15 @@ class User < ActiveRecord::Base
super
end
def identity_url=(url)
begin
self.write_attribute(:identity_url, OpenIdAuthentication.normalize_identifier(url))
rescue InvalidOpenId
# Invlaid url, don't save
end
self.read_attribute(:identity_url)
end
# Returns the user that matches provided login and password, or nil
def self.try_to_login(login, password)
# Make sure no one can sign in with an empty password

View File

@ -184,4 +184,23 @@ class UserTest < Test::Unit::TestCase
assert !u.password.blank?
assert !u.password_confirmation.blank?
end
def test_setting_identity_url
normalized_open_id_url = 'http://example.com/'
u = User.new( :identity_url => 'http://example.com/' )
assert_equal normalized_open_id_url, u.identity_url
end
def test_setting_identity_url_without_trailing_slash
normalized_open_id_url = 'http://example.com/'
u = User.new( :identity_url => 'http://example.com' )
assert_equal normalized_open_id_url, u.identity_url
end
def test_setting_identity_url_without_protocol
normalized_open_id_url = 'http://example.com/'
u = User.new( :identity_url => 'example.com' )
assert_equal normalized_open_id_url, u.identity_url
end
end