mirror of
https://github.com/TracksApp/tracks.git
synced 2025-09-22 05:50:47 +02:00
No point in changing the name of the OpenID identity column in users table. Use the existing one.
This commit is contained in:
parent
c46e5a9e1d
commit
611a53e668
5 changed files with 19 additions and 23 deletions
|
@ -96,7 +96,7 @@ class LoginController < ApplicationController
|
|||
session['noexpiry'] ||= params['user_noexpiry']
|
||||
authenticate_with_open_id do |result, identity_url|
|
||||
if result.successful?
|
||||
if @user = User.find_by_identity_url(identity_url)
|
||||
if @user = User.find_by_open_id_url(identity_url)
|
||||
session['user_id'] = @user.id
|
||||
msg = (should_expire_sessions?) ? "will expire after 1 hour of inactivity." : "will not expire."
|
||||
notify :notice, "Login successful: session #{msg}"
|
||||
|
|
|
@ -154,7 +154,7 @@ class UsersController < ApplicationController
|
|||
# error. If info is nil, it means that the user cancelled
|
||||
# the verification.
|
||||
@user.auth_type = 'open_id'
|
||||
@user.identity_url = identity_url
|
||||
@user.open_id_url = identity_url
|
||||
if @user.save
|
||||
notify :notice, "You have successfully verified #{identity_url} as your identity and set your authentication type to Open ID."
|
||||
else
|
||||
|
|
|
@ -116,11 +116,11 @@ class User < ActiveRecord::Base
|
|||
validates_confirmation_of :password
|
||||
validates_length_of :login, :within => 3..80
|
||||
validates_uniqueness_of :login, :on => :create
|
||||
validates_presence_of :identity_url, :if => :using_openid?
|
||||
validates_presence_of :open_id_url, :if => :using_openid?
|
||||
|
||||
before_create :crypt_password, :generate_token
|
||||
before_update :crypt_password
|
||||
before_save :normalize_identity_url
|
||||
before_save :normalize_open_id_url
|
||||
|
||||
#for will_paginate plugin
|
||||
cattr_accessor :per_page
|
||||
|
@ -145,9 +145,9 @@ class User < ActiveRecord::Base
|
|||
return nil
|
||||
end
|
||||
|
||||
def self.find_by_identity_url(raw_identity_url)
|
||||
normalized_identity_url = OpenIdAuthentication.normalize_url(raw_identity_url)
|
||||
find(:first, :conditions => ['identity_url = ?', normalized_identity_url])
|
||||
def self.find_by_open_id_url(raw_identity_url)
|
||||
normalized_open_id_url = OpenIdAuthentication.normalize_url(raw_identity_url)
|
||||
find(:first, :conditions => ['open_id_url = ?', normalized_open_id_url])
|
||||
end
|
||||
|
||||
def self.no_users_yet?
|
||||
|
@ -235,8 +235,8 @@ protected
|
|||
crypted_password == sha1(pass)
|
||||
end
|
||||
|
||||
def normalize_identity_url
|
||||
return if identity_url.nil?
|
||||
self.identity_url = OpenIdAuthentication.normalize_url(identity_url)
|
||||
def normalize_open_id_url
|
||||
return if open_id_url.nil?
|
||||
self.open_id_url = OpenIdAuthentication.normalize_url(open_id_url)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,8 +12,6 @@ class UpgradeOpenId < ActiveRecord::Migration
|
|||
t.string :salt, :null => false
|
||||
end
|
||||
|
||||
add_column :users, :identity_url, :string
|
||||
|
||||
drop_table :open_id_associations
|
||||
drop_table :open_id_nonces
|
||||
drop_table :open_id_settings
|
||||
|
@ -41,7 +39,5 @@ class UpgradeOpenId < ActiveRecord::Migration
|
|||
t.string "setting"
|
||||
t.binary "value"
|
||||
end
|
||||
|
||||
remove_column :users, :identity_url
|
||||
end
|
||||
end
|
||||
|
|
|
@ -326,18 +326,18 @@ class UserTest < Test::Rails::TestCase
|
|||
assert_nil users(:other_user).remember_token
|
||||
end
|
||||
|
||||
def test_normalizes_identity_url_on_save
|
||||
def test_normalizes_open_id_url_on_save
|
||||
['www.johndoe.com', 'WWW.JOHNDOE.COM', 'http://www.johndoe.com/', 'http://www.johndoe.com'].each do |initial|
|
||||
assert_identity_url_normalized_on_save initial, 'http://www.johndoe.com/'
|
||||
assert_open_id_url_normalized_on_save initial, 'http://www.johndoe.com/'
|
||||
end
|
||||
end
|
||||
|
||||
def test_normalizes_identity_url_on_find
|
||||
def test_normalizes_open_id_url_on_find
|
||||
u = users(:other_user)
|
||||
u.identity_url = 'http://www.johndoe.com'
|
||||
u.open_id_url = 'http://www.johndoe.com'
|
||||
u.save
|
||||
['www.johndoe.com', 'WWW.JOHNDOE.COM', 'http://www.johndoe.com/', 'http://www.johndoe.com'].each do |raw_identity_url|
|
||||
assert_equal u.id, User.find_by_identity_url(raw_identity_url).id
|
||||
['www.johndoe.com', 'WWW.JOHNDOE.COM', 'http://www.johndoe.com/', 'http://www.johndoe.com'].each do |raw_open_id_url|
|
||||
assert_equal u.id, User.find_by_open_id_url(raw_open_id_url).id
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -348,11 +348,11 @@ class UserTest < Test::Rails::TestCase
|
|||
User.create({ :login => 'quire', :password => 'quire', :password_confirmation => 'quire' }.merge(options))
|
||||
end
|
||||
|
||||
def assert_identity_url_normalized_on_save(initial, expected)
|
||||
def assert_open_id_url_normalized_on_save(initial, expected)
|
||||
u = users(:other_user)
|
||||
u.identity_url = initial
|
||||
u.open_id_url = initial
|
||||
u.save
|
||||
assert_equal expected, u.identity_url
|
||||
assert_equal expected, u.open_id_url
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue