caleb-restful-authentication 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +68 -0
- data/README.textile +240 -0
- data/Rakefile +32 -0
- data/TODO +15 -0
- data/generators/authenticated/USAGE +1 -0
- data/generators/authenticated/authenticated_generator.rb +508 -0
- data/generators/authenticated/lib/insert_routes.rb +54 -0
- data/generators/authenticated/templates/_model_partial.html.erb +8 -0
- data/generators/authenticated/templates/activation.erb +3 -0
- data/generators/authenticated/templates/authenticated_system.rb +189 -0
- data/generators/authenticated/templates/authenticated_test_helper.rb +22 -0
- data/generators/authenticated/templates/controller.rb +43 -0
- data/generators/authenticated/templates/helper.rb +2 -0
- data/generators/authenticated/templates/login.html.erb +21 -0
- data/generators/authenticated/templates/mailer.rb +33 -0
- data/generators/authenticated/templates/migration.rb +29 -0
- data/generators/authenticated/templates/model.rb +101 -0
- data/generators/authenticated/templates/model_controller.rb +117 -0
- data/generators/authenticated/templates/model_helper.rb +93 -0
- data/generators/authenticated/templates/model_helper_spec.rb +158 -0
- data/generators/authenticated/templates/observer.rb +14 -0
- data/generators/authenticated/templates/signup.html.erb +21 -0
- data/generators/authenticated/templates/signup_notification.erb +8 -0
- data/generators/authenticated/templates/site_keys.rb +38 -0
- data/generators/authenticated/templates/spec/controllers/access_control_spec.rb +90 -0
- data/generators/authenticated/templates/spec/controllers/authenticated_system_spec.rb +102 -0
- data/generators/authenticated/templates/spec/controllers/sessions_controller_spec.rb +139 -0
- data/generators/authenticated/templates/spec/controllers/users_controller_spec.rb +200 -0
- data/generators/authenticated/templates/spec/fixtures/users.yml +66 -0
- data/generators/authenticated/templates/spec/helpers/users_helper_spec.rb +141 -0
- data/generators/authenticated/templates/spec/models/user_spec.rb +295 -0
- data/generators/authenticated/templates/stories/rest_auth_stories.rb +22 -0
- data/generators/authenticated/templates/stories/rest_auth_stories_helper.rb +81 -0
- data/generators/authenticated/templates/stories/steps/ra_navigation_steps.rb +49 -0
- data/generators/authenticated/templates/stories/steps/ra_resource_steps.rb +179 -0
- data/generators/authenticated/templates/stories/steps/ra_response_steps.rb +171 -0
- data/generators/authenticated/templates/stories/steps/user_steps.rb +153 -0
- data/generators/authenticated/templates/stories/users/accounts.story +194 -0
- data/generators/authenticated/templates/stories/users/sessions.story +134 -0
- data/generators/authenticated/templates/test/functional_test.rb +82 -0
- data/generators/authenticated/templates/test/mailer_test.rb +31 -0
- data/generators/authenticated/templates/test/model_functional_test.rb +95 -0
- data/generators/authenticated/templates/test/unit_test.rb +166 -0
- data/init.rb +1 -0
- data/lib/authentication.rb +40 -0
- data/lib/authentication/by_cookie_token.rb +82 -0
- data/lib/authentication/by_password.rb +64 -0
- data/lib/authorization.rb +14 -0
- data/lib/authorization/aasm_roles.rb +64 -0
- data/lib/authorization/stateful_roles.rb +63 -0
- data/lib/trustification.rb +14 -0
- data/lib/trustification/email_validation.rb +20 -0
- data/rails/init.rb +6 -0
- metadata +115 -0
@@ -0,0 +1,64 @@
|
|
1
|
+
module Authentication
|
2
|
+
module ByPassword
|
3
|
+
# Stuff directives into including module
|
4
|
+
def self.included(recipient)
|
5
|
+
recipient.extend(ModelClassMethods)
|
6
|
+
recipient.class_eval do
|
7
|
+
include ModelInstanceMethods
|
8
|
+
|
9
|
+
# Virtual attribute for the unencrypted password
|
10
|
+
attr_accessor :password
|
11
|
+
validates_presence_of :password, :if => :password_required?
|
12
|
+
validates_presence_of :password_confirmation, :if => :password_required?
|
13
|
+
validates_confirmation_of :password, :if => :password_required?
|
14
|
+
validates_length_of :password, :within => 6..40, :if => :password_required?
|
15
|
+
before_save :encrypt_password
|
16
|
+
end
|
17
|
+
end # #included directives
|
18
|
+
|
19
|
+
#
|
20
|
+
# Class Methods
|
21
|
+
#
|
22
|
+
module ModelClassMethods
|
23
|
+
# This provides a modest increased defense against a dictionary attack if
|
24
|
+
# your db were ever compromised, but will invalidate existing passwords.
|
25
|
+
# See the README and the file config/initializers/site_keys.rb
|
26
|
+
#
|
27
|
+
# It may not be obvious, but if you set REST_AUTH_SITE_KEY to nil and
|
28
|
+
# REST_AUTH_DIGEST_STRETCHES to 1 you'll have backwards compatibility with
|
29
|
+
# older versions of restful-authentication.
|
30
|
+
def password_digest(password, salt)
|
31
|
+
digest = REST_AUTH_SITE_KEY
|
32
|
+
REST_AUTH_DIGEST_STRETCHES.times do
|
33
|
+
digest = secure_digest(digest, salt, password, REST_AUTH_SITE_KEY)
|
34
|
+
end
|
35
|
+
digest
|
36
|
+
end
|
37
|
+
end # class methods
|
38
|
+
|
39
|
+
#
|
40
|
+
# Instance Methods
|
41
|
+
#
|
42
|
+
module ModelInstanceMethods
|
43
|
+
|
44
|
+
# Encrypts the password with the user salt
|
45
|
+
def encrypt(password)
|
46
|
+
self.class.password_digest(password, salt)
|
47
|
+
end
|
48
|
+
|
49
|
+
def authenticated?(password)
|
50
|
+
crypted_password == encrypt(password)
|
51
|
+
end
|
52
|
+
|
53
|
+
# before filter
|
54
|
+
def encrypt_password
|
55
|
+
return if password.blank?
|
56
|
+
self.salt = self.class.make_token if new_record?
|
57
|
+
self.crypted_password = encrypt(password)
|
58
|
+
end
|
59
|
+
def password_required?
|
60
|
+
crypted_password.blank? || !password.blank?
|
61
|
+
end
|
62
|
+
end # instance methods
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Authorization
|
2
|
+
def self.included(recipient)
|
3
|
+
recipient.extend(ModelClassMethods)
|
4
|
+
recipient.class_eval do
|
5
|
+
include ModelInstanceMethods
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module ModelClassMethods
|
10
|
+
end # class methods
|
11
|
+
|
12
|
+
module ModelInstanceMethods
|
13
|
+
end # instance methods
|
14
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Authorization
|
2
|
+
module AasmRoles
|
3
|
+
unless Object.constants.include? "STATEFUL_ROLES_CONSTANTS_DEFINED"
|
4
|
+
STATEFUL_ROLES_CONSTANTS_DEFINED = true # sorry for the C idiom
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.included( recipient )
|
8
|
+
recipient.extend( StatefulRolesClassMethods )
|
9
|
+
recipient.class_eval do
|
10
|
+
include StatefulRolesInstanceMethods
|
11
|
+
include AASM
|
12
|
+
aasm_column :state
|
13
|
+
aasm_initial_state :pending
|
14
|
+
aasm_state :passive
|
15
|
+
aasm_state :pending, :enter => :make_activation_code
|
16
|
+
aasm_state :active, :enter => :do_activate
|
17
|
+
aasm_state :suspended
|
18
|
+
aasm_state :deleted, :enter => :do_delete
|
19
|
+
|
20
|
+
aasm_event :register do
|
21
|
+
transitions :from => :passive, :to => :pending, :guard => Proc.new {|u| !(u.crypted_password.blank? && u.password.blank?) }
|
22
|
+
end
|
23
|
+
|
24
|
+
aasm_event :activate do
|
25
|
+
transitions :from => :pending, :to => :active
|
26
|
+
end
|
27
|
+
|
28
|
+
aasm_event :suspend do
|
29
|
+
transitions :from => [:passive, :pending, :active], :to => :suspended
|
30
|
+
end
|
31
|
+
|
32
|
+
aasm_event :delete do
|
33
|
+
transitions :from => [:passive, :pending, :active, :suspended], :to => :deleted
|
34
|
+
end
|
35
|
+
|
36
|
+
aasm_event :unsuspend do
|
37
|
+
transitions :from => :suspended, :to => :active, :guard => Proc.new {|u| !u.activated_at.blank? }
|
38
|
+
transitions :from => :suspended, :to => :pending, :guard => Proc.new {|u| !u.activation_code.blank? }
|
39
|
+
transitions :from => :suspended, :to => :passive
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
module StatefulRolesClassMethods
|
45
|
+
end # class methods
|
46
|
+
|
47
|
+
module StatefulRolesInstanceMethods
|
48
|
+
# Returns true if the user has just been activated.
|
49
|
+
def recently_activated?
|
50
|
+
@activated
|
51
|
+
end
|
52
|
+
|
53
|
+
def do_delete
|
54
|
+
self.deleted_at = Time.now.utc
|
55
|
+
end
|
56
|
+
|
57
|
+
def do_activate
|
58
|
+
@activated = true
|
59
|
+
self.activated_at = Time.now.utc
|
60
|
+
self.deleted_at = self.activation_code = nil
|
61
|
+
end
|
62
|
+
end # instance methods
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Authorization
|
2
|
+
module StatefulRoles
|
3
|
+
unless Object.constants.include? "STATEFUL_ROLES_CONSTANTS_DEFINED"
|
4
|
+
STATEFUL_ROLES_CONSTANTS_DEFINED = true # sorry for the C idiom
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.included( recipient )
|
8
|
+
recipient.extend( StatefulRolesClassMethods )
|
9
|
+
recipient.class_eval do
|
10
|
+
include StatefulRolesInstanceMethods
|
11
|
+
|
12
|
+
acts_as_state_machine :initial => :pending
|
13
|
+
state :passive
|
14
|
+
state :pending, :enter => :make_activation_code
|
15
|
+
state :active, :enter => :do_activate
|
16
|
+
state :suspended
|
17
|
+
state :deleted, :enter => :do_delete
|
18
|
+
|
19
|
+
event :register do
|
20
|
+
transitions :from => :passive, :to => :pending, :guard => Proc.new {|u| !(u.crypted_password.blank? && u.password.blank?) }
|
21
|
+
end
|
22
|
+
|
23
|
+
event :activate do
|
24
|
+
transitions :from => :pending, :to => :active
|
25
|
+
end
|
26
|
+
|
27
|
+
event :suspend do
|
28
|
+
transitions :from => [:passive, :pending, :active], :to => :suspended
|
29
|
+
end
|
30
|
+
|
31
|
+
event :delete do
|
32
|
+
transitions :from => [:passive, :pending, :active, :suspended], :to => :deleted
|
33
|
+
end
|
34
|
+
|
35
|
+
event :unsuspend do
|
36
|
+
transitions :from => :suspended, :to => :active, :guard => Proc.new {|u| !u.activated_at.blank? }
|
37
|
+
transitions :from => :suspended, :to => :pending, :guard => Proc.new {|u| !u.activation_code.blank? }
|
38
|
+
transitions :from => :suspended, :to => :passive
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
module StatefulRolesClassMethods
|
44
|
+
end # class methods
|
45
|
+
|
46
|
+
module StatefulRolesInstanceMethods
|
47
|
+
# Returns true if the user has just been activated.
|
48
|
+
def recently_activated?
|
49
|
+
@activated
|
50
|
+
end
|
51
|
+
|
52
|
+
def do_delete
|
53
|
+
self.deleted_at = Time.now.utc
|
54
|
+
end
|
55
|
+
|
56
|
+
def do_activate
|
57
|
+
@activated = true
|
58
|
+
self.activated_at = Time.now.utc
|
59
|
+
self.deleted_at = self.activation_code = nil
|
60
|
+
end
|
61
|
+
end # instance methods
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Trustification
|
2
|
+
def self.included(recipient)
|
3
|
+
recipient.extend(ModelClassMethods)
|
4
|
+
recipient.class_eval do
|
5
|
+
include ModelInstanceMethods
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module ModelClassMethods
|
10
|
+
end # class methods
|
11
|
+
|
12
|
+
module ModelInstanceMethods
|
13
|
+
end # instance methods
|
14
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Trustification
|
2
|
+
module EmailValidation
|
3
|
+
unless Object.constants.include? "CONSTANTS_DEFINED"
|
4
|
+
CONSTANTS_DEFINED = true # sorry for the C idiom
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.included(recipient)
|
8
|
+
recipient.extend(ClassMethods)
|
9
|
+
recipient.class_eval do
|
10
|
+
include InstanceMethods
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module ClassMethods
|
15
|
+
end # class methods
|
16
|
+
|
17
|
+
module InstanceMethods
|
18
|
+
end # instance methods
|
19
|
+
end
|
20
|
+
end
|
data/rails/init.rb
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "lib", "authorization")
|
2
|
+
require File.join(File.dirname(__FILE__), "..", "lib", "authorization", "aasm_roles")
|
3
|
+
require File.join(File.dirname(__FILE__), "..", "lib", "authorization", "stateful_roles")
|
4
|
+
require File.join(File.dirname(__FILE__), "..", "lib", "authentication")
|
5
|
+
require File.join(File.dirname(__FILE__), "..", "lib", "authentication", "by_password")
|
6
|
+
require File.join(File.dirname(__FILE__), "..", "lib", "authentication", "by_cookie_token")
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: caleb-restful-authentication
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- RailsJedi
|
8
|
+
- Rick Olson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2008-07-04 00:00:00 -07:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rails
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.1.0
|
24
|
+
version:
|
25
|
+
description: This widely-used plugin provides a foundation for securely managing user.
|
26
|
+
email: railsjedi@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.textile
|
33
|
+
files:
|
34
|
+
- CHANGELOG
|
35
|
+
- README.textile
|
36
|
+
- Rakefile
|
37
|
+
- TODO
|
38
|
+
- generators/authenticated/authenticated_generator.rb
|
39
|
+
- generators/authenticated/lib/insert_routes.rb
|
40
|
+
- generators/authenticated/templates/_model_partial.html.erb
|
41
|
+
- generators/authenticated/templates/activation.erb
|
42
|
+
- generators/authenticated/templates/authenticated_system.rb
|
43
|
+
- generators/authenticated/templates/authenticated_test_helper.rb
|
44
|
+
- generators/authenticated/templates/controller.rb
|
45
|
+
- generators/authenticated/templates/helper.rb
|
46
|
+
- generators/authenticated/templates/login.html.erb
|
47
|
+
- generators/authenticated/templates/mailer.rb
|
48
|
+
- generators/authenticated/templates/migration.rb
|
49
|
+
- generators/authenticated/templates/model.rb
|
50
|
+
- generators/authenticated/templates/model_controller.rb
|
51
|
+
- generators/authenticated/templates/model_helper.rb
|
52
|
+
- generators/authenticated/templates/model_helper_spec.rb
|
53
|
+
- generators/authenticated/templates/observer.rb
|
54
|
+
- generators/authenticated/templates/signup.html.erb
|
55
|
+
- generators/authenticated/templates/signup_notification.erb
|
56
|
+
- generators/authenticated/templates/site_keys.rb
|
57
|
+
- generators/authenticated/templates/spec/controllers/access_control_spec.rb
|
58
|
+
- generators/authenticated/templates/spec/controllers/authenticated_system_spec.rb
|
59
|
+
- generators/authenticated/templates/spec/controllers/sessions_controller_spec.rb
|
60
|
+
- generators/authenticated/templates/spec/controllers/users_controller_spec.rb
|
61
|
+
- generators/authenticated/templates/spec/fixtures/users.yml
|
62
|
+
- generators/authenticated/templates/spec/helpers/users_helper_spec.rb
|
63
|
+
- generators/authenticated/templates/spec/models/user_spec.rb
|
64
|
+
- generators/authenticated/templates/stories/rest_auth_stories.rb
|
65
|
+
- generators/authenticated/templates/stories/rest_auth_stories_helper.rb
|
66
|
+
- generators/authenticated/templates/stories/steps/ra_navigation_steps.rb
|
67
|
+
- generators/authenticated/templates/stories/steps/ra_resource_steps.rb
|
68
|
+
- generators/authenticated/templates/stories/steps/ra_response_steps.rb
|
69
|
+
- generators/authenticated/templates/stories/steps/user_steps.rb
|
70
|
+
- generators/authenticated/templates/stories/users/accounts.story
|
71
|
+
- generators/authenticated/templates/stories/users/sessions.story
|
72
|
+
- generators/authenticated/templates/test/functional_test.rb
|
73
|
+
- generators/authenticated/templates/test/mailer_test.rb
|
74
|
+
- generators/authenticated/templates/test/model_functional_test.rb
|
75
|
+
- generators/authenticated/templates/test/unit_test.rb
|
76
|
+
- generators/authenticated/USAGE
|
77
|
+
- init.rb
|
78
|
+
- lib/authentication/by_cookie_token.rb
|
79
|
+
- lib/authentication/by_password.rb
|
80
|
+
- lib/authentication.rb
|
81
|
+
- lib/authorization/aasm_roles.rb
|
82
|
+
- lib/authorization/stateful_roles.rb
|
83
|
+
- lib/authorization.rb
|
84
|
+
- lib/trustification/email_validation.rb
|
85
|
+
- lib/trustification.rb
|
86
|
+
- rails/init.rb
|
87
|
+
has_rdoc: true
|
88
|
+
homepage: http://github.com/technoweenie/restful-authentication
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options:
|
91
|
+
- --main
|
92
|
+
- README.textile
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: "0"
|
100
|
+
version:
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: "0"
|
106
|
+
version:
|
107
|
+
requirements: []
|
108
|
+
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 1.2.0
|
111
|
+
signing_key:
|
112
|
+
specification_version: 2
|
113
|
+
summary: Generates code for user login and authentication
|
114
|
+
test_files: []
|
115
|
+
|