refinerycms-authentication-devise 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +89 -0
  3. data/.travis.yml +15 -0
  4. data/Gemfile +50 -0
  5. data/Rakefile +20 -0
  6. data/app/controllers/refinery/authentication/devise/admin/users_controller.rb +147 -0
  7. data/app/controllers/refinery/authentication/devise/passwords_controller.rb +58 -0
  8. data/app/controllers/refinery/authentication/devise/sessions_controller.rb +39 -0
  9. data/app/controllers/refinery/authentication/devise/users_controller.rb +50 -0
  10. data/app/decorators/controllers/action_controller_base_decorator.rb +25 -0
  11. data/app/decorators/controllers/refinery/admin_controller_decorator.rb +20 -0
  12. data/app/decorators/controllers/refinery/application_controller_decorator.rb +7 -0
  13. data/app/mailers/refinery/authentication/devise/user_mailer.rb +26 -0
  14. data/app/models/refinery/authentication/devise/nil_user.rb +31 -0
  15. data/app/models/refinery/authentication/devise/role.rb +22 -0
  16. data/app/models/refinery/authentication/devise/roles_users.rb +12 -0
  17. data/app/models/refinery/authentication/devise/user.rb +166 -0
  18. data/app/models/refinery/authentication/devise/user_plugin.rb +11 -0
  19. data/app/views/refinery/authentication/devise/admin/users/_actions.html.erb +7 -0
  20. data/app/views/refinery/authentication/devise/admin/users/_form.html.erb +94 -0
  21. data/app/views/refinery/authentication/devise/admin/users/_records.html.erb +10 -0
  22. data/app/views/refinery/authentication/devise/admin/users/_user.html.erb +23 -0
  23. data/app/views/refinery/authentication/devise/admin/users/_users.html.erb +4 -0
  24. data/app/views/refinery/authentication/devise/admin/users/edit.html.erb +1 -0
  25. data/app/views/refinery/authentication/devise/admin/users/index.html.erb +6 -0
  26. data/app/views/refinery/authentication/devise/admin/users/new.html.erb +1 -0
  27. data/app/views/refinery/authentication/devise/passwords/edit.html.erb +26 -0
  28. data/app/views/refinery/authentication/devise/passwords/new.html.erb +17 -0
  29. data/app/views/refinery/authentication/devise/sessions/new.html.erb +27 -0
  30. data/app/views/refinery/authentication/devise/user_mailer/reset_notification.html.erb +12 -0
  31. data/app/views/refinery/authentication/devise/user_mailer/reset_notification.text.plain.erb +7 -0
  32. data/app/views/refinery/authentication/devise/users/new.html.erb +29 -0
  33. data/app/views/refinery/layouts/login.html.erb +22 -0
  34. data/bin/rails +5 -0
  35. data/bin/rake +21 -0
  36. data/bin/rspec +22 -0
  37. data/bin/spring +18 -0
  38. data/config/locales/bg.yml +73 -0
  39. data/config/locales/ca.yml +75 -0
  40. data/config/locales/cs.yml +77 -0
  41. data/config/locales/da.yml +73 -0
  42. data/config/locales/de.yml +73 -0
  43. data/config/locales/el.yml +73 -0
  44. data/config/locales/en.yml +77 -0
  45. data/config/locales/es.yml +73 -0
  46. data/config/locales/fi.yml +73 -0
  47. data/config/locales/fr.yml +73 -0
  48. data/config/locales/hu.yml +73 -0
  49. data/config/locales/it.yml +77 -0
  50. data/config/locales/ja.yml +73 -0
  51. data/config/locales/ko.yml +73 -0
  52. data/config/locales/lt.yml +56 -0
  53. data/config/locales/lv.yml +73 -0
  54. data/config/locales/nb.yml +73 -0
  55. data/config/locales/nl.yml +77 -0
  56. data/config/locales/pl.yml +73 -0
  57. data/config/locales/pt-BR.yml +69 -0
  58. data/config/locales/pt.yml +73 -0
  59. data/config/locales/rs.yml +73 -0
  60. data/config/locales/ru.yml +70 -0
  61. data/config/locales/sk.yml +73 -0
  62. data/config/locales/sl.yml +62 -0
  63. data/config/locales/sv.yml +65 -0
  64. data/config/locales/tr.yml +73 -0
  65. data/config/locales/uk.yml +71 -0
  66. data/config/locales/vi.yml +73 -0
  67. data/config/locales/zh-CN.yml +73 -0
  68. data/config/locales/zh-TW.yml +74 -0
  69. data/config/routes.rb +49 -0
  70. data/db/migrate/20100913234705_create_refinerycms_authentication_schema.rb +43 -0
  71. data/db/migrate/20120301234455_add_slug_to_refinery_users.rb +7 -0
  72. data/db/migrate/20130805143059_add_full_name_to_refinery_users.rb +5 -0
  73. data/db/migrate/20150503125200_rename_tables_to_new_namespace.rb +17 -0
  74. data/lib/generators/refinery/authentication/devise/generator.rb +18 -0
  75. data/lib/generators/refinery/authentication/devise/templates/config/initializers/refinery/authentication/devise.rb.erb +8 -0
  76. data/lib/refinery/authentication/devise/authorisation_adapter.rb +36 -0
  77. data/lib/refinery/authentication/devise/authorisation_manager.rb +30 -0
  78. data/lib/refinery/authentication/devise/configuration.rb +22 -0
  79. data/lib/refinery/authentication/devise/engine.rb +43 -0
  80. data/lib/refinery/authentication/devise/initialiser.rb +228 -0
  81. data/lib/refinery/authentication/devise/system.rb +63 -0
  82. data/lib/refinery/authentication/devise.rb +26 -0
  83. data/lib/refinerycms-authentication-devise.rb +1 -0
  84. data/license.md +21 -0
  85. data/readme.md +11 -0
  86. data/refinerycms-authentication-devise.gemspec +22 -0
  87. data/spec/controllers/refinery/authentication/devise/admin/users_controller_spec.rb +90 -0
  88. data/spec/factories/user.rb +27 -0
  89. data/spec/features/refinery/authentication/devise/admin/users_spec.rb +88 -0
  90. data/spec/features/refinery/authentication/devise/passwords_spec.rb +71 -0
  91. data/spec/features/refinery/authentication/devise/sessions_spec.rb +103 -0
  92. data/spec/lib/refinery/authentication/devise/configuration_spec.rb +41 -0
  93. data/spec/models/refinery/user_spec.rb +285 -0
  94. data/spec/spec_helper.rb +27 -0
  95. data/spec/support/refinery/authentication/devise/controller_macros.rb +48 -0
  96. data/spec/support/refinery/authentication/devise/feature_macros.rb +26 -0
  97. data/tasks/rspec.rake +4 -0
  98. metadata +225 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0f9178a82fd347d8cf3c9a6295541017ddc1a476
4
+ data.tar.gz: 06a1f4a6d52a5e766a3a2181385f105ae463e2ea
5
+ SHA512:
6
+ metadata.gz: 6e65a2c356403d884ee5c891bd923ddb78794c3f7225bc2b753def48a13740e2c3999448bbcae1b9395eecbb6eafba37af0ce8c18e5db10bd5c62b6fb2a85fa1
7
+ data.tar.gz: 3731dd94959dfca809697acaea225966b87be47ef9e83a6ebd40ee2a886682a1132202e271be9db4ab3ac9b9aa11e2f151a4df9bb012fff43a9b46105e60096a
data/.gitignore ADDED
@@ -0,0 +1,89 @@
1
+ # Rails
2
+ .bundle
3
+ db/*.sqlite3
4
+ db/*.sqlite3-journal
5
+ *.log
6
+ tmp/**/*
7
+
8
+ # Documentation
9
+ doc/api
10
+ doc/app
11
+ doc/*
12
+ .yardoc
13
+ .yardopts
14
+
15
+ # Public Uploads
16
+ public/system/*
17
+ public/themes/*
18
+
19
+ # Public Cache
20
+ public/javascripts/cache
21
+ public/stylesheets/cache
22
+
23
+ # Vendor Cache
24
+ vendor/cache
25
+
26
+ # Acts as Indexed
27
+ index/**/*
28
+
29
+ # Refinery Specific
30
+ *.tmproj
31
+ *.autobackupbyrefinery.*
32
+ /refinerycms-*.gem
33
+ .autotest
34
+
35
+ # Mac
36
+ .DS_Store
37
+
38
+ # Windows
39
+ Thumbs.db
40
+
41
+ # NetBeans
42
+ nbproject
43
+
44
+ # Eclipse
45
+ .project
46
+
47
+ # Redcar
48
+ .redcar
49
+
50
+ # Rubinius
51
+ *.rbc
52
+
53
+ # Vim
54
+ *.swp
55
+ *.swo
56
+
57
+ # RubyMine
58
+ .idea
59
+
60
+ # Backup
61
+ *~
62
+
63
+ # Capybara Bug
64
+ capybara-*html
65
+
66
+ # sass
67
+ .sass-cache
68
+ .sass-cache/*
69
+
70
+ #rvm
71
+ .rvmrc
72
+ .rvmrc.*
73
+
74
+ # REFINERY CMS DEVELOPMENT ====================================================
75
+ # Always keep this section at the bottom.
76
+
77
+ config/database.yml
78
+ config/amazon_s3.yml
79
+ config/rackspace_cloudfiles.yml
80
+ your_*.*
81
+ db/schema.rb
82
+
83
+ # END REFINERY CMS DEVELOPMENT =================================================
84
+
85
+ Gemfile.lock
86
+ spec/dummy
87
+
88
+ # Local Gemfile for developing without sharing dependencies
89
+ .gemfile
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+ cache: bundler
3
+ bundler_args: --without development
4
+ before_script: "bin/rake refinery:testing:dummy_app"
5
+ env:
6
+ - DB=postgresql
7
+ - DB=mysql
8
+ notifications:
9
+ webhooks:
10
+ - https://webhooks.gitter.im/e/b5d48907cdc89864b874
11
+ rvm:
12
+ - 2.2
13
+ - 2.1
14
+ - 2.0.0
15
+ sudo: false
data/Gemfile ADDED
@@ -0,0 +1,50 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ git "https://github.com/refinery/refinerycms", branch: "auth-for-real-yo-tmp" do
6
+ gem "refinerycms"
7
+
8
+ group :test do
9
+ gem "refinerycms-testing"
10
+ end
11
+ end
12
+
13
+ # Database Configuration
14
+ unless ENV["TRAVIS"]
15
+ gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
16
+ gem "sqlite3", :platform => :ruby
17
+ end
18
+
19
+ if !ENV["TRAVIS"] || ENV["DB"] == "mysql"
20
+ gem "activerecord-jdbcmysql-adapter", :platform => :jruby
21
+ gem "jdbc-mysql", "= 5.1.13", :platform => :jruby
22
+ gem "mysql2", :platform => :ruby
23
+ end
24
+
25
+ if !ENV["TRAVIS"] || ENV["DB"] == "postgresql"
26
+ gem "activerecord-jdbcpostgresql-adapter", :platform => :jruby
27
+ gem "pg", :platform => :ruby
28
+ end
29
+
30
+ gem "jruby-openssl", :platform => :jruby
31
+
32
+ # Refinery/rails should pull in the proper versions of these
33
+ group :assets do
34
+ gem "sass-rails"
35
+ gem "coffee-rails"
36
+ gem "uglifier"
37
+ end
38
+
39
+ group :development do
40
+ gem 'quiet_assets'
41
+ end
42
+
43
+ group :test do
44
+ gem "launchy"
45
+ end
46
+
47
+ # Load local gems according to Refinery developer preference.
48
+ if File.exist? local_gemfile = File.expand_path("../.gemfile", __FILE__)
49
+ eval File.read(local_gemfile)
50
+ end
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+
8
+ ENGINE_PATH = File.dirname(__FILE__)
9
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
10
+
11
+ if File.exists?(APP_RAKEFILE)
12
+ load 'rails/tasks/engine.rake'
13
+ end
14
+
15
+ require "refinerycms-testing"
16
+ Refinery::Testing::Railtie.load_dummy_tasks(ENGINE_PATH)
17
+
18
+ load File.expand_path('../tasks/rspec.rake', __FILE__)
19
+
20
+ task :default => :spec
@@ -0,0 +1,147 @@
1
+ module Refinery
2
+ module Authentication
3
+ module Devise
4
+ module Admin
5
+ class UsersController < Refinery::AdminController
6
+
7
+ crudify :'refinery/authentication/devise/user',
8
+ :order => 'username ASC',
9
+ :title_attribute => 'username'
10
+
11
+ before_action :find_available_plugins, :find_available_roles,
12
+ :only => [:new, :create, :edit, :update]
13
+ before_action :redirect_unless_user_editable!, :only => [:edit, :update]
14
+ before_action :exclude_password_assignment_when_blank!, :only => :update
15
+
16
+ def new
17
+ @user = Refinery::Authentication::Devise::User.new
18
+ @selected_plugin_names = []
19
+ end
20
+
21
+ def create
22
+ @user = Refinery::Authentication::Devise::User.new user_params.except(:roles)
23
+ @selected_plugin_names = params[:user][:plugins] || []
24
+ @selected_role_names = params[:user][:roles] || []
25
+
26
+ if @user.save
27
+ create_successful
28
+ else
29
+ create_failed
30
+ end
31
+ end
32
+
33
+ def edit
34
+ @selected_plugin_names = find_user.plugins.map(&:name)
35
+ end
36
+
37
+ def update
38
+ # Store what the user selected.
39
+ @selected_role_names = params[:user].delete(:roles) || []
40
+ @selected_role_names = @user.roles.select(:title).map(&:title) unless user_can_assign_roles?
41
+ @selected_plugin_names = params[:user][:plugins]
42
+
43
+ if user_is_locking_themselves_out?
44
+ flash.now[:error] = t('lockout_prevented', :scope => 'refinery.authentication.devise.admin.users.update')
45
+ render :edit and return
46
+ end
47
+
48
+ store_user_memento
49
+
50
+ @user.roles = @selected_role_names.map { |r| Refinery::Authentication::Devise::Role[r.downcase] }
51
+ if @user.update_attributes user_params
52
+ update_successful
53
+ else
54
+ update_failed
55
+ end
56
+ end
57
+
58
+ protected
59
+
60
+ def create_successful
61
+ @user.plugins = @selected_plugin_names
62
+
63
+ # if the user is a superuser and can assign roles according to this site's
64
+ # settings then the roles are set with the POST data.
65
+ if user_can_assign_roles?
66
+ @user.roles = @selected_role_names.map { |r| Refinery::Authentication::Devise::Role[r.downcase] }
67
+ else
68
+ @user.add_role :refinery
69
+ end
70
+
71
+ redirect_to refinery.authentication_devise_admin_users_path,
72
+ :notice => t('created', :what => @user.username, :scope => 'refinery.crudify')
73
+ end
74
+
75
+ def create_failed
76
+ render 'new'
77
+ end
78
+
79
+ def update_successful
80
+ redirect_to refinery.authentication_devise_admin_users_path,
81
+ :notice => t('updated', :what => @user.username, :scope => 'refinery.crudify')
82
+ end
83
+
84
+ def update_failed
85
+ user_memento_rollback!
86
+
87
+ render :edit
88
+ end
89
+
90
+ def find_available_plugins
91
+ @available_plugins = Refinery::Plugins.registered.in_menu.map { |a|
92
+ { :name => a.name, :title => a.title }
93
+ }.sort_by { |a| a[:title] }
94
+ end
95
+
96
+ def find_available_roles
97
+ @available_roles = Refinery::Authentication::Devise::Role.all
98
+ end
99
+
100
+ def redirect_unless_user_editable!
101
+ unless current_refinery_user.can_edit? find_user
102
+ redirect_to refinery.authentication_devise_admin_users_path
103
+ end
104
+ end
105
+
106
+ private
107
+ def exclude_password_assignment_when_blank!
108
+ if params[:user][:password].blank? && params[:user][:password_confirmation].blank?
109
+ params[:user].except!(:password, :password_confirmation)
110
+ end
111
+ end
112
+
113
+ def user_can_assign_roles?
114
+ Refinery::Authentication::Devise.superuser_can_assign_roles &&
115
+ current_refinery_user.has_role?(:superuser)
116
+ end
117
+
118
+ def user_is_locking_themselves_out?
119
+ return false if current_refinery_user.id != @user.id || @selected_plugin_names.blank?
120
+
121
+ @selected_plugin_names.exclude?('refinery_authentication_devise') || # removing user plugin access
122
+ @selected_role_names.map(&:downcase).exclude?('refinery') # Or we're removing the refinery role
123
+ end
124
+
125
+ def store_user_memento
126
+ # Store the current plugins and roles for this user.
127
+ @previously_selected_plugin_names = @user.plugins.map(&:name)
128
+ @previously_selected_roles = @user.roles
129
+ end
130
+
131
+ def user_memento_rollback!
132
+ @user.plugins = @previously_selected_plugin_names
133
+ @user.roles = @previously_selected_roles
134
+ @user.save
135
+ end
136
+
137
+ def user_params
138
+ params.require(:user).permit(
139
+ :email, :password, :password_confirmation, :remember_me, :username,
140
+ :login, :full_name, plugins: []
141
+ )
142
+ end
143
+ end
144
+ end
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,58 @@
1
+ module Refinery
2
+ module Authentication
3
+ module Devise
4
+ class PasswordsController < ::Devise::PasswordsController
5
+ helper Refinery::Core::Engine.helpers
6
+ layout 'refinery/layouts/login'
7
+
8
+ before_action :store_password_reset_return_to, :only => [:update]
9
+ def store_password_reset_return_to
10
+ session[:'return_to'] = Refinery::Core.backend_path
11
+ end
12
+ protected :store_password_reset_return_to
13
+
14
+ # Rather than overriding devise, it seems better to just apply the notice here.
15
+ after_action :give_notice, :only => [:update]
16
+ def give_notice
17
+ if %w(notice error alert).exclude?(flash.keys.map(&:to_s)) or self.resource.errors.any?
18
+ flash[:notice] = t('successful', :scope => 'refinery.authentication.devise.users.reset', :email => self.resource.email)
19
+ end
20
+ end
21
+ protected :give_notice
22
+
23
+ # GET /registrations/password/edit?reset_password_token=abcdef
24
+ def edit
25
+ if @reset_password_token = params[:reset_password_token]
26
+ self.resource = User.find_or_initialize_with_error_by_reset_password_token(params[:reset_password_token])
27
+ respond_with(self.resource) and return
28
+ end
29
+
30
+ redirect_to refinery.new_authentication_devise_user_password_path,
31
+ :flash => ({ :error => t('code_invalid', :scope => 'refinery.authentication.devise.users.reset') })
32
+ end
33
+
34
+ # POST /registrations/password
35
+ def create
36
+ if params[:authentication_devise_user].present? && (email = params[:authentication_devise_user][:email]).present? &&
37
+ (user = User.where(:email => email).first).present?
38
+
39
+ token = user.generate_reset_password_token!
40
+ UserMailer.reset_notification(user, request, token).deliver_now
41
+ redirect_to refinery.login_path,
42
+ :notice => t('email_reset_sent', :scope => 'refinery.authentication.devise.users.forgot')
43
+ else
44
+ flash.now[:error] = if (email = params[:authentication_devise_user][:email]).blank?
45
+ t('blank_email', :scope => 'refinery.authentication.devise.users.forgot')
46
+ else
47
+ t('email_not_associated_with_account_html', :email => ERB::Util.html_escape(email), :scope => 'refinery.authentication.devise.users.forgot').html_safe
48
+ end
49
+
50
+ self.new
51
+
52
+ render :new
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,39 @@
1
+ module Refinery
2
+ module Authentication
3
+ module Devise
4
+ class SessionsController < ::Devise::SessionsController
5
+ helper Refinery::Core::Engine.helpers
6
+ layout 'refinery/layouts/login'
7
+
8
+ before_action :clear_unauthenticated_flash, :only => [:new]
9
+ before_action :force_signup_when_no_users!
10
+ after_action :detect_authentication_devise_user!, only: [:create]
11
+
12
+ def create
13
+ super
14
+ rescue ::BCrypt::Errors::InvalidSalt, ::BCrypt::Errors::InvalidHash
15
+ flash[:error] = t('password_encryption', :scope => 'refinery.authentication.devise.users.forgot')
16
+ redirect_to refinery.new_authentication_devise_user_password_path
17
+ end
18
+
19
+ protected
20
+
21
+ # We don't like this alert.
22
+ def clear_unauthenticated_flash
23
+ if flash.keys.include?(:alert) and flash.any?{ |k, v|
24
+ ['unauthenticated', t('unauthenticated', :scope => 'devise.failure')].include?(v)
25
+ }
26
+ flash.delete(:alert)
27
+ end
28
+ end
29
+
30
+ def force_signup_when_no_users!
31
+ return if refinery_users_exist?
32
+
33
+ redirect_to refinery.signup_path and return
34
+ end
35
+
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,50 @@
1
+ module Refinery
2
+ module Authentication
3
+ module Devise
4
+ class UsersController < ::Devise::RegistrationsController
5
+
6
+ # Protect these actions behind an admin login
7
+ before_action :redirect?, :only => [:new, :create]
8
+
9
+ helper Refinery::Core::Engine.helpers
10
+ layout 'refinery/layouts/login'
11
+
12
+ def new
13
+ @user = User.new
14
+ end
15
+
16
+ # This method should only be used to create the first Refinery user.
17
+ def create
18
+ @user = User.new(user_params)
19
+
20
+ if @user.create_first
21
+ flash[:message] = t('welcome', scope: 'refinery.authentication.devise.users.create', who: @user)
22
+
23
+ sign_in(@user)
24
+ redirect_back_or_default(Refinery::Core.backend_path)
25
+ else
26
+ render :new
27
+ end
28
+ end
29
+
30
+ protected
31
+
32
+ def redirect?
33
+ if current_refinery_user.has_role?(:refinery)
34
+ redirect_to refinery.authentication_devise_admin_users_path
35
+ elsif refinery_users_exist?
36
+ redirect_to refinery.login_path
37
+ end
38
+ end
39
+
40
+ def user_params
41
+ params.require(:user).permit(
42
+ :email, :password, :password_confirmation, :remember_me, :username,
43
+ :plugins, :login, :full_name
44
+ )
45
+ end
46
+
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,25 @@
1
+ require "refinery/authentication/devise/authorisation_manager"
2
+
3
+ module RefineryAuthenticationDeviseActionControllerBaseDecoration
4
+ def self.prepended(base)
5
+ base.prepend_before_action :detect_authentication_devise_user!
6
+ end
7
+
8
+ protected
9
+ def refinery_users_exist?
10
+ Refinery::Authentication::Devise::Role[:refinery].users.any?
11
+ end
12
+
13
+ private
14
+ def refinery_authorisation_manager
15
+ @refinery_authorisation_manager ||= ::Refinery::Authentication::Devise::AuthorisationManager.new
16
+ end
17
+
18
+ def detect_authentication_devise_user!
19
+ if current_authentication_devise_user
20
+ refinery_authorisation_manager.set_user!(current_authentication_devise_user)
21
+ end
22
+ end
23
+ end
24
+
25
+ ActionController::Base.send :prepend, RefineryAuthenticationDeviseActionControllerBaseDecoration
@@ -0,0 +1,20 @@
1
+ module RefineryAuthenticationDeviseAdminControllerDecorator
2
+ protected
3
+ # this is an override of an existing method in Refinery::AdminController
4
+ def authenticate_refinery_user!
5
+ begin
6
+ super
7
+ rescue Zilch::Authorisation::NotAuthorisedException
8
+ session["return_to"] = request.path
9
+ redirect_to refinery.login_path and return
10
+ end
11
+ end
12
+
13
+ private
14
+ def authorisation_manager
15
+ # defined in app/decorators/controllers/action_controller_base_decorator.rb
16
+ refinery_authorisation_manager
17
+ end
18
+ end
19
+
20
+ Refinery::AdminController.send :prepend, RefineryAuthenticationDeviseAdminControllerDecorator
@@ -0,0 +1,7 @@
1
+ Refinery::ApplicationController.module_eval do
2
+ private
3
+ def authorisation_manager
4
+ # defined in app/decorators/controllers/action_controller_base_decorator.rb
5
+ refinery_authorisation_manager
6
+ end
7
+ end
@@ -0,0 +1,26 @@
1
+ module Refinery
2
+ module Authentication
3
+ module Devise
4
+ class UserMailer < ActionMailer::Base
5
+
6
+ def reset_notification(user, request, reset_password_token)
7
+ @user = user
8
+ @url = refinery.edit_authentication_devise_user_password_url({
9
+ :host => request.host_with_port,
10
+ :reset_password_token => reset_password_token
11
+ })
12
+
13
+ mail(:to => user.email,
14
+ :subject => t('subject', :scope => 'refinery.authentication.devise.user_mailer.reset_notification'),
15
+ :from => "\"#{Refinery::Core.site_name}\" <#{Refinery::Authentication::Devise.email_from_name}@#{request.domain}>")
16
+ end
17
+
18
+ protected
19
+
20
+ def url_prefix(request)
21
+ "#{request.protocol}#{request.host_with_port}"
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,31 @@
1
+ require 'refinery/core/nil_user'
2
+
3
+ module Refinery
4
+ module Authentication
5
+ module Devise
6
+ class NilUser < Refinery::Core::NilUser
7
+
8
+ def plugins
9
+ Refinery::Plugins.new
10
+ end
11
+
12
+ def has_role?(role)
13
+ false
14
+ end
15
+
16
+ def has_plugin?(name)
17
+ false
18
+ end
19
+
20
+ def can_edit?(user)
21
+ false
22
+ end
23
+
24
+ def landing_url
25
+ Refinery::Core.backend_path
26
+ end
27
+
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,22 @@
1
+ module Refinery
2
+ module Authentication
3
+ module Devise
4
+ class Role < Refinery::Core::BaseModel
5
+
6
+ has_and_belongs_to_many :users, :join_table => :refinery_authentication_devise_roles_users
7
+
8
+ before_validation :camelize_title
9
+ validates :title, :uniqueness => true
10
+
11
+ def camelize_title(role_title = self.title)
12
+ self.title = role_title.to_s.camelize
13
+ end
14
+
15
+ def self.[](title)
16
+ where(:title => title.to_s.camelize).first_or_create!
17
+ end
18
+
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,12 @@
1
+ module Refinery
2
+ module Authentication
3
+ module Devise
4
+ class RolesUsers < Refinery::Core::BaseModel
5
+
6
+ belongs_to :role
7
+ belongs_to :user
8
+
9
+ end
10
+ end
11
+ end
12
+ end