refinerycms-authentication 1.0.11 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. data/app/controllers/refinery/admin/users_controller.rb +100 -0
  2. data/app/controllers/refinery/passwords_controller.rb +51 -0
  3. data/app/controllers/refinery/sessions_controller.rb +26 -0
  4. data/app/controllers/refinery/users_controller.rb +42 -0
  5. data/app/helpers/refinery/sessions_helper.rb +4 -0
  6. data/app/helpers/refinery/users_helper.rb +4 -0
  7. data/app/mailers/refinery/user_mailer.rb +22 -0
  8. data/app/models/refinery/role.rb +18 -0
  9. data/app/models/refinery/roles_users.rb +8 -0
  10. data/app/models/refinery/user.rb +94 -0
  11. data/app/models/refinery/user_plugin.rb +8 -0
  12. data/app/views/refinery/admin/users/_actions.html.erb +6 -0
  13. data/app/views/{admin → refinery/admin}/users/_form.html.erb +15 -19
  14. data/app/views/{admin → refinery/admin}/users/_records.html.erb +1 -1
  15. data/app/views/refinery/admin/users/_user.html.erb +21 -0
  16. data/app/views/refinery/admin/users/_users.html.erb +4 -0
  17. data/app/views/refinery/admin/users/edit.html.erb +1 -0
  18. data/app/views/refinery/admin/users/index.html.erb +6 -0
  19. data/app/views/refinery/admin/users/new.html.erb +1 -0
  20. data/app/views/{layouts → refinery/layouts}/login.html.erb +3 -4
  21. data/app/views/refinery/passwords/edit.html.erb +26 -0
  22. data/app/views/refinery/passwords/new.html.erb +17 -0
  23. data/app/views/{sessions → refinery/sessions}/new.html.erb +6 -8
  24. data/app/views/refinery/user_mailer/reset_notification.html.erb +12 -0
  25. data/app/views/refinery/user_mailer/reset_notification.text.plain.erb +7 -0
  26. data/app/views/refinery/users/new.html.erb +29 -0
  27. data/config/locales/bg.yml +55 -55
  28. data/config/locales/cs.yml +58 -58
  29. data/config/locales/da.yml +55 -55
  30. data/config/locales/de.yml +55 -55
  31. data/config/locales/el.yml +55 -55
  32. data/config/locales/en.yml +55 -55
  33. data/config/locales/es.yml +55 -60
  34. data/config/locales/fi.yml +55 -55
  35. data/config/locales/fr.yml +55 -55
  36. data/config/locales/it.yml +51 -57
  37. data/config/locales/ja.yml +72 -0
  38. data/config/locales/ko.yml +72 -0
  39. data/config/locales/lt.yml +46 -46
  40. data/config/locales/lv.yml +55 -55
  41. data/config/locales/nb.yml +55 -55
  42. data/config/locales/nl.yml +55 -55
  43. data/config/locales/pl.yml +53 -59
  44. data/config/locales/pt-BR.yml +52 -52
  45. data/config/locales/rs.yml +62 -61
  46. data/config/locales/ru.yml +52 -52
  47. data/config/locales/sk.yml +55 -55
  48. data/config/locales/sl.yml +55 -54
  49. data/config/locales/sv.yml +52 -52
  50. data/config/locales/vi.yml +55 -55
  51. data/config/locales/zh-CN.yml +55 -55
  52. data/config/locales/zh-TW.yml +55 -55
  53. data/config/routes.rb +30 -24
  54. data/db/migrate/20100913234705_create_refinerycms_authentication_schema.rb +30 -30
  55. data/lib/refinery/authenticated_system.rb +40 -0
  56. data/lib/refinery/authentication/configuration.rb +9 -0
  57. data/lib/refinery/authentication/engine.rb +36 -0
  58. data/lib/refinery/authentication.rb +29 -0
  59. data/lib/refinerycms-authentication.rb +1 -54
  60. data/refinerycms-authentication.gemspec +14 -109
  61. data/spec/controllers/refinery/admin/users_controller_spec.rb +73 -0
  62. data/spec/factories/user.rb +38 -0
  63. data/spec/models/refinery/user_spec.rb +220 -0
  64. data/spec/requests/refinery/admin/users_spec.rb +49 -0
  65. data/spec/requests/refinery/passwords_spec.rb +84 -0
  66. data/spec/requests/refinery/sessions_spec.rb +62 -0
  67. metadata +109 -124
  68. data/app/controllers/admin/users_controller.rb +0 -86
  69. data/app/controllers/passwords_controller.rb +0 -42
  70. data/app/controllers/sessions_controller.rb +0 -23
  71. data/app/controllers/users_controller.rb +0 -67
  72. data/app/helpers/sessions_helper.rb +0 -2
  73. data/app/helpers/users_helper.rb +0 -2
  74. data/app/mailers/user_mailer.rb +0 -20
  75. data/app/models/role.rb +0 -16
  76. data/app/models/roles_users.rb +0 -6
  77. data/app/models/user.rb +0 -65
  78. data/app/models/user_plugin.rb +0 -6
  79. data/app/views/admin/users/_actions.html.erb +0 -5
  80. data/app/views/admin/users/_user.html.erb +0 -19
  81. data/app/views/admin/users/_users.html.erb +0 -4
  82. data/app/views/admin/users/edit.html.erb +0 -1
  83. data/app/views/admin/users/index.html.erb +0 -6
  84. data/app/views/admin/users/new.html.erb +0 -1
  85. data/app/views/passwords/edit.html.erb +0 -31
  86. data/app/views/passwords/new.html.erb +0 -18
  87. data/app/views/user_mailer/reset_notification.html.erb +0 -12
  88. data/app/views/user_mailer/reset_notification.text.plain.erb +0 -7
  89. data/app/views/users/new.html.erb +0 -41
  90. data/config/locales/jp.yml +0 -72
  91. data/config/locales/lolcat.yml +0 -55
  92. data/db/migrate/20100929035252_add_missing_indexes_to_roles_users.rb +0 -11
  93. data/db/migrate/20101206013505_change_to_devise_users_table.rb +0 -27
  94. data/db/migrate/20110106184757_add_remember_created_at_to_users.rb +0 -9
  95. data/db/migrate/20110325213325_remove_password_salt_from_users.rb +0 -13
  96. data/features/lost_password.feature +0 -49
  97. data/features/manage_users.feature +0 -88
  98. data/features/step_definitions/lost_password.rb +0 -8
  99. data/features/step_definitions/user_steps.rb +0 -41
  100. data/features/support/factories.rb +0 -32
  101. data/features/support/paths.rb +0 -24
  102. data/lib/authenticated_system.rb +0 -29
  103. data/lib/gemspec.rb +0 -38
  104. data/lib/generators/refinerycms_authentication_generator.rb +0 -8
  105. data/spec/models/user_spec.rb +0 -152
metadata CHANGED
@@ -1,116 +1,92 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: refinerycms-authentication
3
- version: !ruby/object:Gem::Version
4
- version: 1.0.11
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15
5
5
  prerelease:
6
+ segments:
7
+ - 2
8
+ - 0
9
+ - 0
10
+ version: 2.0.0
6
11
  platform: ruby
7
- authors:
8
- - Resolve Digital
12
+ authors:
9
13
  - Philip Arndt
14
+ - "U\xC4\xA3is Ozols"
10
15
  - David Jones
11
16
  - Steven Heidel
12
- - Uģis Ozols
13
17
  autorequire:
14
18
  bindir: bin
15
19
  cert_chain: []
16
- date: 2012-05-18 00:00:00.000000000 Z
17
- dependencies:
18
- - !ruby/object:Gem::Dependency
19
- name: refinerycms-core
20
- requirement: !ruby/object:Gem::Requirement
21
- none: false
22
- requirements:
23
- - - '='
24
- - !ruby/object:Gem::Version
25
- version: 1.0.11
26
- type: :runtime
20
+
21
+ date: 2012-03-01 00:00:00 Z
22
+ dependencies:
23
+ - !ruby/object:Gem::Dependency
27
24
  prerelease: false
28
- version_requirements: !ruby/object:Gem::Requirement
25
+ requirement: &id001 !ruby/object:Gem::Requirement
29
26
  none: false
30
- requirements:
31
- - - '='
32
- - !ruby/object:Gem::Version
33
- version: 1.0.11
34
- - !ruby/object:Gem::Dependency
35
- name: activerecord
36
- requirement: !ruby/object:Gem::Requirement
37
- none: false
38
- requirements:
27
+ requirements:
39
28
  - - ~>
40
- - !ruby/object:Gem::Version
41
- version: 3.0.10
42
- type: :runtime
43
- prerelease: false
44
- version_requirements: !ruby/object:Gem::Requirement
45
- none: false
46
- requirements:
47
- - - ~>
48
- - !ruby/object:Gem::Version
49
- version: 3.0.10
50
- - !ruby/object:Gem::Dependency
29
+ - !ruby/object:Gem::Version
30
+ hash: 15
31
+ segments:
32
+ - 2
33
+ - 0
34
+ - 0
35
+ version: 2.0.0
36
+ version_requirements: *id001
51
37
  name: devise
52
- requirement: !ruby/object:Gem::Requirement
53
- none: false
54
- requirements:
55
- - - ~>
56
- - !ruby/object:Gem::Version
57
- version: 1.4.3
58
38
  type: :runtime
39
+ - !ruby/object:Gem::Dependency
59
40
  prerelease: false
60
- version_requirements: !ruby/object:Gem::Requirement
61
- none: false
62
- requirements:
63
- - - ~>
64
- - !ruby/object:Gem::Version
65
- version: 1.4.3
66
- - !ruby/object:Gem::Dependency
67
- name: friendly_id_globalize3
68
- requirement: !ruby/object:Gem::Requirement
41
+ requirement: &id002 !ruby/object:Gem::Requirement
69
42
  none: false
70
- requirements:
71
- - - ~>
72
- - !ruby/object:Gem::Version
73
- version: 3.2.1
43
+ requirements:
44
+ - - "="
45
+ - !ruby/object:Gem::Version
46
+ hash: 15
47
+ segments:
48
+ - 2
49
+ - 0
50
+ - 0
51
+ version: 2.0.0
52
+ version_requirements: *id002
53
+ name: refinerycms-core
74
54
  type: :runtime
75
- prerelease: false
76
- version_requirements: !ruby/object:Gem::Requirement
77
- none: false
78
- requirements:
79
- - - ~>
80
- - !ruby/object:Gem::Version
81
- version: 3.2.1
82
- description: The default authentication engine for Refinery CMS
55
+ description: The default authentication extension for Refinery CMS
83
56
  email: info@refinerycms.com
84
57
  executables: []
58
+
85
59
  extensions: []
60
+
86
61
  extra_rdoc_files: []
87
- files:
88
- - app/controllers/admin/users_controller.rb
89
- - app/controllers/passwords_controller.rb
90
- - app/controllers/sessions_controller.rb
91
- - app/controllers/users_controller.rb
92
- - app/helpers/sessions_helper.rb
93
- - app/helpers/users_helper.rb
94
- - app/mailers/user_mailer.rb
95
- - app/models/role.rb
96
- - app/models/roles_users.rb
97
- - app/models/user.rb
98
- - app/models/user_plugin.rb
99
- - app/views/admin/users/_actions.html.erb
100
- - app/views/admin/users/_form.html.erb
101
- - app/views/admin/users/_records.html.erb
102
- - app/views/admin/users/_user.html.erb
103
- - app/views/admin/users/_users.html.erb
104
- - app/views/admin/users/edit.html.erb
105
- - app/views/admin/users/index.html.erb
106
- - app/views/admin/users/new.html.erb
107
- - app/views/layouts/login.html.erb
108
- - app/views/passwords/edit.html.erb
109
- - app/views/passwords/new.html.erb
110
- - app/views/sessions/new.html.erb
111
- - app/views/user_mailer/reset_notification.html.erb
112
- - app/views/user_mailer/reset_notification.text.plain.erb
113
- - app/views/users/new.html.erb
62
+
63
+ files:
64
+ - app/controllers/refinery/admin/users_controller.rb
65
+ - app/controllers/refinery/passwords_controller.rb
66
+ - app/controllers/refinery/sessions_controller.rb
67
+ - app/controllers/refinery/users_controller.rb
68
+ - app/helpers/refinery/sessions_helper.rb
69
+ - app/helpers/refinery/users_helper.rb
70
+ - app/mailers/refinery/user_mailer.rb
71
+ - app/models/refinery/role.rb
72
+ - app/models/refinery/roles_users.rb
73
+ - app/models/refinery/user.rb
74
+ - app/models/refinery/user_plugin.rb
75
+ - app/views/refinery/admin/users/_actions.html.erb
76
+ - app/views/refinery/admin/users/_form.html.erb
77
+ - app/views/refinery/admin/users/_records.html.erb
78
+ - app/views/refinery/admin/users/_user.html.erb
79
+ - app/views/refinery/admin/users/_users.html.erb
80
+ - app/views/refinery/admin/users/edit.html.erb
81
+ - app/views/refinery/admin/users/index.html.erb
82
+ - app/views/refinery/admin/users/new.html.erb
83
+ - app/views/refinery/layouts/login.html.erb
84
+ - app/views/refinery/passwords/edit.html.erb
85
+ - app/views/refinery/passwords/new.html.erb
86
+ - app/views/refinery/sessions/new.html.erb
87
+ - app/views/refinery/user_mailer/reset_notification.html.erb
88
+ - app/views/refinery/user_mailer/reset_notification.text.plain.erb
89
+ - app/views/refinery/users/new.html.erb
114
90
  - config/locales/bg.yml
115
91
  - config/locales/cs.yml
116
92
  - config/locales/da.yml
@@ -121,8 +97,8 @@ files:
121
97
  - config/locales/fi.yml
122
98
  - config/locales/fr.yml
123
99
  - config/locales/it.yml
124
- - config/locales/jp.yml
125
- - config/locales/lolcat.yml
100
+ - config/locales/ja.yml
101
+ - config/locales/ko.yml
126
102
  - config/locales/lt.yml
127
103
  - config/locales/lv.yml
128
104
  - config/locales/nb.yml
@@ -139,47 +115,56 @@ files:
139
115
  - config/locales/zh-TW.yml
140
116
  - config/routes.rb
141
117
  - db/migrate/20100913234705_create_refinerycms_authentication_schema.rb
142
- - db/migrate/20100929035252_add_missing_indexes_to_roles_users.rb
143
- - db/migrate/20101206013505_change_to_devise_users_table.rb
144
- - db/migrate/20110106184757_add_remember_created_at_to_users.rb
145
- - db/migrate/20110325213325_remove_password_salt_from_users.rb
146
- - features/lost_password.feature
147
- - features/manage_users.feature
148
- - features/step_definitions/lost_password.rb
149
- - features/step_definitions/user_steps.rb
150
- - features/support/factories.rb
151
- - features/support/paths.rb
152
- - lib/authenticated_system.rb
153
- - lib/gemspec.rb
154
- - lib/generators/refinerycms_authentication_generator.rb
118
+ - lib/refinery/authenticated_system.rb
119
+ - lib/refinery/authentication.rb
120
+ - lib/refinery/authentication/configuration.rb
121
+ - lib/refinery/authentication/engine.rb
155
122
  - lib/refinerycms-authentication.rb
156
123
  - license.md
157
124
  - refinerycms-authentication.gemspec
158
- - spec/models/user_spec.rb
125
+ - spec/controllers/refinery/admin/users_controller_spec.rb
126
+ - spec/factories/user.rb
127
+ - spec/models/refinery/user_spec.rb
128
+ - spec/requests/refinery/admin/users_spec.rb
129
+ - spec/requests/refinery/passwords_spec.rb
130
+ - spec/requests/refinery/sessions_spec.rb
159
131
  homepage: http://refinerycms.com
160
- licenses:
132
+ licenses:
161
133
  - MIT
162
134
  post_install_message:
163
135
  rdoc_options: []
164
- require_paths:
136
+
137
+ require_paths:
165
138
  - lib
166
- required_ruby_version: !ruby/object:Gem::Requirement
139
+ required_ruby_version: !ruby/object:Gem::Requirement
167
140
  none: false
168
- requirements:
169
- - - ! '>='
170
- - !ruby/object:Gem::Version
171
- version: '0'
172
- required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ hash: 3
145
+ segments:
146
+ - 0
147
+ version: "0"
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
149
  none: false
174
- requirements:
175
- - - ! '>='
176
- - !ruby/object:Gem::Version
177
- version: '0'
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ hash: 3
154
+ segments:
155
+ - 0
156
+ version: "0"
178
157
  requirements: []
158
+
179
159
  rubyforge_project: refinerycms
180
- rubygems_version: 1.8.22
160
+ rubygems_version: 1.8.17
181
161
  signing_key:
182
162
  specification_version: 3
183
- summary: Authentication engine for Refinery CMS
184
- test_files: []
185
- has_rdoc:
163
+ summary: Authentication extension for Refinery CMS
164
+ test_files:
165
+ - spec/controllers/refinery/admin/users_controller_spec.rb
166
+ - spec/factories/user.rb
167
+ - spec/models/refinery/user_spec.rb
168
+ - spec/requests/refinery/admin/users_spec.rb
169
+ - spec/requests/refinery/passwords_spec.rb
170
+ - spec/requests/refinery/sessions_spec.rb
@@ -1,86 +0,0 @@
1
- module Admin
2
- class UsersController < Admin::BaseController
3
-
4
- crudify :user,
5
- :order => 'username ASC',
6
- :title_attribute => 'username',
7
- :xhr_paging => true
8
-
9
- before_filter :load_available_plugins_and_roles, :only => [:new, :create, :edit, :update]
10
-
11
- def new
12
- @user = User.new
13
- @selected_plugin_names = []
14
- end
15
-
16
- def create
17
- @user = User.new(params[:user])
18
- @selected_plugin_names = params[:user][:plugins] || []
19
- @selected_role_names = params[:user][:roles] || []
20
-
21
- if @user.save
22
- @user.plugins = @selected_plugin_names
23
- # if the user is a superuser and can assign roles according to this site's
24
- # settings then the roles are set with the POST data.
25
- unless current_user.has_role?(:superuser) and RefinerySetting.find_or_set(:superuser_can_assign_roles, false)
26
- @user.add_role(:refinery)
27
- else
28
- @user.roles = @selected_role_names.collect{|r| Role[r.downcase.to_sym]}
29
- end
30
-
31
- redirect_to(admin_users_url, :notice => t('created', :what => @user.username, :scope => 'refinery.crudify'))
32
- else
33
- render :action => 'new'
34
- end
35
- end
36
-
37
- def edit
38
- @user = User.find params[:id]
39
- @selected_plugin_names = @user.plugins.collect{|p| p.name}
40
- end
41
-
42
- def update
43
- # Store what the user selected.
44
- @selected_role_names = params[:user].delete(:roles) || []
45
- unless current_user.has_role?(:superuser) and RefinerySetting.find_or_set(:superuser_can_assign_roles, false)
46
- @selected_role_names = @user.roles.collect{|r| r.title}
47
- end
48
- @selected_plugin_names = params[:user][:plugins]
49
-
50
- # Prevent the current user from locking themselves out of the User manager
51
- if current_user.id == @user.id and (params[:user][:plugins].exclude?("refinery_users") || @selected_role_names.map(&:downcase).exclude?("refinery"))
52
- flash.now[:error] = t('cannot_remove_user_plugin_from_current_user', :scope => 'admin.users.update')
53
- render :action => "edit"
54
- else
55
- # Store the current plugins and roles for this user.
56
- @previously_selected_plugin_names = @user.plugins.collect{|p| p.name}
57
- @previously_selected_roles = @user.roles
58
- @user.roles = @selected_role_names.collect{|r| Role[r.downcase.to_sym]}
59
- if params[:user][:password].blank? and params[:user][:password_confirmation].blank?
60
- params[:user].delete(:password)
61
- params[:user].delete(:password_confirmation)
62
- end
63
-
64
- if @user.update_attributes(params[:user])
65
- redirect_to admin_users_url, :notice => t('updated', :what => @user.username, :scope => 'refinery.crudify')
66
- else
67
- @user.plugins = @previously_selected_plugin_names
68
- @user.roles = @previously_selected_roles
69
- @user.save
70
- render :action => 'edit'
71
- end
72
- end
73
- end
74
-
75
- protected
76
-
77
- def load_available_plugins_and_roles
78
- @available_plugins = ::Refinery::Plugins.registered.in_menu.collect{|a|
79
- {:name => a.name, :title => a.title}
80
- }.sort_by {|a| a[:title]}
81
-
82
- @available_roles = Role.all
83
- end
84
-
85
- end
86
- end
@@ -1,42 +0,0 @@
1
- class PasswordsController < ::Devise::PasswordsController
2
- layout 'login'
3
-
4
- # Rather than overriding devise, it seems better to just apply the notice here.
5
- after_filter :give_notice, :only => [:update]
6
- def give_notice
7
- unless %w(notice error alert).include?(flash.keys.map(&:to_s)) or @user.errors.any?
8
- flash[:notice] = t('successful', :scope => 'users.reset', :email => @user.email)
9
- end
10
- end
11
- protected :give_notice
12
-
13
- # GET /registrations/password/edit?reset_password_token=abcdef
14
- def edit
15
- if params[:reset_password_token] and (@user = User.where(:reset_password_token => params[:reset_password_token]).first).present?
16
- render_with_scope :edit
17
- else
18
- redirect_to(new_user_password_url, :flash => ({
19
- :error => t('code_invalid', :scope => 'users.reset')
20
- }))
21
- end
22
- end
23
-
24
- # POST /registrations/password
25
- def create
26
- if params[:user].present? and (email = params[:user][:email]).present? and
27
- (user = User.where(:email => email).first).present?
28
-
29
- # Call devise reset function.
30
- user.send(:generate_reset_password_token!)
31
- UserMailer.reset_notification(user, request).deliver
32
- redirect_to new_user_session_path, :notice => t('email_reset_sent', :scope => 'users.forgot') and return
33
- else
34
- flash.now[:error] = if (email = params[:user][:email]).blank?
35
- t('blank_email', :scope => 'users.forgot')
36
- else
37
- t('email_not_associated_with_account_html', :email => ERB::Util.html_escape(email), :scope => 'users.forgot').html_safe
38
- end
39
- render_with_scope :new
40
- end
41
- end
42
- end
@@ -1,23 +0,0 @@
1
- class SessionsController < ::Devise::SessionsController
2
- layout 'login'
3
-
4
- before_filter :clear_unauthenticated_flash, :only => [:new]
5
-
6
- def create
7
- super
8
- rescue ::BCrypt::Errors::InvalidSalt, ::BCrypt::Errors::InvalidHash
9
- flash[:error] = t('password_encryption', :scope => 'users.forgot')
10
- redirect_to new_user_password_path
11
- end
12
-
13
- protected
14
- # We don't like this alert.
15
- def clear_unauthenticated_flash
16
- if flash.keys.include?(:alert) and flash.values.any?{|v|
17
- ['unauthenticated', t('unauthenticated', :scope => 'devise.failure')].include?(v)
18
- }
19
- flash.delete(:alert)
20
- end
21
- end
22
-
23
- end
@@ -1,67 +0,0 @@
1
- class UsersController < ::Devise::RegistrationsController
2
-
3
- # Protect these actions behind an admin login
4
- before_filter :redirect?, :only => [:new, :create]
5
-
6
- layout 'login'
7
-
8
- def new
9
- @user = User.new
10
- end
11
-
12
- # This method should only be used to create the first Refinery user.
13
- def create
14
- @user = User.new(params[:user])
15
- @selected_plugin_titles = params[:user][:plugins] || []
16
-
17
- @user.save if @user.valid?
18
-
19
- if @user.errors.empty?
20
- @user.add_role(:refinery)
21
- @user.plugins = @selected_plugin_titles
22
- @user.save
23
- if Role[:refinery].users.count == 1
24
- # this is the superuser if this user is the only user.
25
- @user.add_role(:superuser)
26
- @user.save
27
-
28
- # set this user as the recipient of inquiry notifications, if we're using that engine.
29
- if defined?(InquirySetting) and
30
- (notification_recipients = InquirySetting.find_or_create_by_name("Notification Recipients")).present?
31
- notification_recipients.update_attributes({
32
- :value => @user.email,
33
- :destroyable => false
34
- })
35
- end
36
- end
37
-
38
- flash[:message] = "<h2>#{t('welcome', :scope => 'users.create', :who => @user.username).gsub(/\.$/, '')}.</h2>".html_safe
39
-
40
- site_name_setting = RefinerySetting.find_or_create_by_name('site_name', :value => "Company Name")
41
- if site_name_setting.value.to_s =~ /^(|Company\ Name)$/ or Role[:refinery].users.count == 1
42
- flash[:message] << "<p>#{t('setup_website_name_html', :scope => 'users',
43
- :link => edit_admin_refinery_setting_path(site_name_setting, :dialog => true),
44
- :title => t('edit', :scope => 'admin.refinery_settings'))}</p>".html_safe
45
- end
46
- sign_in(@user)
47
- redirect_back_or_default(admin_root_url)
48
- else
49
- render :action => 'new'
50
- end
51
- end
52
-
53
- protected
54
-
55
- def redirect?
56
- if refinery_user?
57
- redirect_to admin_users_url
58
- elsif refinery_users_exist?
59
- redirect_to new_user_session_path
60
- end
61
- end
62
-
63
- def refinery_users_exist?
64
- Role[:refinery].users.any?
65
- end
66
-
67
- end
@@ -1,2 +0,0 @@
1
- module SessionsHelper
2
- end
@@ -1,2 +0,0 @@
1
- module UsersHelper
2
- end
@@ -1,20 +0,0 @@
1
- class UserMailer < ActionMailer::Base
2
-
3
- def reset_notification(user, request)
4
- @user = user
5
- @url = edit_user_password_url(:host => request.host_with_port,
6
- :reset_password_token => @user.reset_password_token)
7
-
8
- domain = request.domain(RefinerySetting.find_or_set(:tld_length, 1))
9
-
10
- mail(:to => user.email,
11
- :subject => t('subject', :scope => 'user_mailer.reset_notification'),
12
- :from => "\"#{RefinerySetting[:site_name]}\" <no-reply@#{domain}>")
13
- end
14
-
15
- protected
16
-
17
- def url_prefix(request)
18
- "#{request.protocol}#{request.host_with_port}"
19
- end
20
- end
data/app/models/role.rb DELETED
@@ -1,16 +0,0 @@
1
- class Role < ActiveRecord::Base
2
-
3
- has_and_belongs_to_many :users
4
-
5
- before_validation :camelize_title
6
- validates :title, :uniqueness => true
7
-
8
- def camelize_title(role_title = self.title)
9
- self.title = role_title.to_s.camelize
10
- end
11
-
12
- def self.[](title)
13
- find_or_create_by_title(title.to_s.camelize)
14
- end
15
-
16
- end
@@ -1,6 +0,0 @@
1
- class RolesUsers < ActiveRecord::Base
2
-
3
- belongs_to :role
4
- belongs_to :user
5
-
6
- end
data/app/models/user.rb DELETED
@@ -1,65 +0,0 @@
1
- require 'devise'
2
-
3
- class User < ActiveRecord::Base
4
- has_and_belongs_to_many :roles
5
- has_many :plugins, :class_name => "UserPlugin", :order => "position ASC", :dependent => :destroy
6
- has_friendly_id :username, :use_slug => true
7
-
8
- # Include default devise modules. Others available are:
9
- # :token_authenticatable, :confirmable, :lockable and :timeoutable
10
- devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable
11
-
12
- # Setup accessible (or protected) attributes for your model
13
- # :login is a virtual attribute for authenticating by either username or email
14
- # This is in addition to a real persisted field like 'username'
15
- attr_accessor :login
16
- attr_accessible :email, :password, :password_confirmation, :remember_me, :username, :plugins, :login
17
-
18
- validates :username, :presence => true, :uniqueness => true
19
-
20
- class << self
21
- # Configure authentication_keys here instead of devise.rb initialzer so we don't overwrite standard devise models
22
- def authentication_keys
23
- [:login]
24
- end
25
-
26
- # Find user by email or username.
27
- # https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-sign_in-using-their-username-or-email-address
28
- def find_for_database_authentication(conditions)
29
- value = conditions[authentication_keys.first]
30
- where(["username = :value OR email = :value", { :value => value }]).first
31
- end
32
- end
33
-
34
- def plugins=(plugin_names)
35
- if persisted? # don't add plugins when the user_id is nil.
36
- UserPlugin.delete_all(:user_id => id)
37
-
38
- plugin_names.each_with_index do |plugin_name, index|
39
- plugins.create(:name => plugin_name, :position => index) if plugin_name.is_a?(String)
40
- end
41
- end
42
- end
43
-
44
- def authorized_plugins
45
- plugins.collect { |p| p.name } | Refinery::Plugins.always_allowed.names
46
- end
47
-
48
- def can_delete?(user_to_delete = self)
49
- user_to_delete.persisted? and
50
- id != user_to_delete.id and
51
- !user_to_delete.has_role?(:superuser) and
52
- Role[:refinery].users.count > 1
53
- end
54
-
55
- def add_role(title)
56
- raise ArgumentException, "Role should be the title of the role not a role object." if title.is_a?(Role)
57
- roles << Role[title] unless has_role?(title)
58
- end
59
-
60
- def has_role?(title)
61
- raise ArgumentException, "Role should be the title of the role not a role object." if title.is_a?(Role)
62
- roles.any?{|r| r.title == title.to_s.camelize}
63
- end
64
-
65
- end
@@ -1,6 +0,0 @@
1
- class UserPlugin < ActiveRecord::Base
2
-
3
- belongs_to :user
4
- attr_accessible :user_id, :name, :position
5
-
6
- end
@@ -1,5 +0,0 @@
1
- <ul>
2
- <li>
3
- <%= link_to t('.create_new_user'), new_admin_user_url, :class => "add_icon" %>
4
- </li>
5
- </ul>
@@ -1,19 +0,0 @@
1
- <li id="sortable_<%= user.id %>" class='clearfix record <%= cycle("on", "on-hover") %>'>
2
- <span class='title'>
3
- <strong><%= user.username %></strong>
4
- <span class="preview">
5
- <%= t('.preview', :who => user.email, :created_at => l(user.created_at, :format => :short)) %>
6
- </span>
7
- </span>
8
- <span class='actions'>
9
- <%= mail_to user.email, refinery_icon_tag('email_go.png'),
10
- :title => t('.email_user') %>
11
- <%= link_to refinery_icon_tag('application_edit.png'), edit_admin_user_path(user),
12
- :title => t('edit', :scope => 'admin.users')%>
13
- <%= link_to refinery_icon_tag('delete.png'), admin_user_path(user),
14
- :class => "cancel confirm-delete",
15
- :title => t('delete', :scope => 'admin.users'),
16
- :method => :delete,
17
- :confirm => t('message', :scope => 'shared.admin.delete', :title => user.username) if current_user.can_delete?(user) %>
18
- </span>
19
- </li>
@@ -1,4 +0,0 @@
1
- <%= will_paginate @users %>
2
- <ul>
3
- <%= render :partial => "user", :collection => @users %>
4
- </ul>
@@ -1 +0,0 @@
1
- <%= render :partial => 'form' %>
@@ -1,6 +0,0 @@
1
- <section id='records'>
2
- <%= render :partial => 'records' %>
3
- </section>
4
- <aside id='actions'>
5
- <%= render :partial => 'actions' %>
6
- </aside>