josevalim-auth_helpers 0.4.1 → 0.5.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/README +5 -1
- data/lib/auth_helpers/controller/confirmable.rb +11 -23
- data/lib/auth_helpers/controller/helpers.rb +9 -8
- data/lib/auth_helpers/controller/recoverable.rb +29 -43
- metadata +12 -2
data/README
CHANGED
@@ -17,13 +17,17 @@ Authlogic also include some controllers to deal with the modules added. For
|
|
17
17
|
example, if you add Recoverable to your model, you can have all password
|
18
18
|
management for free, if you inherit from the Recoverable controller:
|
19
19
|
|
20
|
-
class AccountPasswordsController < AuthHelpers::Controller
|
20
|
+
class AccountPasswordsController < AuthHelpers::Controller::Recoverable
|
21
21
|
end
|
22
22
|
|
23
23
|
This functionality is powered by InheritedResources, which is available at:
|
24
24
|
|
25
25
|
http://github.com/josevalim/inherited_resources
|
26
26
|
|
27
|
+
You can see an example at:
|
28
|
+
|
29
|
+
http://github.com/josevalim/starter
|
30
|
+
|
27
31
|
Installation
|
28
32
|
------------
|
29
33
|
|
@@ -13,53 +13,41 @@ module AuthHelpers
|
|
13
13
|
# GET /account/confirmation/new
|
14
14
|
def new(&block)
|
15
15
|
object = get_or_set_with_send(:new)
|
16
|
-
|
16
|
+
respond_with(object, &block)
|
17
17
|
end
|
18
18
|
alias :new! :new
|
19
19
|
|
20
20
|
# POST /account/confirmation
|
21
21
|
# POST /account/confirmation.xml
|
22
|
-
def create(&block)
|
22
|
+
def create(options={}, &block)
|
23
23
|
object = get_or_set_with_send(:find_and_resend_confirmation_instructions, params[self.instance_name])
|
24
|
-
respond_block, redirect_block = select_block_by_arity(block)
|
25
24
|
|
26
25
|
if object.errors.empty?
|
27
26
|
set_flash_message!(:notice, 'We sent confirmation instructions to your email, please check your inbox.')
|
28
|
-
|
29
|
-
|
30
|
-
format.html { redirect_to_block_or_scope_to(redirect_block, :session) }
|
31
|
-
format.all { head :ok }
|
27
|
+
respond_with_dual_blocks(object, options, true, block) do |format|
|
28
|
+
format.html { redirect_to(options[:location] || url_by_name_and_scope(:session)) }
|
32
29
|
end
|
33
30
|
else
|
34
31
|
set_flash_message!(:error)
|
35
|
-
|
36
|
-
|
37
|
-
respond_to_with_dual_blocks(false, block, options) do |format|
|
38
|
-
format.html { render :action => 'new' }
|
39
|
-
end
|
32
|
+
respond_with_dual_blocks(object, options, false, block)
|
40
33
|
end
|
41
34
|
end
|
42
35
|
alias :create! :create
|
43
36
|
|
44
37
|
# GET /account/confirmation?account[perishable_token]=xxxx
|
45
|
-
#
|
46
|
-
def show(&block)
|
38
|
+
# POST /account/confirmation.xml?account[perishable_token]=xxxx
|
39
|
+
def show(options={}, &block)
|
47
40
|
object = get_or_set_with_send(:find_and_confirm, params[self.instance_name])
|
48
|
-
respond_block, redirect_block = select_block_by_arity(block)
|
49
41
|
|
50
42
|
if object.errors.empty?
|
51
43
|
set_flash_message!(:notice, '{{resource_name}} was successfully confirmed.')
|
52
|
-
|
53
|
-
|
54
|
-
format.html { redirect_to_block_or_scope_to(redirect_block, :session) }
|
55
|
-
format.all { head :ok }
|
44
|
+
respond_with_dual_blocks(object, options, true, block) do |format|
|
45
|
+
format.html { redirect_to(options[:location] || url_by_name_and_scope(:session)) }
|
56
46
|
end
|
57
47
|
else
|
58
48
|
set_flash_message!(:error, object.errors.on(:perishable_token))
|
59
|
-
options
|
60
|
-
|
61
|
-
respond_to_with_dual_blocks(false, block, options) do |format|
|
62
|
-
format.html { redirect_to :action => 'new' }
|
49
|
+
respond_with_dual_blocks(object, options, false, block) do |format|
|
50
|
+
format.html { render :action => "new" }
|
63
51
|
end
|
64
52
|
end
|
65
53
|
end
|
@@ -4,6 +4,7 @@ module AuthHelpers
|
|
4
4
|
|
5
5
|
def self.included(base)
|
6
6
|
base.extend ClassMethods
|
7
|
+
base.respond_to :html
|
7
8
|
end
|
8
9
|
|
9
10
|
module ClassMethods
|
@@ -37,18 +38,17 @@ module AuthHelpers
|
|
37
38
|
self.instance_name = klass.name.downcase
|
38
39
|
self.route_name = klass.name.downcase
|
39
40
|
end
|
40
|
-
end
|
41
|
-
|
41
|
+
end
|
42
|
+
|
42
43
|
protected
|
43
44
|
|
44
|
-
#
|
45
|
-
# try to call the url given by scope, for example:
|
45
|
+
# Try to call a url using resource object and the scope, for example:
|
46
46
|
#
|
47
47
|
# new_account_session_url
|
48
48
|
# new_account_password_url
|
49
49
|
#
|
50
|
-
def
|
51
|
-
|
50
|
+
def url_by_name_and_scope(scope) #:nodoc:
|
51
|
+
send("new_#{self.route_name}_#{scope}_url")
|
52
52
|
end
|
53
53
|
|
54
54
|
# Try to get the instance variable, otherwise send the args given to
|
@@ -57,7 +57,8 @@ module AuthHelpers
|
|
57
57
|
def get_or_set_with_send(*args) #:nodoc:
|
58
58
|
instance_variable_get("@#{self.instance_name}") || instance_variable_set("@#{self.instance_name}", resource_class.send(*args))
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
end
|
62
|
-
end
|
62
|
+
end
|
63
|
+
end
|
63
64
|
|
@@ -9,67 +9,53 @@ module AuthHelpers
|
|
9
9
|
class << self
|
10
10
|
alias :has_recoverable :set_class_accessors_with_class
|
11
11
|
end
|
12
|
-
|
13
|
-
# GET /account/password/new
|
12
|
+
|
13
|
+
# GET /account/password/new
|
14
14
|
def new(&block)
|
15
|
-
object = get_or_set_with_send(:new)
|
16
|
-
|
17
|
-
end
|
18
|
-
alias :new! :new
|
19
|
-
|
20
|
-
# POST /account/password
|
21
|
-
# POST /account/password.xml
|
22
|
-
def create(&block)
|
23
|
-
object = get_or_set_with_send(:find_and_send_reset_password_instructions, params[self.instance_name])
|
24
|
-
respond_block, redirect_block = select_block_by_arity(block)
|
15
|
+
object = get_or_set_with_send(:new)
|
16
|
+
respond_with(object, &block)
|
17
|
+
end
|
18
|
+
alias :new! :new
|
19
|
+
|
20
|
+
# POST /account/password
|
21
|
+
# POST /account/password.xml
|
22
|
+
def create(options={}, &block)
|
23
|
+
object = get_or_set_with_send(:find_and_send_reset_password_instructions, params[self.instance_name])
|
25
24
|
|
26
25
|
if object.errors.empty?
|
27
26
|
set_flash_message!(:notice, 'We sent instruction to reset your password, please check your inbox.')
|
28
|
-
|
29
|
-
|
30
|
-
format.html { redirect_to_block_or_scope_to(redirect_block, :session) }
|
31
|
-
format.all { head :ok }
|
27
|
+
respond_with_dual_blocks(object, options, true, block) do |format|
|
28
|
+
format.html { redirect_to(options[:location] || url_by_name_and_scope(:session)) }
|
32
29
|
end
|
33
30
|
else
|
34
|
-
set_flash_message!(:error)
|
35
|
-
|
36
|
-
|
37
|
-
respond_to_with_dual_blocks(false, block, options) do |format|
|
38
|
-
format.html { render :action => 'new' }
|
39
|
-
end
|
31
|
+
set_flash_message!(:error)
|
32
|
+
respond_with_dual_blocks(object, options, false, block)
|
40
33
|
end
|
41
34
|
end
|
42
35
|
alias :create! :create
|
43
36
|
|
44
|
-
# GET /account/password/edit?account[perishable_token]=xxxx
|
37
|
+
# GET /account/password/edit?account[perishable_token]=xxxx
|
45
38
|
def edit(&block)
|
46
39
|
object = get_or_set_with_send(:new)
|
47
|
-
object.perishable_token = params[self.instance_name].try(:fetch, :perishable_token)
|
48
|
-
|
40
|
+
object.perishable_token = params[self.instance_name].try(:fetch, :perishable_token)
|
41
|
+
respond_with(object, &block)
|
49
42
|
end
|
50
|
-
alias :edit! :edit
|
51
|
-
|
52
|
-
# PUT /account/password
|
53
|
-
# PUT /account/password.xml
|
54
|
-
def update(&block)
|
55
|
-
object = get_or_set_with_send(:find_and_reset_password, params[self.instance_name])
|
56
|
-
respond_block, redirect_block = select_block_by_arity(block)
|
43
|
+
alias :edit! :edit
|
44
|
+
|
45
|
+
# PUT /account/password
|
46
|
+
# PUT /account/password.xml
|
47
|
+
def update(options={}, &block)
|
48
|
+
object = get_or_set_with_send(:find_and_reset_password, params[self.instance_name])
|
57
49
|
|
58
50
|
if object.errors.empty?
|
59
51
|
set_flash_message!(:notice, 'Your password was successfully reset.')
|
60
|
-
|
61
|
-
|
62
|
-
format.html { redirect_to_block_or_scope_to(redirect_block, :session) }
|
63
|
-
format.all { head :ok }
|
52
|
+
respond_with_dual_blocks(object, options, true, block) do |format|
|
53
|
+
format.html { redirect_to(options[:location] || url_by_name_and_scope(:session)) }
|
64
54
|
end
|
65
55
|
else
|
66
|
-
set_flash_message!(:error)
|
67
|
-
|
68
|
-
|
69
|
-
respond_to_with_dual_blocks(false, block, options) do |format|
|
70
|
-
format.html { render :action => 'edit' }
|
71
|
-
end
|
72
|
-
end
|
56
|
+
set_flash_message!(:error)
|
57
|
+
respond_with_dual_blocks(object, options, false, block)
|
58
|
+
end
|
73
59
|
end
|
74
60
|
alias :update! :update
|
75
61
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: josevalim-auth_helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Jos\xC3\xA9 Valim"
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-08-25 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -22,6 +22,16 @@ dependencies:
|
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: "0"
|
24
24
|
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: josevalim-inherited_resources
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.9.0
|
34
|
+
version:
|
25
35
|
description: AuthHelpers is a collection of modules to improve your Authlogic resources.
|
26
36
|
email: jose.valim@gmail.com
|
27
37
|
executables: []
|