simple_auth 0.1.8 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. data/.gitignore +5 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +13 -0
  4. data/Gemfile.lock +109 -0
  5. data/README.markdown +13 -29
  6. data/Rakefile +21 -33
  7. data/lib/simple_auth/action_controller.rb +42 -38
  8. data/lib/simple_auth/active_record.rb +59 -47
  9. data/lib/simple_auth/config.rb +8 -3
  10. data/lib/simple_auth/generator.rb +11 -0
  11. data/lib/simple_auth/railtie.rb +24 -0
  12. data/lib/simple_auth/session.rb +12 -0
  13. data/lib/simple_auth/version.rb +3 -3
  14. data/lib/simple_auth.rb +1 -7
  15. data/simple_auth.gemspec +35 -21
  16. data/spec/controllers/redirect_logged_user_spec.rb +87 -0
  17. data/spec/controllers/require_logged_user_spec.rb +105 -0
  18. data/spec/schema.rb +4 -0
  19. data/spec/simple_auth/active_record_spec.rb +32 -15
  20. data/spec/simple_auth/config_spec.rb +7 -1
  21. data/spec/simple_auth/helper_spec.rb +12 -16
  22. data/spec/simple_auth/session_spec.rb +9 -7
  23. data/spec/spec_helper.rb +9 -34
  24. data/spec/support/app/controllers/application_controller.rb +2 -0
  25. data/spec/support/app/models/account.rb +2 -0
  26. data/spec/{resources → support/app/models}/user.rb +1 -1
  27. data/spec/{resources → support/app}/views/dashboard/index.erb +0 -0
  28. data/spec/{resources → support/app}/views/session/new.erb +0 -0
  29. data/spec/support/config/boot.rb +14 -0
  30. data/spec/support/config/database.yml +3 -0
  31. data/spec/support/config/routes.rb +4 -0
  32. data/{generators/simple_auth/templates/simple_auth.rb → templates/initializer.rb} +5 -4
  33. metadata +47 -21
  34. data/generators/simple_auth/USAGE +0 -5
  35. data/generators/simple_auth/simple_auth_generator.rb +0 -7
  36. data/init.rb +0 -1
  37. data/spec/resources/controllers.rb +0 -35
  38. data/spec/simple_auth/action_controller_spec.rb +0 -117
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ pkg
2
+ .rubyrc
3
+ .rvmrc
4
+ log
5
+ .bundle
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color --format documentation
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source :rubygems
2
+
3
+ gem "rspec-rails", "2.0.0.rc"
4
+ gem "rails", "3.0.0"
5
+ gem "sqlite3-ruby", :require => "sqlite3"
6
+
7
+ platforms :mri_18 do
8
+ gem "ruby-debug"
9
+ end
10
+
11
+ platforms :mri_19 do
12
+ gem "ruby-debug19", :require => "ruby-debug"
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,109 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ abstract (1.0.0)
5
+ actionmailer (3.0.0)
6
+ actionpack (= 3.0.0)
7
+ mail (~> 2.2.5)
8
+ actionpack (3.0.0)
9
+ activemodel (= 3.0.0)
10
+ activesupport (= 3.0.0)
11
+ builder (~> 2.1.2)
12
+ erubis (~> 2.6.6)
13
+ i18n (~> 0.4.1)
14
+ rack (~> 1.2.1)
15
+ rack-mount (~> 0.6.12)
16
+ rack-test (~> 0.5.4)
17
+ tzinfo (~> 0.3.23)
18
+ activemodel (3.0.0)
19
+ activesupport (= 3.0.0)
20
+ builder (~> 2.1.2)
21
+ i18n (~> 0.4.1)
22
+ activerecord (3.0.0)
23
+ activemodel (= 3.0.0)
24
+ activesupport (= 3.0.0)
25
+ arel (~> 1.0.0)
26
+ tzinfo (~> 0.3.23)
27
+ activeresource (3.0.0)
28
+ activemodel (= 3.0.0)
29
+ activesupport (= 3.0.0)
30
+ activesupport (3.0.0)
31
+ archive-tar-minitar (0.5.2)
32
+ arel (1.0.1)
33
+ activesupport (~> 3.0.0)
34
+ builder (2.1.2)
35
+ columnize (0.3.1)
36
+ diff-lcs (1.1.2)
37
+ erubis (2.6.6)
38
+ abstract (>= 1.0.0)
39
+ i18n (0.4.1)
40
+ linecache (0.43)
41
+ linecache19 (0.5.11)
42
+ ruby_core_source (>= 0.1.4)
43
+ mail (2.2.5)
44
+ activesupport (>= 2.3.6)
45
+ mime-types
46
+ treetop (>= 1.4.5)
47
+ mime-types (1.16)
48
+ polyglot (0.3.1)
49
+ rack (1.2.1)
50
+ rack-mount (0.6.13)
51
+ rack (>= 1.0.0)
52
+ rack-test (0.5.4)
53
+ rack (>= 1.0)
54
+ rails (3.0.0)
55
+ actionmailer (= 3.0.0)
56
+ actionpack (= 3.0.0)
57
+ activerecord (= 3.0.0)
58
+ activeresource (= 3.0.0)
59
+ activesupport (= 3.0.0)
60
+ bundler (~> 1.0.0)
61
+ railties (= 3.0.0)
62
+ railties (3.0.0)
63
+ actionpack (= 3.0.0)
64
+ activesupport (= 3.0.0)
65
+ rake (>= 0.8.4)
66
+ thor (~> 0.14.0)
67
+ rake (0.8.7)
68
+ rspec (2.0.0.rc)
69
+ rspec-core (= 2.0.0.rc)
70
+ rspec-expectations (= 2.0.0.rc)
71
+ rspec-mocks (= 2.0.0.rc)
72
+ rspec-core (2.0.0.rc)
73
+ rspec-expectations (2.0.0.rc)
74
+ diff-lcs (>= 1.1.2)
75
+ rspec-mocks (2.0.0.rc)
76
+ rspec-core (= 2.0.0.rc)
77
+ rspec-expectations (= 2.0.0.rc)
78
+ rspec-rails (2.0.0.rc)
79
+ rspec (= 2.0.0.rc)
80
+ ruby-debug (0.10.3)
81
+ columnize (>= 0.1)
82
+ ruby-debug-base (~> 0.10.3.0)
83
+ ruby-debug-base (0.10.3)
84
+ linecache (>= 0.3)
85
+ ruby-debug-base19 (0.11.24)
86
+ columnize (>= 0.3.1)
87
+ linecache19 (>= 0.5.11)
88
+ ruby_core_source (>= 0.1.4)
89
+ ruby-debug19 (0.11.6)
90
+ columnize (>= 0.3.1)
91
+ linecache19 (>= 0.5.11)
92
+ ruby-debug-base19 (>= 0.11.19)
93
+ ruby_core_source (0.1.4)
94
+ archive-tar-minitar (>= 0.5.2)
95
+ sqlite3-ruby (1.3.1)
96
+ thor (0.14.0)
97
+ treetop (1.4.8)
98
+ polyglot (>= 0.3.1)
99
+ tzinfo (0.3.23)
100
+
101
+ PLATFORMS
102
+ ruby
103
+
104
+ DEPENDENCIES
105
+ rails (= 3.0.0)
106
+ rspec-rails (= 2.0.0.rc)
107
+ ruby-debug
108
+ ruby-debug19
109
+ sqlite3-ruby
data/README.markdown CHANGED
@@ -8,15 +8,9 @@ This library only supports in-site authentication and won't implement OpenID, Fa
8
8
  Installation
9
9
  ------------
10
10
 
11
- As plugin:
12
-
13
- script/plugin install git://github.com/fnando/simple_auth.git
14
-
15
- As gem:
16
-
17
11
  sudo gem install simple_auth
18
12
 
19
- Then run `script/generate simple_auth` to copy the initializer file.
13
+ Then run `rails generate simple_auth:install` to copy the initializer file.
20
14
 
21
15
  Usage
22
16
  -----
@@ -44,23 +38,15 @@ Your user model should have the attributes `password_hash` and `password_salt`.
44
38
  end
45
39
  end
46
40
 
47
- If your user model is other than `User`, you have to set it in your `config/initializer/simple_auth.rb` initializer file.
48
- You can also set up the credentials attributes.
49
-
50
- SimpleAuth.setup do |config|
51
- config.model = :account
52
- config.credentials = [:username]
53
- end
54
-
55
- On your model, call the method `has_authentication`.
41
+ In your model, use the `authentication` macro.
56
42
 
57
43
  class User < ActiveRecord::Base
58
- has_authentication
44
+ authentication
59
45
  end
60
46
 
61
- This will add some callbacks and password validations.
47
+ This will add some callbacks and password validations. It will also inject helper methods like `Model.authenticate`.
62
48
 
63
- After you set up the model, you can go the controller.
49
+ After you set up the model, you can go to the controller.
64
50
 
65
51
  class SessionsController < ApplicationController
66
52
  def new
@@ -97,6 +83,11 @@ Here's some usage examples:
97
83
  redirect_logged_user :only => [:index], :to => login_path
98
84
  redirect_logged_user :except => [:public], :to => login_path
99
85
 
86
+ You can skip the `:to` option if you set it globally on your initializer:
87
+
88
+ SimpleAuth::Config.logged_url = {:controller => "session", :action => "new"}
89
+ SimpleAuth::Config.logged_url = proc { login_path }
90
+
100
91
  To require a logged user, use the `require_logged_user` macro:
101
92
 
102
93
  class DashboardController < ApplicationController
@@ -112,8 +103,8 @@ Here's some usage examples:
112
103
 
113
104
  You can skip the `:to` option if you set it globally on your initializer:
114
105
 
115
- SimpleAuth::Config.redirect_to = {:controller => "session", :action => "new"}
116
- SimpleAuth::Config.redirect_to = proc { login_path }
106
+ SimpleAuth::Config.login_url = {:controller => "session", :action => "new"}
107
+ SimpleAuth::Config.login_url = proc { login_path }
117
108
 
118
109
  There are some helpers:
119
110
 
@@ -122,19 +113,12 @@ There are some helpers:
122
113
  current_session # controller & views
123
114
  when_logged(&block) # views
124
115
 
125
- If you're having problems to use any helper, include the module <tt>SimpleAuth::Helper</tt> to your <tt>ApplicationHelper</tt>.
116
+ If you're having problems to use any helper, include the module <tt>SimpleAuth::Helper</tt> on your <tt>ApplicationHelper</tt>.
126
117
 
127
118
  module ApplicationHelper
128
119
  include SimpleAuth::Helper
129
120
  end
130
121
 
131
- Sinatra support
132
- ---------------
133
-
134
- Sinatra is not fully supported. For now, you can only use the ActiveRecord part:
135
-
136
- require "simple_auth/active_record"
137
-
138
122
  Troubleshooting
139
123
  ---------------
140
124
 
data/Rakefile CHANGED
@@ -1,39 +1,27 @@
1
- require 'rake'
2
-
3
- if ENV["TARGET"] == "rails3"
4
- require 'rspec/core/rake_task'
5
- Rspec::Core::RakeTask.new(:spec)
6
- else
7
- require 'spec/rake/spectask'
8
- desc 'Run the specs'
9
- Spec::Rake::SpecTask.new(:spec) do |t|
10
- t.spec_opts = ['--colour --format specdoc --loadby mtime --reverse']
11
- t.spec_files = FileList['spec/**/*_spec.rb']
12
- end
13
- end
14
-
15
- require 'jeweler'
16
- require File.dirname(__FILE__) + '/lib/simple_auth/version'
1
+ require "rspec/core/rake_task"
2
+ require File.dirname(__FILE__) + "/lib/simple_auth/version"
17
3
 
4
+ RSpec::Core::RakeTask.new
18
5
 
19
- desc 'Default: run specs.'
6
+ desc "Default: run specs."
20
7
  task :default => :spec
21
8
 
9
+ begin
10
+ require "jeweler"
11
+
12
+ JEWEL = Jeweler::Tasks.new do |gem|
13
+ gem.name = "simple_auth"
14
+ gem.version = SimpleAuth::Version::STRING
15
+ gem.summary = "A simple authentication system for Rails apps"
16
+ gem.description = "When Authlogic & Devise are just too much."
17
+ gem.authors = ["Nando Vieira"]
18
+ gem.email = "fnando.vieira@gmail.com"
19
+ gem.homepage = "http://github.com/fnando/simple_auth"
20
+ gem.has_rdoc = true
21
+ gem.add_dependency "rails", ">= 3.0.0"
22
+ end
22
23
 
23
- JEWEL = Jeweler::Tasks.new do |gem|
24
- gem.name = "simple_auth"
25
- gem.version = SimpleAuth::Version::STRING
26
- gem.summary = "A simple authentication system for Rails apps"
27
- gem.description = <<-TXT
28
- When Authlogic & Devise are just too much.
29
- TXT
30
-
31
- gem.authors = ["Nando Vieira"]
32
- gem.email = "fnando.vieira@gmail.com"
33
- gem.homepage = "http://github.com/fnando/simple_auth"
34
-
35
- gem.has_rdoc = false
36
- gem.files = %w(Rakefile simple_auth.gemspec init.rb VERSION README.markdown) + Dir["{generators,lib,spec,app,config}/**/*"]
24
+ Jeweler::GemcutterTasks.new
25
+ rescue LoadError => e
26
+ puts "You don't Jeweler installed, so you won't be able to build gems."
37
27
  end
38
-
39
- Jeweler::GemcutterTasks.new
@@ -1,58 +1,57 @@
1
1
  module SimpleAuth
2
2
  module ActionController
3
- module Implementation
4
- def self.included(base)
5
- base.prepend_before_filter :activate_simple_auth
6
- base.helper_method :current_user, :current_session, :logged_in?
3
+ def self.included(base)
4
+ base.class_eval do
5
+ include InstanceMethods
6
+ extend ClassMethods
7
7
  end
8
8
  end
9
9
 
10
10
  module InstanceMethods
11
11
  private
12
- def current_session
13
- @current_session ||= SimpleAuth::Session.find
14
- end
12
+ def current_session
13
+ @current_session ||= SimpleAuth::Session.find
14
+ end
15
15
 
16
- def current_user
17
- current_session && current_session.record
18
- end
16
+ def current_user
17
+ current_session && current_session.record
18
+ end
19
19
 
20
- def authorized?
21
- true
22
- end
20
+ def authorized?
21
+ true
22
+ end
23
23
 
24
- def logged_in?
25
- current_user != nil
26
- end
24
+ def logged_in?
25
+ current_user != nil
26
+ end
27
27
 
28
- def activate_simple_auth
29
- SimpleAuth::Config.controller = self
30
- end
28
+ def activate_simple_auth
29
+ SimpleAuth::Config.controller = self
30
+ end
31
31
 
32
- def simple_auth_path(controller, path)
33
- path ||= SimpleAuth::Config.redirect_to
34
- path = controller.instance_eval(&path) if path.kind_of?(Proc)
35
- path
36
- end
32
+ def simple_auth_url_for(method, controller, path)
33
+ path ||= SimpleAuth::Config.send(method)
34
+ path = controller.instance_eval(&path) if path.kind_of?(Proc)
35
+ path
36
+ end
37
37
  end
38
38
 
39
39
  module ClassMethods
40
- # Redirect unlogged users to the specified :to path
40
+ # Redirect unlogged users to the specified <tt>:to</tt> path
41
41
  #
42
42
  # require_logged_user :to => proc { login_path }
43
43
  # require_logged_user :to => {:controller => "session", :action => "new"}
44
44
  # require_logged_user :only => [:index], :to => login_path
45
45
  # require_logged_user :except => [:public], :to => login_path
46
46
  #
47
- # You can set :to globally:
47
+ # You can set login url globally:
48
+ #
49
+ # SimpleAuth::Config.login_url = {:controller => "session", :action => "new"}
50
+ # SimpleAuth::Config.login_url = proc { login_path }
48
51
  #
49
- # SimpleAuth::Config.redirect_to = {:controller => "session", :action => "new"}
50
- # SimpleAuth::Config.redirect_to = proc { login_path }
51
52
  def require_logged_user(options = {})
52
- before_filter(options.except(:to)) do |c|
53
- c.instance_eval do
54
- path = simple_auth_path(c, options[:to])
55
-
53
+ before_filter options.except(:to) do |controller|
54
+ controller.instance_eval do
56
55
  unless logged_in? && authorized?
57
56
  flash[:alert] = I18n.translate("simple_auth.sessions.need_to_be_logged")
58
57
 
@@ -63,23 +62,28 @@ module SimpleAuth
63
62
  end
64
63
 
65
64
  session[:return_to] = return_to if request.get?
66
- redirect_to path
65
+ redirect_to simple_auth_url_for(:login_url, controller, options[:to])
67
66
  end
68
67
  end
69
68
  end
70
69
  end
71
70
 
72
- # Redirect logged users to the specified :to path
71
+ # Redirect logged users to the specified <tt>:to</tt> path
73
72
  #
74
73
  # redirect_logged_user :to => proc { login_path }
75
74
  # redirect_logged_user :to => {:controller => "dashboard"}
76
75
  # redirect_logged_user :only => [:index], :to => login_path
77
76
  # redirect_logged_user :except => [:public], :to => login_path
77
+ #
78
+ # You can set the logged url globally:
79
+ #
80
+ # SimpleAuth::Config.logged_url = {:controller => "dashboard", :action => "index"}
81
+ # SimpleAuth::Config.logged_url = proc { dashboard_path }
82
+ #
78
83
  def redirect_logged_user(options = {})
79
- before_filter(options.except(:to)) do |c|
80
- c.instance_eval do
81
- path = simple_auth_path(c, options[:to])
82
- redirect_to path if logged_in?
84
+ before_filter options.except(:to) do |controller|
85
+ controller.instance_eval do
86
+ redirect_to simple_auth_url_for(:logged_url, controller, options[:to]) if logged_in?
83
87
  end
84
88
  end
85
89
  end
@@ -1,7 +1,48 @@
1
- require "simple_auth/config" unless defined?(SimpleAuth::Config)
2
-
3
1
  module SimpleAuth
4
2
  module ActiveRecord
3
+ def self.included(base)
4
+ base.class_eval { extend Macro }
5
+ end
6
+
7
+ module Macro
8
+ # Set virtual attributes, callbacks and validations.
9
+ # Is called automatically after setting up configuration with
10
+ # `SimpleAuth.setup {|config| config.model = :user}`.
11
+ #
12
+ # class User < ActiveRecord::Base
13
+ # authentication
14
+ # end
15
+ #
16
+ # Can set configuration when a block is provided.
17
+ #
18
+ # class User < ActiveRecord::Base
19
+ # authentication do |config|
20
+ # config.credentials = ["email"]
21
+ # end
22
+ # end
23
+ #
24
+ def authentication(&block)
25
+ SimpleAuth.setup(&block) if block_given?
26
+ SimpleAuth::Config.model ||= name.underscore.to_sym
27
+
28
+ return if respond_to?(:authenticate)
29
+
30
+ attr_reader :password
31
+ attr_accessor :password_confirmation
32
+
33
+ include SimpleAuth::ActiveRecord::InstanceMethods
34
+ extend SimpleAuth::ActiveRecord::ClassMethods
35
+
36
+ before_save :encrypt_password, :if => :validate_password?
37
+ after_save :erase_password
38
+
39
+ validates_presence_of :password, :if => :validate_password?
40
+ validates_length_of :password, :if => :validate_password?, :minimum => 4, :allow_blank => true
41
+ validates_presence_of :password_confirmation, :if => :validate_password?
42
+ validates_confirmation_of :password, :if => :validate_password?
43
+ end
44
+ end
45
+
5
46
  module InstanceMethods
6
47
  def password=(password)
7
48
  @password_changed = true
@@ -13,23 +54,23 @@ module SimpleAuth
13
54
  end
14
55
 
15
56
  private
16
- def encrypt_password
17
- self.password_salt = SimpleAuth::Config.salt.call(self)
18
- self.password_hash = SimpleAuth::Config.crypter.call(password, password_salt)
19
- end
57
+ def encrypt_password
58
+ self.password_salt = SimpleAuth::Config.salt.call(self)
59
+ self.password_hash = SimpleAuth::Config.crypter.call(password, password_salt)
60
+ end
20
61
 
21
- def erase_password
22
- self.password = nil
23
- self.password_confirmation = nil
62
+ def erase_password
63
+ self.password = nil
64
+ self.password_confirmation = nil
24
65
 
25
- # Mark password as unchanged after erasing passwords,
26
- # or it will be marked as changed anyway
27
- @password_changed = false
28
- end
66
+ # Mark password as unchanged after erasing passwords,
67
+ # or it will be marked as changed anyway
68
+ @password_changed = false
69
+ end
29
70
 
30
- def validate_password?
31
- new_record? || password_changed?
32
- end
71
+ def validate_password?
72
+ new_record? || password_changed?
73
+ end
33
74
  end
34
75
 
35
76
  module ClassMethods
@@ -61,38 +102,9 @@ module SimpleAuth
61
102
  # Compare password
62
103
  return nil unless record.password_hash == SimpleAuth::Config.crypter.call(password, record.password_salt)
63
104
 
64
- return record
65
- end
66
-
67
- # Set virtual attributes, callbacks and acts as a wrapper for
68
- # SimpleAuth::Config if a block is provided.
69
- #
70
- # class User < ActiveRecord::Base
71
- # has_authentication
72
- # end
73
- #
74
- # class User < ActiveRecord::Base
75
- # has_authentication do |config|
76
- # config.credentials = [:email]
77
- # end
78
- # end
79
- def has_authentication(&block)
80
- attr_reader :password
81
- attr_accessor :password_confirmation
82
-
83
- SimpleAuth.setup(&block)
84
-
85
- before_save :encrypt_password, :if => :validate_password?
86
- after_save :erase_password
87
-
88
- validates_presence_of :password, :if => :validate_password?
89
- validates_length_of :password, :if => :validate_password?, :minimum => 4, :allow_blank => true
90
- validates_presence_of :password_confirmation, :if => :validate_password?
91
- validates_confirmation_of :password, :if => :validate_password?
105
+ # Yay! Everything matched so return record.
106
+ record
92
107
  end
93
108
  end
94
109
  end
95
110
  end
96
-
97
- ::ActiveRecord::Base.send :include, SimpleAuth::ActiveRecord::InstanceMethods
98
- ::ActiveRecord::Base.send :extend, SimpleAuth::ActiveRecord::ClassMethods
@@ -1,5 +1,5 @@
1
1
  module SimpleAuth
2
- # Add a shortcut to Authorization::Config
2
+ # Add a shortcut to SimpleAuth::Config
3
3
  def self.setup(&block)
4
4
  yield SimpleAuth::Config if block_given?
5
5
  end
@@ -32,8 +32,13 @@ module SimpleAuth
32
32
  @@controller = nil
33
33
 
34
34
  # Set the login url
35
- cattr_accessor :redirect_to
36
- @@redirect_to = proc { login_path }
35
+ cattr_accessor :login_url
36
+ @@login_url = proc { login_path }
37
+
38
+ # Logged users will be redirect to this url
39
+ # when +redirect_logged_user+ helper is used.
40
+ cattr_accessor :logged_url
41
+ @@logged_url = proc { dashboard_path }
37
42
 
38
43
  # Reset session before saving the user session
39
44
  cattr_accessor :reset_session
@@ -0,0 +1,11 @@
1
+ require "rails/generators/base"
2
+
3
+ module SimpleAuth
4
+ class InstallGenerator < ::Rails::Generators::Base
5
+ source_root File.dirname(__FILE__) + "/../../templates"
6
+
7
+ def copy_initializer_file
8
+ copy_file "initializer.rb", "config/initializers/simple_auth.rb"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,24 @@
1
+ module SimpleAuth
2
+ class Railtie < Rails::Railtie
3
+ generators do
4
+ require "simple_auth/generator"
5
+ end
6
+
7
+ config.after_initialize do
8
+ ActiveSupport.on_load(:action_controller) do
9
+ include SimpleAuth::ActionController
10
+ helper SimpleAuth::Helper
11
+ prepend_before_filter :activate_simple_auth
12
+ helper_method :current_user, :current_session, :logged_in?
13
+ end
14
+
15
+ ActiveSupport.on_load(:active_record) do
16
+ include SimpleAuth::ActiveRecord
17
+ end
18
+ end
19
+
20
+ initializer "simple_auth.initialize" do |app|
21
+ ::I18n.load_path += Dir[File.dirname(__FILE__) + "/../../config/locales/*.yml"]
22
+ end
23
+ end
24
+ end
@@ -66,6 +66,10 @@ module SimpleAuth
66
66
  true
67
67
  end
68
68
 
69
+ def self.model_name
70
+ ActiveModel::Name.new(self)
71
+ end
72
+
69
73
  def initialize(options = {})
70
74
  options ||= {}
71
75
 
@@ -76,10 +80,18 @@ module SimpleAuth
76
80
  @errors = Errors.new
77
81
  end
78
82
 
83
+ def to_key
84
+ nil
85
+ end
86
+
79
87
  def new_record?
80
88
  record.nil?
81
89
  end
82
90
 
91
+ def persisted?
92
+ !new_record?
93
+ end
94
+
83
95
  def valid?
84
96
  if record
85
97
  true
@@ -1,8 +1,8 @@
1
1
  module SimpleAuth
2
2
  module Version
3
- MAJOR = "0"
4
- MINOR = "1"
5
- PATCH = "8"
3
+ MAJOR = "1"
4
+ MINOR = "0"
5
+ PATCH = "1"
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
data/lib/simple_auth.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "digest/sha2"
2
+ require "simple_auth/railtie"
2
3
  require "simple_auth/config"
3
4
  require "simple_auth/action_controller"
4
5
  require "simple_auth/active_record"
@@ -9,10 +10,3 @@ require "simple_auth/version"
9
10
  module SimpleAuth
10
11
  class NotAuthorized < Exception; end
11
12
  end
12
-
13
- ::ActionController::Base.send :include, SimpleAuth::ActionController::Implementation
14
- ::ActionController::Base.send :include, SimpleAuth::ActionController::InstanceMethods
15
- ::ActionController::Base.send :extend, SimpleAuth::ActionController::ClassMethods
16
- ::ApplicationController.helper SimpleAuth::Helper if defined?(::ApplicationController)
17
-
18
- I18n.load_path += Dir[File.dirname(__FILE__) + "/../config/locales/*.yml"]