auth_logic_user_session_helper 2.0.0
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/MIT-LICENSE +20 -0
- data/README.rdoc +40 -0
- data/Rakefile +23 -0
- data/VERSION +1 -0
- data/lib/auth_logic_user_session_helper.rb +22 -0
- data/lib/auth_logic_user_session_helper/auth_logic_test_helper.rb +20 -0
- data/lib/auth_logic_user_session_helper/instance_methods.rb +50 -0
- data/test/auth_logic_user_session_helper_test.rb +8 -0
- data/test/test_helper.rb +3 -0
- metadata +76 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 [Brent Greeff]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
= AuthLogic UserSession Helper
|
2
|
+
|
3
|
+
Bunch of convenience methods for use with AuthLogic and Rails.
|
4
|
+
|
5
|
+
Only works if you are using a standard user, and user_session.
|
6
|
+
|
7
|
+
Will be able to specify the model(s) names in the future.
|
8
|
+
|
9
|
+
== Example
|
10
|
+
|
11
|
+
|
12
|
+
* Get the current_user from the session
|
13
|
+
current_user
|
14
|
+
|
15
|
+
* Is there a user logged in?
|
16
|
+
user?
|
17
|
+
|
18
|
+
* Is there no user currently logged in?
|
19
|
+
no_user?
|
20
|
+
|
21
|
+
* A user is required! (use as before filter to redirect to '/login')
|
22
|
+
user_required
|
23
|
+
|
24
|
+
* A user cannot be logged in (will redirect to the root_url, whatever that is mapped to)
|
25
|
+
no_user_required
|
26
|
+
|
27
|
+
* If you need to remember what the user was trying to do before you made them login
|
28
|
+
store_location
|
29
|
+
redirect_back_or_default
|
30
|
+
|
31
|
+
=== user_required will store the requested location before redirecting.
|
32
|
+
=== Call redirect_back_or_default after login to enable this behaviour.
|
33
|
+
|
34
|
+
|
35
|
+
== Testing
|
36
|
+
|
37
|
+
Adds login_as and logout methods to tests.
|
38
|
+
|
39
|
+
|
40
|
+
Copyright (c) 2009 [Brent Greeff], released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc 'Test the auth_logic_user_session_helper plugin.'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.libs << 'test'
|
12
|
+
t.pattern = 'test/**/*_test.rb'
|
13
|
+
t.verbose = true
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Generate documentation for the auth_logic_user_session_helper plugin.'
|
17
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
18
|
+
rdoc.rdoc_dir = 'rdoc'
|
19
|
+
rdoc.title = 'AuthLogicUserSessionHelper'
|
20
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
21
|
+
rdoc.rdoc_files.include('README')
|
22
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
23
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module AuthLogic
|
2
|
+
module UserSessionHelper
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.class_eval do
|
6
|
+
include InstanceMethods
|
7
|
+
|
8
|
+
helper_method :current_user
|
9
|
+
helper_method :user?
|
10
|
+
helper_method :no_user?
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
ActionController::Base.send(:include, AuthLogic::UserSessionHelper)
|
17
|
+
|
18
|
+
if RAILS_ENV.eql? 'test'
|
19
|
+
require 'test_help'
|
20
|
+
require 'auth_logic_user_session_helper/auth_logic_test_helper'
|
21
|
+
ActiveSupport::TestCase.send(:include, AuthLogic::TestHelper)
|
22
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module AuthLogic
|
2
|
+
module TestHelper
|
3
|
+
def login_as(someone)
|
4
|
+
login_user(someone)
|
5
|
+
end
|
6
|
+
|
7
|
+
def login_user(user)
|
8
|
+
raise 'Cannot login, user is not a User' unless user.is_a? User
|
9
|
+
UserSession.create(user)
|
10
|
+
end
|
11
|
+
|
12
|
+
def logout
|
13
|
+
logout_user
|
14
|
+
end
|
15
|
+
|
16
|
+
def logout_user
|
17
|
+
@request.session[:user_credentials] = nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module AuthLogic
|
2
|
+
module UserSessionHelper
|
3
|
+
|
4
|
+
module InstanceMethods
|
5
|
+
def current_user_session
|
6
|
+
return @current_user_session if defined?(@current_user_session)
|
7
|
+
@current_user_session = UserSession.find
|
8
|
+
end
|
9
|
+
|
10
|
+
def current_user
|
11
|
+
return @current_user if defined?(@current_user)
|
12
|
+
@current_user = current_user_session && current_user_session.record
|
13
|
+
end
|
14
|
+
|
15
|
+
def user?
|
16
|
+
return current_user.is_a? User
|
17
|
+
end
|
18
|
+
|
19
|
+
def no_user?
|
20
|
+
return current_user.nil?
|
21
|
+
end
|
22
|
+
|
23
|
+
def user_required
|
24
|
+
return if user?
|
25
|
+
|
26
|
+
store_location
|
27
|
+
flash[:error] = 'Please log in first'
|
28
|
+
redirect_to login_url
|
29
|
+
end
|
30
|
+
|
31
|
+
def no_user_required
|
32
|
+
return if no_user?
|
33
|
+
|
34
|
+
flash[:error] = 'You are already logged in'
|
35
|
+
redirect_to root_url
|
36
|
+
end
|
37
|
+
|
38
|
+
# Redirect back
|
39
|
+
|
40
|
+
def store_location
|
41
|
+
session[:return_to] = request.request_uri
|
42
|
+
end
|
43
|
+
|
44
|
+
def redirect_back_or_default(default)
|
45
|
+
redirect_to(session[:return_to] || default)
|
46
|
+
session[:return_to] = nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: auth_logic_user_session_helper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 2.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Brent Greeff
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-10-29 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Convenience methods for use with AuthLogic and Rails. :current_user, user? etc
|
23
|
+
email: email@brentgreeff.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- MIT-LICENSE
|
30
|
+
- README.rdoc
|
31
|
+
files:
|
32
|
+
- MIT-LICENSE
|
33
|
+
- README.rdoc
|
34
|
+
- Rakefile
|
35
|
+
- VERSION
|
36
|
+
- lib/auth_logic_user_session_helper.rb
|
37
|
+
- lib/auth_logic_user_session_helper/auth_logic_test_helper.rb
|
38
|
+
- lib/auth_logic_user_session_helper/instance_methods.rb
|
39
|
+
- test/auth_logic_user_session_helper_test.rb
|
40
|
+
- test/test_helper.rb
|
41
|
+
has_rdoc: true
|
42
|
+
homepage: http://github.com/brentgreeff/auth_logic_user_session_helper
|
43
|
+
licenses: []
|
44
|
+
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options:
|
47
|
+
- --charset=UTF-8
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
hash: 3
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
version: "0"
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.3.7
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: Convenience methods for use with AuthLogic and Rails. :current_user, user? etc.
|
75
|
+
test_files: []
|
76
|
+
|