rails_warden 0.2.2 → 0.2.3
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.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/rails_warden.rb +34 -14
- data/lib/rails_warden/controller_mixin.rb +9 -8
- data/lib/rails_warden/manager.rb +1 -0
- data/lib/rails_warden/rails_settings.rb +11 -10
- data/rails_warden.gemspec +4 -4
- data/spec/rails_warden_spec.rb +18 -18
- metadata +3 -3
data/Rakefile
CHANGED
@@ -21,7 +21,7 @@ begin
|
|
21
21
|
gem.email = EMAIL
|
22
22
|
gem.homepage = HOMEPAGE
|
23
23
|
gem.rubyforge_project = "warden"
|
24
|
-
gem.add_dependency "warden", "
|
24
|
+
gem.add_dependency "warden", ">= 0.3.2"
|
25
25
|
end
|
26
26
|
rescue LoadError
|
27
27
|
puts "Jeweler (or a dependency) not available. Install with: sudo gem install jeweler"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
data/lib/rails_warden.rb
CHANGED
@@ -1,15 +1,35 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'rubygems'
|
1
|
+
# encoding: utf-8
|
4
2
|
require 'warden'
|
5
3
|
require 'active_support'
|
6
|
-
|
7
|
-
|
8
|
-
require "
|
4
|
+
|
5
|
+
$:.unshift File.expand_path(File.dirname(__FILE__))
|
6
|
+
require "rails_warden/manager"
|
7
|
+
require "rails_warden/rails_settings"
|
8
|
+
require "rails_warden/controller_mixin"
|
9
|
+
|
10
|
+
module Warden::Mixins::Common
|
11
|
+
# Gets the rails request object by default if it's available
|
12
|
+
def request
|
13
|
+
return @request if @request
|
14
|
+
if env['action_controller.rescue.request']
|
15
|
+
@request = env['action_controller.rescue.request']
|
16
|
+
else
|
17
|
+
Rack::Request.new(env)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def raw_session
|
22
|
+
request.session
|
23
|
+
end
|
24
|
+
|
25
|
+
def reset_session!
|
26
|
+
raw_session.inspect # why do I have to inspect it to get it to clear?
|
27
|
+
raw_session.clear
|
28
|
+
end
|
29
|
+
end
|
9
30
|
|
10
31
|
Warden::Manager.before_failure do |env, opts|
|
11
|
-
request =
|
12
|
-
request.params["action"] = RailsWarden.unauthenticated_action || "unauthenticated"
|
32
|
+
env['warden'].request.params['action'] = RailsWarden.unauthenticated_action || "unauthenticated"
|
13
33
|
end
|
14
34
|
|
15
35
|
if defined?(Rails)
|
@@ -18,22 +38,22 @@ if defined?(Rails)
|
|
18
38
|
include RailsWarden::Mixins::HelperMethods
|
19
39
|
include RailsWarden::Mixins::ControllerOnlyMethods
|
20
40
|
end
|
21
|
-
|
41
|
+
|
22
42
|
module ApplicationHelper
|
23
43
|
include RailsWarden::Mixins::HelperMethods
|
24
44
|
end
|
25
45
|
end
|
26
46
|
end
|
27
47
|
|
28
|
-
# Session Serialization in. This block determines how the user will
|
29
|
-
# be stored in the session. If you're using a complex object like an
|
48
|
+
# Session Serialization in. This block determines how the user will
|
49
|
+
# be stored in the session. If you're using a complex object like an
|
30
50
|
# ActiveRecord model, it is not a good idea to store the complete object.
|
31
51
|
# An ID is sufficient
|
32
|
-
Warden::Manager.serialize_into_session{ |user| [user.class, user.id] }
|
52
|
+
Warden::Manager.serialize_into_session{ |user| [user.class, user.id] }
|
33
53
|
|
34
54
|
# Session Serialization out. This block gets the user out of the session.
|
35
55
|
# It should be the reverse of serializing the object into the session
|
36
|
-
Warden::Manager.serialize_from_session do |klass, id|
|
56
|
+
Warden::Manager.serialize_from_session do |klass, id|
|
37
57
|
klass = case klass
|
38
58
|
when Class
|
39
59
|
klass
|
@@ -41,4 +61,4 @@ Warden::Manager.serialize_from_session do |klass, id|
|
|
41
61
|
klass.to_s.classify.constantize
|
42
62
|
end
|
43
63
|
klass.find(id)
|
44
|
-
end
|
64
|
+
end
|
@@ -1,32 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
module RailsWarden
|
2
|
-
module Mixins
|
3
|
+
module Mixins
|
3
4
|
module HelperMethods
|
4
5
|
# The main accessor for the warden proxy instance
|
5
6
|
# :api: public
|
6
7
|
def warden
|
7
8
|
request.env['warden']
|
8
9
|
end
|
9
|
-
|
10
|
+
|
10
11
|
# Proxy to the authenticated? method on warden
|
11
12
|
# :api: public
|
12
13
|
def authenticated?(*args)
|
13
14
|
warden.authenticated?(*args)
|
14
15
|
end
|
15
16
|
alias_method :logged_in?, :authenticated?
|
16
|
-
|
17
|
+
|
17
18
|
# Access the currently logged in user
|
18
19
|
# :api: public
|
19
20
|
def user(*args)
|
20
21
|
warden.user(*args)
|
21
22
|
end
|
22
23
|
alias_method :current_user, :user
|
23
|
-
|
24
|
+
|
24
25
|
def user=(user)
|
25
26
|
warden.set_user user
|
26
27
|
end
|
27
28
|
alias_method :current_user=, :user=
|
28
29
|
end # Helper Methods
|
29
|
-
|
30
|
+
|
30
31
|
module ControllerOnlyMethods
|
31
32
|
# Logout the current user
|
32
33
|
# :api: public
|
@@ -34,19 +35,19 @@ module RailsWarden
|
|
34
35
|
warden._session.inspect # Without this inspect here. The session does not clear :|
|
35
36
|
warden.logout(*args)
|
36
37
|
end
|
37
|
-
|
38
|
+
|
38
39
|
# Proxy to the authenticate method on warden
|
39
40
|
# :api: public
|
40
41
|
def authenticate(*args)
|
41
42
|
warden.authenticate(*args)
|
42
43
|
end
|
43
|
-
|
44
|
+
|
44
45
|
# Proxy to the authenticate method on warden
|
45
46
|
# :api: public
|
46
47
|
def authenticate!(*args)
|
47
48
|
warden.authenticate!(*args)
|
48
49
|
end
|
49
|
-
|
50
|
+
|
50
51
|
end
|
51
52
|
end
|
52
53
|
end
|
data/lib/rails_warden/manager.rb
CHANGED
@@ -1,20 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
module RailsWarden
|
2
|
-
|
3
|
+
|
3
4
|
# Set the default user class for the application
|
4
5
|
# :api: public
|
5
6
|
def self.default_user_class=(klass)
|
6
7
|
@default_user_class = klass
|
7
8
|
end
|
8
|
-
|
9
|
-
# Accessor for the default user class for the application
|
9
|
+
|
10
|
+
# Accessor for the default user class for the application
|
10
11
|
# :api: public
|
11
12
|
def self.default_user_class
|
12
13
|
@default_user_class ||= User
|
13
14
|
end
|
14
|
-
|
15
|
+
|
15
16
|
# Get the action called when there is an unauthenticated failure
|
16
17
|
# This is usually an action on a controller
|
17
|
-
# The action is called on the failure application. This would normally be
|
18
|
+
# The action is called on the failure application. This would normally be
|
18
19
|
# A rails controller
|
19
20
|
#
|
20
21
|
# Example
|
@@ -22,7 +23,7 @@ module RailsWarden
|
|
22
23
|
# :defaults => :password,
|
23
24
|
# :unauthenticated_action => :bad_login
|
24
25
|
# )
|
25
|
-
#
|
26
|
+
#
|
26
27
|
# The unauthenticated_action is :bad_login
|
27
28
|
# The bad_login action will be called on the LoginController
|
28
29
|
# :api: public
|
@@ -30,10 +31,10 @@ module RailsWarden
|
|
30
31
|
action = action.to_s if action
|
31
32
|
@unauthenticated_action = action
|
32
33
|
end
|
33
|
-
|
34
|
+
|
34
35
|
# Get the action called when there is an unauthenticated failure
|
35
36
|
# This is usually an action on a controller
|
36
|
-
# The action is called on the failure application. This would normally be
|
37
|
+
# The action is called on the failure application. This would normally be
|
37
38
|
# A rails controller
|
38
39
|
#
|
39
40
|
# Example
|
@@ -41,11 +42,11 @@ module RailsWarden
|
|
41
42
|
# :defaults => :password,
|
42
43
|
# :unauthenticated_action => :bad_login
|
43
44
|
# )
|
44
|
-
#
|
45
|
+
#
|
45
46
|
# The unauthenticated_action is :bad_login
|
46
47
|
# The bad_login action will be called on the LoginController
|
47
48
|
# :api: public
|
48
49
|
def self.unauthenticated_action
|
49
50
|
@unauthenticated_action ||= "unauthenticated"
|
50
51
|
end
|
51
|
-
end
|
52
|
+
end
|
data/rails_warden.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rails_warden}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Daniel Neighman"]
|
@@ -52,11 +52,11 @@ Gem::Specification.new do |s|
|
|
52
52
|
s.specification_version = 3
|
53
53
|
|
54
54
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
55
|
-
s.add_runtime_dependency(%q<warden>, ["
|
55
|
+
s.add_runtime_dependency(%q<warden>, [">= 0.3.2"])
|
56
56
|
else
|
57
|
-
s.add_dependency(%q<warden>, ["
|
57
|
+
s.add_dependency(%q<warden>, [">= 0.3.2"])
|
58
58
|
end
|
59
59
|
else
|
60
|
-
s.add_dependency(%q<warden>, ["
|
60
|
+
s.add_dependency(%q<warden>, [">= 0.3.2"])
|
61
61
|
end
|
62
62
|
end
|
data/spec/rails_warden_spec.rb
CHANGED
@@ -1,45 +1,45 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
3
|
describe "rails_warden" do
|
4
|
-
|
4
|
+
|
5
5
|
before(:each) do
|
6
|
-
@app = lambda{|e|
|
7
|
-
class FooFailure
|
6
|
+
@app = lambda{|e| Rack::Resposnse.new("response").finish}
|
7
|
+
class ::FooFailure
|
8
8
|
end
|
9
|
-
|
10
|
-
class FooUser
|
9
|
+
|
10
|
+
class ::FooUser
|
11
11
|
end
|
12
|
-
|
13
|
-
class User
|
12
|
+
|
13
|
+
class ::User
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
RailsWarden.default_user_class = nil
|
17
17
|
RailsWarden.unauthenticated_action = nil
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
it "RailsWarden::Manager.new should return an instance of Warden::Manager" do
|
21
21
|
r = RailsWarden::Manager.new(@app, :failure_app => "foo_failure", :defaults => :password)
|
22
22
|
r.should be_an_instance_of(Warden::Manager)
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
it "should set the failure application to FooFailure" do
|
26
26
|
r = RailsWarden::Manager.new(@app, :failure_app => "foo_failure", :defaults => :password)
|
27
27
|
r.failure_app.should == FooFailure
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
it "should set the default user to FooUser if specified" do
|
31
|
-
r = RailsWarden::Manager.new(@app, :failure_app => "foo_failure",
|
32
|
-
:defaults => :password,
|
31
|
+
r = RailsWarden::Manager.new(@app, :failure_app => "foo_failure",
|
32
|
+
:defaults => :password,
|
33
33
|
:default_user => "foo_user")
|
34
34
|
RailsWarden.default_user_class.should == FooUser
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
it "should set the default user to User if there is none specified" do
|
38
|
-
r = RailsWarden::Manager.new(@app, :failure_app => "foo_failure",
|
38
|
+
r = RailsWarden::Manager.new(@app, :failure_app => "foo_failure",
|
39
39
|
:defaults => :password)
|
40
40
|
RailsWarden.default_user_class.should == User
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
it "should set the failure action when specified" do
|
44
44
|
r = RailsWarden::Manager.new(@app, :failure_app => "foo_failure",
|
45
45
|
:defaults => :password,
|
@@ -47,11 +47,11 @@ describe "rails_warden" do
|
|
47
47
|
)
|
48
48
|
RailsWarden.unauthenticated_action.should == "bad_login"
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
it "should set the failure action to unauthenticated when not specified" do
|
52
52
|
r = RailsWarden::Manager.new(@app, :failure_app => "foo_failure",
|
53
53
|
:defaults => :password
|
54
54
|
)
|
55
55
|
RailsWarden.unauthenticated_action.should == "unauthenticated"
|
56
56
|
end
|
57
|
-
end
|
57
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_warden
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Neighman
|
@@ -18,9 +18,9 @@ dependencies:
|
|
18
18
|
version_requirement:
|
19
19
|
version_requirements: !ruby/object:Gem::Requirement
|
20
20
|
requirements:
|
21
|
-
- - "
|
21
|
+
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.2
|
23
|
+
version: 0.3.2
|
24
24
|
version:
|
25
25
|
description: A gem that provides authenitcation via the Warden framework
|
26
26
|
email: has.sox@gmail.com
|