central_authentication 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.version = CentralAuthentication::VERSION
8
8
  s.authors = ["Hannes Benson"]
9
9
  s.email = ["hannes@mpowered.co.za"]
10
- s.homepage = ""
10
+ s.homepage = "https://github.com/HannesBenson/CentralAuthentication"
11
11
  s.summary = %q{Central Authentication using Authlogic}
12
12
  s.description = %q{This gem allows you to share a central database and using authlogic stores and retrieves passwords}
13
13
 
@@ -22,27 +22,33 @@ module ActiveRecord
22
22
  config.validate_login_field = false
23
23
  end
24
24
 
25
- validates_presence_of :password
26
- validates_presence_of :password_confirmation
25
+ validates_presence_of :password, :if => Proc.new {|user| user.new_record? && user.central_auth_user_id.nil?}
26
+ validates_presence_of :password_confirmation, :if => Proc.new {|user| user.new_record? && user.central_auth_user_id.nil?}
27
27
  validates_format_of :password, :with => /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s).{9,15}$/,
28
- :message => 'must contain at least one uppercase and one lowercase letter as well as at least one numerical character.'
28
+ :message => 'must be between 9 and 15 characters long, contain at least one uppercase and one lowercase letter as well as at least one numerical character.',
29
+ :if => Proc.new {|user| (user.password.present? || user.password_confirmation.present?)}
29
30
  validates_format_of :password_confirmation, :with => /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s).{9,15}$/,
30
- :message => 'must contain at least one uppercase and one lowercase letter as well as at least one numerical character.'
31
+ :message => 'must be between 9 and 15 characters long, contain at least one uppercase and one lowercase letter as well as at least one numerical character.',
32
+ :if => Proc.new {|user| (user.password.present? || user.password_confirmation.present?)}
31
33
  validates_confirmation_of :password
32
34
 
33
- before_save :create_or_set_cauth_user
35
+ before_validation :create_or_set_cauth_user
36
+
37
+ def self.find_by_persistence_token(persistence_token)
38
+ CentralAuthentication::User.find_by_persistence_token(persistence_token)
39
+ end
34
40
  end
35
41
  end
36
42
  module InstanceMethods
37
43
  def create_cauth_user
38
- CentralAuthentication::User.create(:email => self.email, :password => self.password, :password_confirmation => self.password_confirmation, :password_expires_on => Date.today + 30.days, :persistence_token => self.persistence_token)
44
+ CentralAuthentication::User.create(:email => self.email, :password => self.password, :password_expires_on => Date.today + 30.days, :persistence_token => self.persistence_token)
39
45
  end
40
46
 
41
47
  def update_cauth_user(cauth_user)
42
48
  if self.password.blank?
43
49
  cauth_user.update_attributes(:email => self.email)
44
50
  else
45
- cauth_user.update_attributes(:password => self.password, :password_confirmation => self.password_confirmation, :email => self.email)
51
+ cauth_user.update_attributes(:password => self.password, :email => self.email)
46
52
  end
47
53
  end
48
54
 
@@ -52,6 +58,7 @@ module ActiveRecord
52
58
  cauth_user = create_cauth_user
53
59
  self.central_auth_user_id = cauth_user.id
54
60
  else
61
+ self.central_authentication_user = cauth_user if self.central_auth_user_id.nil?
55
62
  update_cauth_user(cauth_user)
56
63
  end
57
64
  end
@@ -3,7 +3,7 @@ require 'rails'
3
3
 
4
4
  module CentralAuthentication
5
5
  class Railtie < Rails::Railtie
6
- config.after_initialize do
6
+ initializer "central_authentication.configure_rails_initialization" do
7
7
  require 'central_authentication/version'
8
8
  require 'central_authentication/connection'
9
9
  require 'central_authentication/migration'
@@ -1,9 +1,8 @@
1
1
  class CentralAuthentication::User < CentralAuthentication::Connection
2
2
  acts_as_authentic do |config|
3
- #config.merge_validates_length_of_password_field_options({:minimum => 9})
4
- #config.merge_validates_length_of_password_confirmation_field_options({:minimum => 9})
5
3
  config.login_field = :email
6
4
  config.validate_password_field = false
5
+ config.session_class = UserSession
7
6
  end
8
7
 
9
8
  def self.valid?(email, password)
@@ -1,3 +1,3 @@
1
1
  module CentralAuthentication
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -1,15 +1,31 @@
1
1
  class RemovePasswordRelatedFieldsFromUser < ActiveRecord::Migration
2
2
  def self.up
3
- remove_column :users, :password_salt
4
- remove_column :users, :crypted_password
5
- remove_column :users, :persistence_token
6
- remove_column :users, :perishable_token
3
+ if column_exists? :users, :password_salt
4
+ remove_column :users, :password_salt
5
+ end
6
+ if column_exists? :users, :crypted_password
7
+ remove_column :users, :crypted_password
8
+ end
9
+ if column_exists? :users, :persistence_token
10
+ remove_column :users, :persistence_token
11
+ end
12
+ if column_exists? :users, :perishable_token
13
+ remove_column :users, :perishable_token
14
+ end
7
15
  end
8
16
 
9
17
  def self.down
10
- add_column :users, :password_salt, :string
11
- add_column :users, :crypted_password, :string
12
- add_column :users, :persistence_token, :string
13
- add_column :users, :perishable_token, :string
18
+ unless column_exists? :users, :password_salt
19
+ add_column :users, :password_salt, :string
20
+ end
21
+ unless column_exists? :users, :crypted_password
22
+ add_column :users, :crypted_password, :string
23
+ end
24
+ unless column_exists? :users, :persistence_token
25
+ add_column :users, :persistence_token, :string
26
+ end
27
+ unless column_exists? :users, :perishable_token
28
+ add_column :users, :perishable_token, :string
29
+ end
14
30
  end
15
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: central_authentication
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-27 00:00:00.000000000 +02:00
13
- default_executable:
12
+ date: 2012-03-17 00:00:00.000000000 Z
14
13
  dependencies: []
15
14
  description: This gem allows you to share a central database and using authlogic stores
16
15
  and retrieves passwords
@@ -37,8 +36,7 @@ files:
37
36
  - lib/generators/templates/add_users_table_to_cauth_db.rb
38
37
  - lib/generators/templates/create_central_authentication_users.rb
39
38
  - lib/generators/templates/remove_password_related_fields_from_user.rb
40
- has_rdoc: true
41
- homepage: ''
39
+ homepage: https://github.com/HannesBenson/CentralAuthentication
42
40
  licenses: []
43
41
  post_install_message:
44
42
  rdoc_options: []
@@ -58,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
56
  version: '0'
59
57
  requirements: []
60
58
  rubyforge_project: central_authentication
61
- rubygems_version: 1.6.2
59
+ rubygems_version: 1.8.17
62
60
  signing_key:
63
61
  specification_version: 3
64
62
  summary: Central Authentication using Authlogic