jcnetdev-restful-authentication 1.0.20080704

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/CHANGELOG +68 -0
  2. data/README +176 -0
  3. data/Rakefile +22 -0
  4. data/TODO +15 -0
  5. data/generators/authenticated/USAGE +1 -0
  6. data/generators/authenticated/authenticated_generator.rb +478 -0
  7. data/generators/authenticated/lib/insert_routes.rb +50 -0
  8. data/generators/authenticated/templates/_model_partial.html.erb +8 -0
  9. data/generators/authenticated/templates/activation.html.erb +3 -0
  10. data/generators/authenticated/templates/authenticated_system.rb +187 -0
  11. data/generators/authenticated/templates/authenticated_test_helper.rb +22 -0
  12. data/generators/authenticated/templates/controller.rb +43 -0
  13. data/generators/authenticated/templates/helper.rb +2 -0
  14. data/generators/authenticated/templates/login.html.erb +16 -0
  15. data/generators/authenticated/templates/mailer.rb +25 -0
  16. data/generators/authenticated/templates/migration.rb +26 -0
  17. data/generators/authenticated/templates/model.rb +69 -0
  18. data/generators/authenticated/templates/model_controller.rb +86 -0
  19. data/generators/authenticated/templates/model_helper.rb +93 -0
  20. data/generators/authenticated/templates/model_helper_spec.rb +158 -0
  21. data/generators/authenticated/templates/observer.rb +11 -0
  22. data/generators/authenticated/templates/signup.html.erb +19 -0
  23. data/generators/authenticated/templates/signup_notification.html.erb +8 -0
  24. data/generators/authenticated/templates/site_keys.rb +38 -0
  25. data/generators/authenticated/templates/spec/controllers/access_control_spec.rb +90 -0
  26. data/generators/authenticated/templates/spec/controllers/authenticated_system_spec.rb +101 -0
  27. data/generators/authenticated/templates/spec/controllers/sessions_controller_spec.rb +139 -0
  28. data/generators/authenticated/templates/spec/controllers/users_controller_spec.rb +198 -0
  29. data/generators/authenticated/templates/spec/fixtures/users.yml +60 -0
  30. data/generators/authenticated/templates/spec/helpers/users_helper_spec.rb +141 -0
  31. data/generators/authenticated/templates/spec/models/user_spec.rb +290 -0
  32. data/generators/authenticated/templates/stories/rest_auth_stories.rb +22 -0
  33. data/generators/authenticated/templates/stories/rest_auth_stories_helper.rb +81 -0
  34. data/generators/authenticated/templates/stories/steps/ra_navigation_steps.rb +49 -0
  35. data/generators/authenticated/templates/stories/steps/ra_resource_steps.rb +179 -0
  36. data/generators/authenticated/templates/stories/steps/ra_response_steps.rb +171 -0
  37. data/generators/authenticated/templates/stories/steps/user_steps.rb +153 -0
  38. data/generators/authenticated/templates/stories/users/accounts.story +186 -0
  39. data/generators/authenticated/templates/stories/users/sessions.story +134 -0
  40. data/generators/authenticated/templates/test/functional_test.rb +88 -0
  41. data/generators/authenticated/templates/test/mailer_test.rb +31 -0
  42. data/generators/authenticated/templates/test/model_functional_test.rb +99 -0
  43. data/generators/authenticated/templates/test/unit_test.rb +164 -0
  44. data/init.rb +1 -0
  45. data/lib/authentication.rb +43 -0
  46. data/lib/authentication/by_cookie_token.rb +85 -0
  47. data/lib/authentication/by_password.rb +65 -0
  48. data/lib/authorization.rb +15 -0
  49. data/lib/authorization/aasm_roles.rb +64 -0
  50. data/lib/authorization/stateful_roles.rb +63 -0
  51. data/lib/trustification.rb +15 -0
  52. data/lib/trustification/email_validation.rb +20 -0
  53. data/rails/init.rb +3 -0
  54. data/restful-authentication.gemspec +74 -0
  55. metadata +116 -0
@@ -0,0 +1,65 @@
1
+ module Authentication
2
+ module ByPassword
3
+
4
+ # Stuff directives into including module
5
+ def self.included( recipient )
6
+ recipient.extend( ModelClassMethods )
7
+ recipient.class_eval do
8
+ include ModelInstanceMethods
9
+
10
+ # Virtual attribute for the unencrypted password
11
+ attr_accessor :password
12
+ validates_presence_of :password, :if => :password_required?
13
+ validates_presence_of :password_confirmation, :if => :password_required?
14
+ validates_confirmation_of :password, :if => :password_required?
15
+ validates_length_of :password, :within => 6..40, :if => :password_required?
16
+ before_save :encrypt_password
17
+ end
18
+ end # #included directives
19
+
20
+ #
21
+ # Class Methods
22
+ #
23
+ module ModelClassMethods
24
+ # This provides a modest increased defense against a dictionary attack if
25
+ # your db were ever compromised, but will invalidate existing passwords.
26
+ # See the README and the file config/initializers/site_keys.rb
27
+ #
28
+ # It may not be obvious, but if you set REST_AUTH_SITE_KEY to nil and
29
+ # REST_AUTH_DIGEST_STRETCHES to 1 you'll have backwards compatibility with
30
+ # older versions of restful-authentication.
31
+ def password_digest(password, salt)
32
+ digest = REST_AUTH_SITE_KEY
33
+ REST_AUTH_DIGEST_STRETCHES.times do
34
+ digest = secure_digest(digest, salt, password, REST_AUTH_SITE_KEY)
35
+ end
36
+ digest
37
+ end
38
+ end # class methods
39
+
40
+ #
41
+ # Instance Methods
42
+ #
43
+ module ModelInstanceMethods
44
+
45
+ # Encrypts the password with the user salt
46
+ def encrypt(password)
47
+ self.class.password_digest(password, salt)
48
+ end
49
+
50
+ def authenticated?(password)
51
+ crypted_password == encrypt(password)
52
+ end
53
+
54
+ # before filter
55
+ def encrypt_password
56
+ return if password.blank?
57
+ self.salt = self.class.make_token if new_record?
58
+ self.crypted_password = encrypt(password)
59
+ end
60
+ def password_required?
61
+ crypted_password.blank? || !password.blank?
62
+ end
63
+ end # instance methods
64
+ end
65
+ end
@@ -0,0 +1,15 @@
1
+ module Authorization
2
+
3
+ def self.included( recipient )
4
+ recipient.extend( ModelClassMethods )
5
+ recipient.class_eval do
6
+ include ModelInstanceMethods
7
+ end
8
+ end
9
+
10
+ module ModelClassMethods
11
+ end # class methods
12
+
13
+ module ModelInstanceMethods
14
+ end # instance methods
15
+ 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 = 'yup' # 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 :initial => :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
+
46
+ end # class methods
47
+
48
+ module StatefulRolesInstanceMethods
49
+ # Returns true if the user has just been activated.
50
+ def recently_activated?
51
+ @activated
52
+ end
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 = 'yup' # 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
+
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
+ 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,15 @@
1
+ module Trustification
2
+
3
+ def self.included( recipient )
4
+ recipient.extend( ModelClassMethods )
5
+ recipient.class_eval do
6
+ include ModelInstanceMethods
7
+ end
8
+ end
9
+
10
+ module ModelClassMethods
11
+ end # class methods
12
+
13
+ module ModelInstanceMethods
14
+ end # instance methods
15
+ end
@@ -0,0 +1,20 @@
1
+ module Trustification
2
+ module EmailValidation
3
+ unless Object.constants.include? "CONSTANTS_DEFINED"
4
+ CONSTANTS_DEFINED = 'yup' # 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,3 @@
1
+ require 'authentication'
2
+ require 'authentication/by_password'
3
+ require 'authentication/by_cookie_token'
@@ -0,0 +1,74 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'restful-authentication'
3
+ s.version = '1.0.20080704'
4
+ s.date = '2008-07-04'
5
+
6
+ s.summary = "Generates code for user login and authentication"
7
+ s.description = "This widely-used plugin provides a foundation for securely managing user."
8
+
9
+ s.authors = ['RailsJedi', 'Rick Olson']
10
+ s.email = 'railsjedi@gmail.com'
11
+ s.homepage = 'http://github.com/jcnetdev/restful-authentication'
12
+
13
+ s.has_rdoc = true
14
+ s.rdoc_options = ["--main", "README"]
15
+ s.extra_rdoc_files = ["README"]
16
+
17
+ s.add_dependency 'rails', ['>= 2.1']
18
+
19
+ s.files = ["CHANGELOG",
20
+ "README",
21
+ "Rakefile",
22
+ "TODO",
23
+ "generators/authenticated/authenticated_generator.rb",
24
+ "generators/authenticated/lib/insert_routes.rb",
25
+ "generators/authenticated/templates/_model_partial.html.erb",
26
+ "generators/authenticated/templates/activation.html.erb",
27
+ "generators/authenticated/templates/authenticated_system.rb",
28
+ "generators/authenticated/templates/authenticated_test_helper.rb",
29
+ "generators/authenticated/templates/controller.rb",
30
+ "generators/authenticated/templates/helper.rb",
31
+ "generators/authenticated/templates/login.html.erb",
32
+ "generators/authenticated/templates/mailer.rb",
33
+ "generators/authenticated/templates/migration.rb",
34
+ "generators/authenticated/templates/model.rb",
35
+ "generators/authenticated/templates/model_controller.rb",
36
+ "generators/authenticated/templates/model_helper.rb",
37
+ "generators/authenticated/templates/model_helper_spec.rb",
38
+ "generators/authenticated/templates/observer.rb",
39
+ "generators/authenticated/templates/signup.html.erb",
40
+ "generators/authenticated/templates/signup_notification.html.erb",
41
+ "generators/authenticated/templates/site_keys.rb",
42
+ "generators/authenticated/templates/spec/controllers/access_control_spec.rb",
43
+ "generators/authenticated/templates/spec/controllers/authenticated_system_spec.rb",
44
+ "generators/authenticated/templates/spec/controllers/sessions_controller_spec.rb",
45
+ "generators/authenticated/templates/spec/controllers/users_controller_spec.rb",
46
+ "generators/authenticated/templates/spec/fixtures/users.yml",
47
+ "generators/authenticated/templates/spec/helpers/users_helper_spec.rb",
48
+ "generators/authenticated/templates/spec/models/user_spec.rb",
49
+ "generators/authenticated/templates/stories/rest_auth_stories.rb",
50
+ "generators/authenticated/templates/stories/rest_auth_stories_helper.rb",
51
+ "generators/authenticated/templates/stories/steps/ra_navigation_steps.rb",
52
+ "generators/authenticated/templates/stories/steps/ra_resource_steps.rb",
53
+ "generators/authenticated/templates/stories/steps/ra_response_steps.rb",
54
+ "generators/authenticated/templates/stories/steps/user_steps.rb",
55
+ "generators/authenticated/templates/stories/users/accounts.story",
56
+ "generators/authenticated/templates/stories/users/sessions.story",
57
+ "generators/authenticated/templates/test/functional_test.rb",
58
+ "generators/authenticated/templates/test/mailer_test.rb",
59
+ "generators/authenticated/templates/test/model_functional_test.rb",
60
+ "generators/authenticated/templates/test/unit_test.rb",
61
+ "generators/authenticated/USAGE",
62
+ "init.rb",
63
+ "lib/authentication/by_cookie_token.rb",
64
+ "lib/authentication/by_password.rb",
65
+ "lib/authentication.rb",
66
+ "lib/authorization/aasm_roles.rb",
67
+ "lib/authorization/stateful_roles.rb",
68
+ "lib/authorization.rb",
69
+ "lib/trustification/email_validation.rb",
70
+ "lib/trustification.rb",
71
+ "rails/init.rb",
72
+ "restful-authentication.gemspec"]
73
+
74
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jcnetdev-restful-authentication
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.20080704
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"
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
33
+ files:
34
+ - CHANGELOG
35
+ - README
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.html.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.html.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
+ - restful-authentication.gemspec
88
+ has_rdoc: true
89
+ homepage: http://github.com/jcnetdev/restful-authentication
90
+ post_install_message:
91
+ rdoc_options:
92
+ - --main
93
+ - README
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: "0"
101
+ version:
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: "0"
107
+ version:
108
+ requirements: []
109
+
110
+ rubyforge_project:
111
+ rubygems_version: 1.2.0
112
+ signing_key:
113
+ specification_version: 2
114
+ summary: Generates code for user login and authentication
115
+ test_files: []
116
+