Permalink
Browse files

Update with authlogic 2.0

  • Loading branch information...
1 parent e1cd014 commit a319babd522ea981415cffa2ce481899d5f56cc8 @binarylogic binarylogic committed Mar 30, 2009
Showing 1,117 changed files with 51,675 additions and 105,833 deletions.
@@ -1,5 +1,5 @@
class UsersController < ApplicationController
- before_filter :require_no_user, :only => [:new, :create]
+ #before_filter :require_no_user, :only => [:new, :create]
before_filter :require_user, :only => [:show, :edit, :update]
def new
@@ -8,29 +8,34 @@ def new
def create
@user = User.new(params[:user])
- if @user.save
- flash[:notice] = "Account registered!"
- redirect_back_or_default account_url
- else
- render :action => :new
+ @user.save do |result|
+ if result
+ flash[:notice] = "Account registered!"
+ redirect_back_or_default account_url
+ else
+ render :action => :new
+ end
end
end
def show
- @user = @current_user
+ @user = current_user
end
def edit
- @user = @current_user
+ @user = current_user
end
def update
- @user = @current_user # makes our views "cleaner" and more consistent
- if @user.update_attributes(params[:user])
- flash[:notice] = "Account updated!"
- redirect_to account_url
- else
- render :action => :edit
+ @user = current_user # makes our views "cleaner" and more consistent
+ @user.attributes = params[:user]
+ @user.save do |result|
+ if result
+ flash[:notice] = "Account updated!"
+ redirect_to account_url
+ else
+ render :action => :edit
+ end
end
end
end
View
@@ -1,20 +1,3 @@
class User < ActiveRecord::Base
- acts_as_authentic :login_field_validation_options => {:if => :openid_identifier_blank?}, :password_field_validation_options => {:if => :openid_identifier_blank?}
-
- validate :normalize_openid_identifier
- validates_uniqueness_of :openid_identifier, :allow_blank => true
-
- # For acts_as_authentic configuration
- def openid_identifier_blank?
- openid_identifier.blank?
- end
-
- private
- def normalize_openid_identifier
- begin
- self.openid_identifier = OpenIdAuthentication.normalize_url(openid_identifier) if !openid_identifier.blank?
- rescue OpenIdAuthentication::InvalidOpenId => e
- errors.add(:openid_identifier, e.message)
- end
- end
-end
+ acts_as_authentic
+end
View
@@ -1,34 +1,3 @@
class UserSession < Authlogic::Session::Base
- attr_accessor :openid_identifier
-
- def authenticating_with_openid?
- !openid_identifier.blank? || controller.params[:open_id_complete]
- end
-
- def save(&block)
- if authenticating_with_openid?
- raise ArgumentError.new("You must supply a block to authenticate with OpenID") unless block_given?
-
- controller.send(:authenticate_with_open_id, openid_identifier) do |result, openid_identifier|
- if !result.successful?
- errors.add_to_base(result.message)
- yield false
- return
- end
-
- record = klass.find_by_openid_identifier(openid_identifier)
-
- if !record
- errors.add(:openid_identifier, "did not match any users in our database, have you set up your account to use OpenID?")
- yield false
- return
- end
-
- self.unauthorized_record = record
- super
- end
- else
- super
- end
- end
+ logout_on_timeout true
end
@@ -9,4 +9,6 @@
<br />
<%= form.label :openid_identifier, "Or use OpenID instead of a standard login / password" %><br />
<%= form.text_field :openid_identifier %><br />
-<br />
+<br />
+<%= form.label :email %><br />
+<%= form.text_field :email %><br />
View
@@ -44,6 +44,7 @@ class VendorBoot < Boot
def load_initializer
require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
Rails::Initializer.run(:install_gem_spec_stubs)
+ Rails::GemDependency.add_frozen_gem_path
end
end
@@ -67,7 +68,7 @@ def load_rails_gem
class << self
def rubygems_version
- Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion
+ Gem::RubyGemsVersion rescue nil
end
def gem_version
@@ -82,7 +83,7 @@ def gem_version
def load_rubygems
require 'rubygems'
- min_version = '1.1.1'
+ min_version = '1.3.1'
unless rubygems_version >= min_version
$stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
exit 1
View
@@ -26,13 +26,14 @@
# config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
# config.gem "aws-s3", :lib => "aws/s3"
config.gem "authlogic"
+ config.gem "authlogic-oid", :lib => "authlogic_openid"
# Only load the plugins named here, in the order given. By default, all plugins
# in vendor/plugins are loaded in alphabetical order.
# :all can be used as a placeholder for all plugins not explicitly named
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
- config.plugin_paths += ["#{RAILS_ROOT}/../../Libs"]
- config.plugins = [:authlogic, :open_id_authentication]
+ #config.plugin_paths += ["#{RAILS_ROOT}/../../Libs"]
+ #config.plugins = [:authlogic, :authlogic_openid, :open_id_authentication]
# Add additional load paths for your own custom dirs
# config.load_paths += %W( #{RAILS_ROOT}/extras )
@@ -2,9 +2,11 @@ class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.timestamps
- t.string :login, :null => false
- t.string :crypted_password, :null => false
- t.string :password_salt, :null => false
+ t.string :login
+ t.string :crypted_password
+ t.string :password_salt
+ t.string :email, :null => false
+ t.string :openid_identifier
t.string :persistence_token, :null => false
t.integer :login_count, :default => 0, :null => false
t.datetime :last_request_at
@@ -15,6 +17,8 @@ def self.up
end
add_index :users, :login
+ add_index :users, :email
+ add_index :users, :openid_identifier
add_index :users, :persistence_token
add_index :users, :last_request_at
end
@@ -1,19 +0,0 @@
-class AddUsersOpenidField < ActiveRecord::Migration
- def self.up
- add_column :users, :openid_identifier, :string
- add_index :users, :openid_identifier
-
- change_column :users, :login, :string, :default => nil, :null => true
- change_column :users, :crypted_password, :string, :default => nil, :null => true
- change_column :users, :password_salt, :string, :default => nil, :null => true
- end
-
- def self.down
- remove_column :users, :openid_identifier
-
- [:login, :crypted_password, :password_salt].each do |field|
- User.all(:conditions => "#{field} is NULL").each { |user| user.update_attribute(field, "") if user.send(field).nil? }
- change_column :users, field, :string, :default => "", :null => false
- end
- end
-end
Oops, something went wrong.

0 comments on commit a319bab

Please sign in to comment.