central_authentication 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,10 @@
1
- require "authlogic"
2
-
3
- require "central_authentication/version"
4
- require "central_authentication/connection"
5
- require "central_authentication/migration"
6
- require "central_authentication/user"
7
- require "central_authentication/acts_as_central_authentication_user"
1
+ require 'authlogic'
2
+ if defined?(Rails::Railtie)
3
+ require 'central_authentication/railtie'
4
+ else
5
+ require 'central_authentication/version'
6
+ require 'central_authentication/connection'
7
+ require 'central_authentication/migration'
8
+ require 'central_authentication/user'
9
+ require 'central_authentication/acts_as_central_authentication_user'
10
+ end
@@ -35,7 +35,7 @@ module ActiveRecord
35
35
  end
36
36
  module InstanceMethods
37
37
  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)
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)
39
39
  end
40
40
 
41
41
  def update_cauth_user(cauth_user)
@@ -58,7 +58,7 @@ module ActiveRecord
58
58
 
59
59
  def persistence_token
60
60
  # This method returns the persistence_token from the central authentication user. If this user does not exist yet it returns a arbitrary string otherwise it fails validation.
61
- return 'a' if central_authentication_user.nil?
61
+ return Authlogic::Random.hex_token if central_authentication_user.nil?
62
62
  central_authentication_user.persistence_token
63
63
  end
64
64
 
@@ -1,8 +1,4 @@
1
1
  class CentralAuthentication::Connection < ActiveRecord::Base
2
2
  establish_connection "cauth_#{Rails.env}"
3
3
  self.abstract_class = true
4
-
5
- def self.table_name_prefix
6
- "cauth_#{Rails.env}."
7
- end
8
4
  end
@@ -0,0 +1,17 @@
1
+ require 'central_authentication'
2
+ require 'rails'
3
+
4
+ module CentralAuthentication
5
+ class Railtie < Rails::Railtie
6
+ config.after_initialize do
7
+ require 'central_authentication/version'
8
+ require 'central_authentication/connection'
9
+ require 'central_authentication/migration'
10
+ require 'central_authentication/user'
11
+ require 'central_authentication/acts_as_central_authentication_user'
12
+ end
13
+ rake_tasks do
14
+ load 'central_authentication/tasks.rb'
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ namespace :central_auth do
2
+ desc "Generate the migrations for central authentication."
3
+ task :generate => :environment do
4
+ end
5
+ end
@@ -1,8 +1,9 @@
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})
3
+ #config.merge_validates_length_of_password_field_options({:minimum => 9})
4
+ #config.merge_validates_length_of_password_confirmation_field_options({:minimum => 9})
5
5
  config.login_field = :email
6
+ config.validate_password_field = false
6
7
  end
7
8
 
8
9
  def self.valid?(email, password)
@@ -1,3 +1,3 @@
1
1
  module CentralAuthentication
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,27 @@
1
+ # lib/generators/authr/authr_generator.rb
2
+ require 'rails/generators'
3
+ require 'rails/generators/migration'
4
+
5
+ class CentralAuthenticationGenerator < Rails::Generators::Base
6
+ include Rails::Generators::Migration
7
+ def self.source_root
8
+ @source_root ||= File.join(File.dirname(__FILE__), 'templates')
9
+ end
10
+
11
+ # Implement the required interface for Rails::Generators::Migration.
12
+ # taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
13
+ def self.next_migration_number(dirname)
14
+ if ActiveRecord::Base.timestamped_migrations
15
+ Time.now.utc.strftime("%Y%m%d%H%M%S%6N")
16
+ else
17
+ "%.3d" % (current_migration_number(dirname) + 1)
18
+ end
19
+ end
20
+
21
+ def create_migration_files
22
+ migration_template 'add_auth_id_to_users.rb', 'db/migrate/add_auth_id_to_users.rb'
23
+ migration_template 'add_users_table_to_cauth_db.rb', 'db/migrate/add_users_table_to_cauth_db.rb'
24
+ migration_template 'create_central_authentication_users.rb', 'db/migrate/create_central_authentication_users.rb'
25
+ migration_template 'remove_password_related_fields_from_user.rb', 'db/migrate/remove_password_related_fields_from_user.rb'
26
+ end
27
+ 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.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -24,17 +24,19 @@ files:
24
24
  - Gemfile
25
25
  - Rakefile
26
26
  - central_authentication.gemspec
27
- - generators/central_authentication_generator.rb
28
- - generators/templates/add_auth_id_to_users.rb
29
- - generators/templates/add_users_table_to_cauth_db.rb
30
- - generators/templates/create_central_authentication_users.rb
31
- - generators/templates/remove_password_related_fields_from_user.rb
32
27
  - lib/central_authentication.rb
33
28
  - lib/central_authentication/acts_as_central_authentication_user.rb
34
29
  - lib/central_authentication/connection.rb
35
30
  - lib/central_authentication/migration.rb
31
+ - lib/central_authentication/railtie.rb
32
+ - lib/central_authentication/tasks.rb
36
33
  - lib/central_authentication/user.rb
37
34
  - lib/central_authentication/version.rb
35
+ - lib/generators/central_authentication_generator.rb
36
+ - lib/generators/templates/add_auth_id_to_users.rb
37
+ - lib/generators/templates/add_users_table_to_cauth_db.rb
38
+ - lib/generators/templates/create_central_authentication_users.rb
39
+ - lib/generators/templates/remove_password_related_fields_from_user.rb
38
40
  has_rdoc: true
39
41
  homepage: ''
40
42
  licenses: []
@@ -1,13 +0,0 @@
1
- class CentralAuthenticationGenerator < Rails::Generator::Base
2
- def manifest
3
- record do |m|
4
- m.migration_template 'add_auth_id_to_users.rb', 'db/migrate', :migration_file_name => 'add_auth_id_to_users.rb'
5
- m.sleep(2)
6
- m.migration_template 'add_users_table_to_cauth_db.rb', 'db/migrate', :migration_file_name => 'add_users_table_to_cauth_db.rb'
7
- m.sleep(2)
8
- m.migration_template 'create_central_authentication_users.rb', 'db/migrate', :migration_file_name => 'create_central_authentication_users.rb'
9
- m.sleep(2)
10
- m.migration_template 'remove_password_related_fields_from_user.rb', 'db/migrate', :migration_file_name => 'remove_password_related_fields_from_user.rb'
11
- end
12
- end
13
- end