refinerycms-authentication 0.9.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/app/controllers/admin/users_controller.rb +90 -0
  2. data/app/controllers/passwords_controller.rb +43 -0
  3. data/app/controllers/registrations_controller.rb +67 -0
  4. data/app/controllers/sessions_controller.rb +23 -0
  5. data/app/helpers/sessions_helper.rb +2 -0
  6. data/app/helpers/users_helper.rb +2 -0
  7. data/app/mailers/user_mailer.rb +20 -0
  8. data/app/models/role.rb +16 -0
  9. data/app/models/roles_users.rb +6 -0
  10. data/app/models/user.rb +60 -0
  11. data/app/models/user_plugin.rb +5 -0
  12. data/app/views/admin/users/_form.html.erb +92 -0
  13. data/app/views/admin/users/_user.html.erb +19 -0
  14. data/app/views/admin/users/_users.html.erb +4 -0
  15. data/app/views/admin/users/edit.html.erb +1 -0
  16. data/app/views/admin/users/index.html.erb +12 -0
  17. data/app/views/admin/users/new.html.erb +1 -0
  18. data/app/views/layouts/login.html.erb +21 -0
  19. data/app/views/passwords/edit.html.erb +31 -0
  20. data/app/views/passwords/new.html.erb +18 -0
  21. data/app/views/registrations/new.html.erb +41 -0
  22. data/app/views/sessions/new.html.erb +29 -0
  23. data/app/views/user_mailer/reset_notification.html.erb +12 -0
  24. data/app/views/user_mailer/reset_notification.text.plain.erb +7 -0
  25. data/config/locales/cs.yml +75 -0
  26. data/config/locales/da.yml +72 -0
  27. data/config/locales/de.yml +72 -0
  28. data/config/locales/el.yml +72 -0
  29. data/config/locales/en.yml +72 -0
  30. data/config/locales/es.yml +100 -0
  31. data/config/locales/fr.yml +72 -0
  32. data/config/locales/it.yml +97 -0
  33. data/config/locales/lolcat.yml +55 -0
  34. data/config/locales/lt.yml +55 -0
  35. data/config/locales/lv.yml +72 -0
  36. data/config/locales/nb.yml +72 -0
  37. data/config/locales/nl.yml +70 -0
  38. data/config/locales/pl.yml +100 -0
  39. data/config/locales/pt-BR.yml +68 -0
  40. data/config/locales/rs.yml +72 -0
  41. data/config/locales/ru.yml +97 -0
  42. data/config/locales/sl.yml +61 -0
  43. data/config/locales/sv.yml +64 -0
  44. data/config/locales/vi.yml +72 -0
  45. data/config/locales/zh-CN.yml +72 -0
  46. data/config/locales/zh-TW.yml +72 -0
  47. data/config/routes.rb +31 -0
  48. data/db/migrate/20100913234705_create_refinerycms_authentication_schema.rb +43 -0
  49. data/db/migrate/20100929035252_add_missing_indexes_to_roles_users.rb +11 -0
  50. data/db/migrate/20101206013505_change_to_devise_users_table.rb +27 -0
  51. data/db/migrate/20110106184757_add_remember_created_at_to_users.rb +9 -0
  52. data/features/lost_password.feature +49 -0
  53. data/features/manage_users.feature +61 -0
  54. data/features/step_definitions/lost_password.rb +8 -0
  55. data/features/step_definitions/user_steps.rb +36 -0
  56. data/features/support/factories.rb +18 -0
  57. data/features/support/paths.rb +24 -0
  58. data/lib/authenticated_system.rb +29 -0
  59. data/lib/gemspec.rb +34 -0
  60. data/lib/generators/refinerycms_authentication_generator.rb +8 -0
  61. data/lib/refinerycms-authentication.rb +47 -0
  62. data/license.md +21 -0
  63. data/readme.md +17 -0
  64. data/refinerycms-authentication.gemspec +112 -0
  65. data/spec/models/user_spec.rb +159 -0
  66. metadata +144 -0
data/readme.md ADDED
@@ -0,0 +1,17 @@
1
+ # Authentication
2
+
3
+ ## About
4
+
5
+ At the heart of Refinery's user management is the authentication plugin located in ``vendor/plugins/authentication``
6
+
7
+ What this really is is just a standard [authlogic](http://github.com/binarylogic/authlogic) install extended with a few extra features like "I forgot my password" and hooked directly into the heart of Refinery's plugin system.
8
+
9
+ Authlogic allows you to easily integrate with other systems too. So you could be logged in into another system using authlogic and easily stay logged in between the two systems without having to login twice.
10
+
11
+ ## Adding New Users
12
+
13
+ New users can be easily added by going to the 'Users' area admin and clicking on "Add new user".
14
+
15
+ ## Limiting and Granting Access
16
+
17
+ Each user has a set of plugins they're allowed to see. You can control which plugins each user can see by checking and unchecking the checkboxes next to the plugin name when editing or adding a new user.
@@ -0,0 +1,112 @@
1
+ # DO NOT EDIT THIS FILE DIRECTLY! Instead, use lib/gemspec.rb to generate it.
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{refinerycms-authentication}
5
+ s.version = %q{0.9.9.1}
6
+ s.summary = %q{Authentication engine for Refinery CMS}
7
+ s.description = %q{The default authentication engine for Refinery CMS}
8
+ s.date = %q{2011-02-15}
9
+ s.email = %q{info@refinerycms.com}
10
+ s.homepage = %q{http://refinerycms.com}
11
+ s.rubyforge_project = %q{refinerycms}
12
+ s.authors = ['Resolve Digital', 'Philip Arndt', 'David Jones', 'Steven Heidel']
13
+ s.license = %q{MIT}
14
+ s.require_paths = %w(lib)
15
+ s.executables = %w()
16
+
17
+ s.add_dependency 'refinerycms-core', '~> 0.9.9.1'
18
+ s.add_dependency 'devise', '~> 1.1'
19
+
20
+ s.files = [
21
+ 'app',
22
+ 'app/controllers',
23
+ 'app/controllers/admin',
24
+ 'app/controllers/admin/users_controller.rb',
25
+ 'app/controllers/passwords_controller.rb',
26
+ 'app/controllers/registrations_controller.rb',
27
+ 'app/controllers/sessions_controller.rb',
28
+ 'app/helpers',
29
+ 'app/helpers/sessions_helper.rb',
30
+ 'app/helpers/users_helper.rb',
31
+ 'app/mailers',
32
+ 'app/mailers/user_mailer.rb',
33
+ 'app/models',
34
+ 'app/models/role.rb',
35
+ 'app/models/roles_users.rb',
36
+ 'app/models/user.rb',
37
+ 'app/models/user_plugin.rb',
38
+ 'app/views',
39
+ 'app/views/admin',
40
+ 'app/views/admin/users',
41
+ 'app/views/admin/users/_form.html.erb',
42
+ 'app/views/admin/users/_user.html.erb',
43
+ 'app/views/admin/users/_users.html.erb',
44
+ 'app/views/admin/users/edit.html.erb',
45
+ 'app/views/admin/users/index.html.erb',
46
+ 'app/views/admin/users/new.html.erb',
47
+ 'app/views/layouts',
48
+ 'app/views/layouts/login.html.erb',
49
+ 'app/views/passwords',
50
+ 'app/views/passwords/edit.html.erb',
51
+ 'app/views/passwords/new.html.erb',
52
+ 'app/views/registrations',
53
+ 'app/views/registrations/new.html.erb',
54
+ 'app/views/sessions',
55
+ 'app/views/sessions/new.html.erb',
56
+ 'app/views/user_mailer',
57
+ 'app/views/user_mailer/reset_notification.html.erb',
58
+ 'app/views/user_mailer/reset_notification.text.plain.erb',
59
+ 'config',
60
+ 'config/locales',
61
+ 'config/locales/cs.yml',
62
+ 'config/locales/da.yml',
63
+ 'config/locales/de.yml',
64
+ 'config/locales/el.yml',
65
+ 'config/locales/en.yml',
66
+ 'config/locales/es.yml',
67
+ 'config/locales/fr.yml',
68
+ 'config/locales/it.yml',
69
+ 'config/locales/lolcat.yml',
70
+ 'config/locales/lt.yml',
71
+ 'config/locales/lv.yml',
72
+ 'config/locales/nb.yml',
73
+ 'config/locales/nl.yml',
74
+ 'config/locales/pl.yml',
75
+ 'config/locales/pt-BR.yml',
76
+ 'config/locales/rs.yml',
77
+ 'config/locales/ru.yml',
78
+ 'config/locales/sl.yml',
79
+ 'config/locales/sv.yml',
80
+ 'config/locales/vi.yml',
81
+ 'config/locales/zh-CN.yml',
82
+ 'config/locales/zh-TW.yml',
83
+ 'config/routes.rb',
84
+ 'db',
85
+ 'db/migrate',
86
+ 'db/migrate/20100913234705_create_refinerycms_authentication_schema.rb',
87
+ 'db/migrate/20100929035252_add_missing_indexes_to_roles_users.rb',
88
+ 'db/migrate/20101206013505_change_to_devise_users_table.rb',
89
+ 'db/migrate/20110106184757_add_remember_created_at_to_users.rb',
90
+ 'features',
91
+ 'features/lost_password.feature',
92
+ 'features/manage_users.feature',
93
+ 'features/step_definitions',
94
+ 'features/step_definitions/lost_password.rb',
95
+ 'features/step_definitions/user_steps.rb',
96
+ 'features/support',
97
+ 'features/support/factories.rb',
98
+ 'features/support/paths.rb',
99
+ 'lib',
100
+ 'lib/authenticated_system.rb',
101
+ 'lib/gemspec.rb',
102
+ 'lib/generators',
103
+ 'lib/generators/refinerycms_authentication_generator.rb',
104
+ 'lib/refinerycms-authentication.rb',
105
+ 'license.md',
106
+ 'readme.md',
107
+ 'refinerycms-authentication.gemspec',
108
+ 'spec',
109
+ 'spec/models',
110
+ 'spec/models/user_spec.rb'
111
+ ]
112
+ end
@@ -0,0 +1,159 @@
1
+ require 'spec_helper'
2
+
3
+ Dir[File.expand_path('../../../features/support/factories.rb', __FILE__)].each {|f| require f}
4
+
5
+ describe User do
6
+ context "Roles" do
7
+ context "add_role" do
8
+ it "raises Exception when Role object is passed" do
9
+ user = Factory(:user)
10
+ lambda{ user.add_role(Role.new)}.should raise_exception
11
+ end
12
+
13
+ it "adds a Role to the User when role not yet assigned to User" do
14
+ user = Factory(:user)
15
+ lambda {
16
+ user.add_role(:new_role)
17
+ }.should change(user.roles, :count).by(1)
18
+ user.roles.collect(&:title).should include("NewRole")
19
+ end
20
+
21
+ it "does not add a Role to the User when this Role is already assigned to User" do
22
+ user = Factory(:refinery_user)
23
+ lambda {
24
+ user.add_role(:refinery)
25
+ }.should_not change(user.roles, :count).by(1)
26
+ user.roles.collect(&:title).should include("Refinery")
27
+ end
28
+ end
29
+
30
+ context "has_role" do
31
+ it "raises Exception when Role object is passed" do
32
+ user = Factory(:user)
33
+ lambda{ user.has_role?(Role.new)}.should raise_exception
34
+ end
35
+
36
+ it "returns the true if user has Role" do
37
+ user = Factory(:refinery_user)
38
+ user.has_role?(:refinery).should be_true
39
+ end
40
+
41
+ it "returns false if user hasn't the Role" do
42
+ user = Factory(:refinery_user)
43
+ user.has_role?(:refinery_fail).should be_false
44
+ end
45
+ end
46
+
47
+ describe "role association" do
48
+ it "have a roles attribute" do
49
+ Factory(:user).should respond_to(:roles)
50
+ end
51
+ end
52
+ end
53
+
54
+ context "validations" do
55
+ # email and password validations are done by including devises validatable
56
+ # module so those validations are not tested here
57
+ before(:each) do
58
+ @attr = {
59
+ :username => "RefineryCMS",
60
+ :email => "refinery@cms.com",
61
+ :password => "123456",
62
+ :password_confirmation => "123456"
63
+ }
64
+ end
65
+
66
+ it "requires username" do
67
+ User.new(@attr.merge(:username => "")).should_not be_valid
68
+ end
69
+
70
+ it "rejects duplicate usernames" do
71
+ User.create!(@attr)
72
+ User.new(@attr.merge(:email => "another@email.com")).should_not be_valid
73
+ end
74
+ end
75
+
76
+ describe ".find_for_database_authentication" do
77
+ it "finds user either by username or email" do
78
+ user = Factory(:user)
79
+ User.find_for_database_authentication(:login => user.username).should == user
80
+ User.find_for_database_authentication(:login => user.email).should == user
81
+ end
82
+ end
83
+
84
+ describe "#can_delete?" do
85
+ before(:each) do
86
+ @user = Factory(:refinery_user)
87
+ @user_not_persisted = Factory.build(:refinery_user)
88
+ @super_user = Factory(:refinery_user)
89
+ @super_user.add_role(:superuser)
90
+ end
91
+
92
+ context "won't allow to delete" do
93
+ it "not persisted user record" do
94
+ @user.can_delete?(@user_not_persisted).should be_false
95
+ end
96
+
97
+ it "user with superuser role" do
98
+ @user.can_delete?(@super_user).should be_false
99
+ end
100
+
101
+ it "if user count with refinery role <= 1" do
102
+ Role[:refinery].users.delete(@user)
103
+ @super_user.can_delete?(@user).should be_false
104
+ end
105
+
106
+ it "user himself" do
107
+ @user.can_delete?(@user).should be_false
108
+ end
109
+ end
110
+
111
+ context "allow to delete" do
112
+ it "if all conditions return true" do
113
+ @super_user.can_delete?(@user).should be_true
114
+ end
115
+ end
116
+ end
117
+
118
+ describe "#plugins=" do
119
+ it "assigns plugins to user" do
120
+ user = Factory(:user)
121
+ plugin_list = ["refinery_one", "refinery_two", "refinery_three"]
122
+ user.plugins = plugin_list
123
+ user.plugins.collect { |p| p.name }.should == plugin_list
124
+ end
125
+ end
126
+
127
+ describe "#authorized_plugins" do
128
+ it "returns array of user and always allowd plugins" do
129
+ user = Factory(:user)
130
+ ["refinery_one", "refinery_two", "refinery_three"].each_with_index do |name, index|
131
+ user.plugins.create!(:name => name, :position => index)
132
+ end
133
+ user.authorized_plugins.should == user.plugins.collect { |p| p.name } | Refinery::Plugins.always_allowed.names
134
+ end
135
+ end
136
+
137
+ describe "plugins association" do
138
+ before(:each) do
139
+ @user = Factory(:user)
140
+ @plugin_list = ["refinery_one", "refinery_two", "refinery_three"]
141
+ @user.plugins = @plugin_list
142
+ end
143
+
144
+ it "have a plugins attribute" do
145
+ @user.should respond_to(:plugins)
146
+ end
147
+
148
+ it "returns plugins in ASC order" do
149
+ @user.plugins[0].name.should == @plugin_list[0]
150
+ @user.plugins[1].name.should == @plugin_list[1]
151
+ @user.plugins[2].name.should == @plugin_list[2]
152
+ end
153
+
154
+ it "deletes associated plugins" do
155
+ @user.destroy
156
+ UserPlugin.find_by_user_id(@user.id).should be_nil
157
+ end
158
+ end
159
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: refinerycms-authentication
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.9.9.1
6
+ platform: ruby
7
+ authors:
8
+ - Resolve Digital
9
+ - Philip Arndt
10
+ - David Jones
11
+ - Steven Heidel
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2011-02-15 00:00:00 +13:00
17
+ default_executable:
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: refinerycms-core
21
+ prerelease: false
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: 0.9.9.1
28
+ type: :runtime
29
+ version_requirements: *id001
30
+ - !ruby/object:Gem::Dependency
31
+ name: devise
32
+ prerelease: false
33
+ requirement: &id002 !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: "1.1"
39
+ type: :runtime
40
+ version_requirements: *id002
41
+ description: The default authentication engine for Refinery CMS
42
+ email: info@refinerycms.com
43
+ executables: []
44
+
45
+ extensions: []
46
+
47
+ extra_rdoc_files: []
48
+
49
+ files:
50
+ - app/controllers/admin/users_controller.rb
51
+ - app/controllers/passwords_controller.rb
52
+ - app/controllers/registrations_controller.rb
53
+ - app/controllers/sessions_controller.rb
54
+ - app/helpers/sessions_helper.rb
55
+ - app/helpers/users_helper.rb
56
+ - app/mailers/user_mailer.rb
57
+ - app/models/role.rb
58
+ - app/models/roles_users.rb
59
+ - app/models/user.rb
60
+ - app/models/user_plugin.rb
61
+ - app/views/admin/users/_form.html.erb
62
+ - app/views/admin/users/_user.html.erb
63
+ - app/views/admin/users/_users.html.erb
64
+ - app/views/admin/users/edit.html.erb
65
+ - app/views/admin/users/index.html.erb
66
+ - app/views/admin/users/new.html.erb
67
+ - app/views/layouts/login.html.erb
68
+ - app/views/passwords/edit.html.erb
69
+ - app/views/passwords/new.html.erb
70
+ - app/views/registrations/new.html.erb
71
+ - app/views/sessions/new.html.erb
72
+ - app/views/user_mailer/reset_notification.html.erb
73
+ - app/views/user_mailer/reset_notification.text.plain.erb
74
+ - config/locales/cs.yml
75
+ - config/locales/da.yml
76
+ - config/locales/de.yml
77
+ - config/locales/el.yml
78
+ - config/locales/en.yml
79
+ - config/locales/es.yml
80
+ - config/locales/fr.yml
81
+ - config/locales/it.yml
82
+ - config/locales/lolcat.yml
83
+ - config/locales/lt.yml
84
+ - config/locales/lv.yml
85
+ - config/locales/nb.yml
86
+ - config/locales/nl.yml
87
+ - config/locales/pl.yml
88
+ - config/locales/pt-BR.yml
89
+ - config/locales/rs.yml
90
+ - config/locales/ru.yml
91
+ - config/locales/sl.yml
92
+ - config/locales/sv.yml
93
+ - config/locales/vi.yml
94
+ - config/locales/zh-CN.yml
95
+ - config/locales/zh-TW.yml
96
+ - config/routes.rb
97
+ - db/migrate/20100913234705_create_refinerycms_authentication_schema.rb
98
+ - db/migrate/20100929035252_add_missing_indexes_to_roles_users.rb
99
+ - db/migrate/20101206013505_change_to_devise_users_table.rb
100
+ - db/migrate/20110106184757_add_remember_created_at_to_users.rb
101
+ - features/lost_password.feature
102
+ - features/manage_users.feature
103
+ - features/step_definitions/lost_password.rb
104
+ - features/step_definitions/user_steps.rb
105
+ - features/support/factories.rb
106
+ - features/support/paths.rb
107
+ - lib/authenticated_system.rb
108
+ - lib/gemspec.rb
109
+ - lib/generators/refinerycms_authentication_generator.rb
110
+ - lib/refinerycms-authentication.rb
111
+ - license.md
112
+ - readme.md
113
+ - refinerycms-authentication.gemspec
114
+ - spec/models/user_spec.rb
115
+ has_rdoc: true
116
+ homepage: http://refinerycms.com
117
+ licenses:
118
+ - MIT
119
+ post_install_message:
120
+ rdoc_options: []
121
+
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: "0"
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: "0"
136
+ requirements: []
137
+
138
+ rubyforge_project: refinerycms
139
+ rubygems_version: 1.5.2
140
+ signing_key:
141
+ specification_version: 3
142
+ summary: Authentication engine for Refinery CMS
143
+ test_files: []
144
+