refinerycms-authentication-devise 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -0,0 +1,73 @@
1
+ vi:
2
+ refinery:
3
+ plugins:
4
+ refinery_authentication_devise:
5
+ title: Users
6
+ description: Quản lý người dùng
7
+ authentication:
8
+ devise:
9
+ admin:
10
+ users:
11
+ delete: Xoá vĩnh viễn người dùng này
12
+ edit: Chỉnh sửa người dùng này
13
+ update:
14
+ lockout_prevented: Bạn không thể xoá 'Users' plugin bằng tài khoản bạn đang đăng nhập.
15
+ form:
16
+ blank_password_keeps_current: Bỏ trống mật khẩu để giữ nguyên mật khẩu đang sử dụng
17
+ plugin_access: Truy cập plugin
18
+ role_access: Truy cập phân quyền
19
+ enable_all: kích hoạt tất cả
20
+ actions:
21
+ create_new_user: Thêm người dùng mới
22
+ user:
23
+ email_user: Gửi thư điện tử tới người dùng này
24
+ preview: '(%{who}) được thêm tại %{created_at}'
25
+ sessions:
26
+ new:
27
+ hello_please_sign_in: Xin vui lòng đăng nhập.
28
+ sign_in: Đăng nhập
29
+ forgot_password: Quên mật khẩu
30
+ users:
31
+ new:
32
+ fill_form: Điền thông tin chi tiết cuả bạn để có thể bắt đầu.
33
+ sign_up: Đăng ký
34
+ create:
35
+ welcome: 'Chào mừng tới hệ quản trị nội dung, %{who}'
36
+ forgot:
37
+ email_address: Địa chỉ thư điện tử
38
+ enter_email_address: Xin vui lòng nhận địa chỉ thư điện tử cho tài khoản cuả bạn.
39
+ reset_password: Khởi tạo lại mật khẩu
40
+ blank_email: Bạn chưa nhập địa chỉ thư điện tử.
41
+ email_not_associated_with_account_html: "Xin lỗi, '%{email}' không có trong hệ thống.<br />Bạn có chắc là đã nhập đúng địa chỉ thư điện tử?"
42
+ email_reset_sent: Thử điện tử chứa đường dẫn để khởi tạo lại mật khẩu vừa được gửi tới bạn.
43
+ password_encryption: Bạn cần khởi tạo lại mật khẩu vì có thay đổi trong cách chúng tôi mã khoá mật khẩu.
44
+ reset:
45
+ successful: "Khởi tạo lại mật khẩu thành công cho '%{email}'"
46
+ pick_new_password_for: "Chọn mật khẩu mới cho %{email}"
47
+ reset_password: Khởi tạo lại mật khẩu
48
+ user_mailer:
49
+ reset_notification:
50
+ subject: Đường dẫn để khởi tạo lại mật khẩu
51
+ reset_request_received_for: "Yêu cầu khởii tạo lại mật khẩu cho %{username}"
52
+ visit_this_url: Mở URL này để chọn mật khẩu mới
53
+ remain_same_if_no_action: Mật khẩu của bạn sẽ không đổi nếu không thực tiện thao tác nào
54
+ roles:
55
+ superuser: Superuser
56
+ refinery: Refinery
57
+ devise:
58
+ failure:
59
+ unauthenticated: Bạn cần đăng nhập trước khi tiếp tục.
60
+ invalid: "Xin lỗi, mật khẩu của bạn không đúng."
61
+ sessions:
62
+ signed_in: Đăng nhập thành công.
63
+ activerecord:
64
+ models:
65
+ refinery/authentication/devise/user: người dùng
66
+ attributes:
67
+ refinery/authentication/devise/user:
68
+ login: Đăng nhập
69
+ username: Tên người dùng
70
+ password: Mật khẩu
71
+ password_confirmation: Kiểm định mật khẩu
72
+ email: Thư điện tử
73
+ remember_me: Nhớ đăng nhập cho lần sau
@@ -0,0 +1,73 @@
1
+ zh-CN:
2
+ refinery:
3
+ plugins:
4
+ refinery_authentication_devise:
5
+ title: 用户
6
+ description: 用户管理
7
+ authentication:
8
+ devise:
9
+ admin:
10
+ users:
11
+ delete: 永久删除此用户
12
+ edit: 编辑此用户
13
+ update:
14
+ lockout_prevented: 您当前登录所使用的帐号无法移除‘用户’插件.
15
+ form:
16
+ blank_password_keeps_current: 保留密码框为空以保持原有密码
17
+ plugin_access: 插件
18
+ role_access: 角色
19
+ enable_all: 选中所有
20
+ actions:
21
+ create_new_user: 添加新用户
22
+ user:
23
+ email_user: 发邮件到此用户
24
+ preview: '(%{who}) 添加于 %{created_at}'
25
+ sessions:
26
+ new:
27
+ hello_please_sign_in: 您好! 请登录.
28
+ sign_in: 登录
29
+ forgot_password: 找回密码
30
+ users:
31
+ new:
32
+ fill_form: 在下面填写您的详细信息以做好开始的准备.
33
+ sign_up: 注册
34
+ create:
35
+ welcome: '欢迎使用 Refinery, %{who}'
36
+ forgot:
37
+ email_address: 邮件地址
38
+ enter_email_address: 请为您的帐号输入邮件地址.
39
+ reset_password: 重置密码
40
+ blank_email: 您没有输入邮件地址.
41
+ email_not_associated_with_account_html: "对不起, '%{email}' 并没有关联到任何的帐号.<br />您确认输入了正确的邮件地址?"
42
+ email_reset_sent: 一封包含有重置密码链接的邮件已经发送到您的邮箱.
43
+ password_encryption: '请重置您的密码. (为了更好的安全性,Refinery 改进了加密算法, 您需要重置密码使之生效)'
44
+ reset:
45
+ successful: "'%{email}' 密码重置成功"
46
+ pick_new_password_for: "为 %{email} 获得一个新密码"
47
+ reset_password: 重置密码
48
+ user_mailer:
49
+ reset_notification:
50
+ subject: 密码重置的链接
51
+ reset_request_received_for: "请求收%{username}到重置密码"
52
+ visit_this_url: 浏览此URL去选择一个新密码
53
+ remain_same_if_no_action: '如果你不进行操作, 你的密码将维持不变'
54
+ roles:
55
+ superuser: 超级用户
56
+ refinery: Refinery
57
+ devise:
58
+ failure:
59
+ unauthenticated: 您尚未登录.
60
+ invalid: "对不起, 您的用户名或密码不正确."
61
+ sessions:
62
+ signed_in: 登录成功.
63
+ activerecord:
64
+ models:
65
+ refinery/authentication/devise/user: 用户
66
+ attributes:
67
+ refinery/authentication/devise/user:
68
+ login: 登录
69
+ username: 用户名
70
+ password: 密码
71
+ password_confirmation: 确认密码
72
+ email: Email
73
+ remember_me: 记住我
@@ -0,0 +1,74 @@
1
+ zh-TW:
2
+ refinery:
3
+ plugins:
4
+ refinery_authentication_devise:
5
+ title: 使用者
6
+ description: 管理使用者
7
+ authentication:
8
+ devise:
9
+ admin:
10
+ users:
11
+ delete: 永遠移除這位使用者
12
+ edit: 編輯這位使用者
13
+ update:
14
+ lockout_prevented: 您無法從目前登入的帳號移除 '使用者' 插件.
15
+ form:
16
+ blank_password_keeps_current: 密碼處空白可維持現在的密碼
17
+ plugin_access: 插件存取權限
18
+ role_access: 角色存取權限
19
+ enable_all: 全部開啟
20
+ actions:
21
+ create_new_user: 新增使用者
22
+ user:
23
+ email_user: 發送電子郵件給這個使用者
24
+ preview: '(%{who}) 加入 %{created_at}'
25
+ sessions:
26
+ new:
27
+ hello_please_sign_in: 您好! 請登入
28
+ sign_in: 登入
29
+ forgot_password: 我忘記了密碼
30
+ users:
31
+ new:
32
+ fill_form: 在底下填入您的資料好繼續之後的流程.
33
+ sign_up: 登入
34
+ create:
35
+ welcome: '歡迎使用 Refinery, %{who}'
36
+ forgot:
37
+ email_address: 電子郵件地址
38
+ enter_email_address: 請為您的帳號輸入電子郵件地址
39
+ reset_password: 重設密碼
40
+ blank_email: 您沒有輸入電子郵件地址.
41
+ email_not_associated_with_account_html: "抱歉, '%{email}' 不是任何帳號的電子郵件地址.<br />您確定輸入了正確的電子郵件地址嗎?"
42
+ email_reset_sent: 一封附上可重設您密碼的連結的電子郵件已經寄給您
43
+ password_encryption: "因為 Refinery 有些密碼加密演算法的改變, 所以您必須重設您的密碼, 如此您的密碼會比以往更安全地儲存著."
44
+ reset:
45
+ code_invalid: "很抱歉, 但這個重設碼過期或是失效了. 如果您遇到問題, 試著複製貼上您電子郵件上的網址到您的瀏覽器或是重新啟動重設密碼的流程."
46
+ successful: "成功地重設 '%{email}' 的密碼"
47
+ pick_new_password_for: "為 %{email} 挑選新的密碼"
48
+ reset_password: 重設密碼
49
+ user_mailer:
50
+ reset_notification:
51
+ subject: 重設您的密碼的連結
52
+ reset_request_received_for: '請求重設 %{username} 的密碼'
53
+ visit_this_url: 到這個網址來設定新的密碼
54
+ remain_same_if_no_action: '如果您不做任何動作, 您的密碼將會維持不變'
55
+ roles:
56
+ superuser: 管理者
57
+ refinery: Refinery
58
+ devise:
59
+ failure:
60
+ unauthenticated: 您必須登入之後才能繼續.
61
+ invalid: '抱歉, 您輸入的帳號或是密碼不正確.'
62
+ sessions:
63
+ signed_in: 登入成功.
64
+ activerecord:
65
+ models:
66
+ refinery/authentication/devise/user: 使用者
67
+ attributes:
68
+ refinery/authentication/devise/user:
69
+ login: 登入
70
+ username: 使用者名稱
71
+ password: 密碼
72
+ password_confirmation: 再次確認密碼
73
+ email: 電子郵件
74
+ remember_me: 記住我的設定
data/config/routes.rb ADDED
@@ -0,0 +1,49 @@
1
+ Refinery::Core::Engine.routes.draw do
2
+ begin
3
+ require 'devise'
4
+
5
+ # Override Devise's other routes for convenience methods.
6
+ devise_scope :authentication_devise_user do
7
+ get "/#{Refinery::Core.backend_route}/login",
8
+ to: "authentication/devise/sessions#new", as: :login
9
+ get "/#{Refinery::Core.backend_route}/logout",
10
+ to: "authentication/devise/sessions#destroy", as: :logout
11
+ get "/#{Refinery::Core.backend_route}/users/register",
12
+ to: 'authentication/devise/users#new', as: :new_signup
13
+ post "/#{Refinery::Core.backend_route}/users/register",
14
+ to: 'authentication/devise/users#create', as: :signup
15
+ end
16
+
17
+ devise_for :authentication_devise_user,
18
+ class_name: 'Refinery::Authentication::Devise::User',
19
+ path: "#{Refinery::Core.backend_route}/users",
20
+ controllers: {
21
+ passwords: 'refinery/authentication/devise/passwords',
22
+ sessions: 'refinery/authentication/devise/sessions',
23
+ registrations: 'refinery/authentication/devise/users'
24
+ },
25
+ skip: [:registrations],
26
+ path_names: { sign_out: 'logout',
27
+ sign_in: 'login',
28
+ sign_up: 'register' }
29
+ rescue RuntimeError => exc
30
+ if exc.message =~ /ORM/
31
+ # We don't want to complain on a fresh installation.
32
+ if (ARGV || []).exclude?('--fresh-installation')
33
+ puts "---\nYou can safely ignore the following warning if you're currently installing Refinery as Devise support files have not yet been copied to your application:\n\n"
34
+ puts exc.message
35
+ puts '---'
36
+ end
37
+ else
38
+ raise exc
39
+ end
40
+ end
41
+
42
+ namespace :authentication, path: '' do
43
+ namespace :devise, path: '' do
44
+ namespace :admin, path: Refinery::Core.backend_route do
45
+ resources :users, except: :show
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,43 @@
1
+ class CreateRefinerycmsAuthenticationSchema < ActiveRecord::Migration
2
+ def change
3
+ # Postgres apparently requires the roles_users table to exist before creating the roles table.
4
+ create_table :refinery_roles_users, :id => false do |t|
5
+ t.integer :user_id
6
+ t.integer :role_id
7
+ end
8
+
9
+ add_index :refinery_roles_users, [:role_id, :user_id]
10
+ add_index :refinery_roles_users, [:user_id, :role_id]
11
+
12
+ create_table :refinery_roles do |t|
13
+ t.string :title
14
+ end
15
+
16
+ create_table :refinery_user_plugins do |t|
17
+ t.integer :user_id
18
+ t.string :name
19
+ t.integer :position
20
+ end
21
+
22
+ add_index :refinery_user_plugins, :name
23
+ add_index :refinery_user_plugins, [:user_id, :name], :unique => true
24
+
25
+ create_table :refinery_users do |t|
26
+ t.string :username, :null => false
27
+ t.string :email, :null => false
28
+ t.string :encrypted_password, :null => false
29
+ t.datetime :current_sign_in_at
30
+ t.datetime :last_sign_in_at
31
+ t.string :current_sign_in_ip
32
+ t.string :last_sign_in_ip
33
+ t.integer :sign_in_count
34
+ t.datetime :remember_created_at
35
+ t.string :reset_password_token
36
+ t.datetime :reset_password_sent_at
37
+
38
+ t.timestamps
39
+ end
40
+
41
+ add_index :refinery_users, :id
42
+ end
43
+ end
@@ -0,0 +1,7 @@
1
+ class AddSlugToRefineryUsers < ActiveRecord::Migration
2
+ def change
3
+ add_column :refinery_users, :slug, :string
4
+ add_index :refinery_users, :slug
5
+
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ class AddFullNameToRefineryUsers < ActiveRecord::Migration
2
+ def change
3
+ add_column :refinery_users, :full_name, :string
4
+ end
5
+ end
@@ -0,0 +1,17 @@
1
+ class RenameTablesToNewNamespace < ActiveRecord::Migration
2
+ def change
3
+ remove_index :refinery_user_plugins, [:user_id, :name]
4
+ add_index :refinery_user_plugins, [:user_id, :name], unique: true,
5
+ name: :refinery_user_plugins_user_id_name
6
+
7
+ remove_index :refinery_roles_users, [:role_id, :user_id]
8
+ remove_index :refinery_roles_users, [:user_id, :role_id]
9
+ add_index :refinery_roles_users, [:role_id, :user_id], name: :refinery_roles_users_role_id_user_id
10
+ add_index :refinery_roles_users, [:user_id, :role_id], name: :refinery_roles_users_user_id_role_id
11
+
12
+ rename_table :refinery_users, :refinery_authentication_devise_users
13
+ rename_table :refinery_roles, :refinery_authentication_devise_roles
14
+ rename_table :refinery_user_plugins, :refinery_authentication_devise_user_plugins
15
+ rename_table :refinery_roles_users, :refinery_authentication_devise_roles_users
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ module Refinery
2
+ module Authentication
3
+ module Devise
4
+ class Generator < Rails::Generators::Base
5
+ source_root File.expand_path("../templates", __FILE__)
6
+
7
+ def rake_db
8
+ rake "refinery_authentication:install:migrations"
9
+ end
10
+
11
+ def generate_authentication_devise_initializer
12
+ template "config/initializers/refinery/authentication/devise.rb.erb",
13
+ File.join(destination_root, "config", "initializers", "refinery", "authentication.rb")
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,8 @@
1
+ # encoding: utf-8
2
+ Refinery::Authentication::Devise.configure do |config|
3
+ # Configure whether to allow superuser to assign roles
4
+ # config.superuser_can_assign_roles = <%= Refinery::Authentication::Devise.superuser_can_assign_roles.inspect %>
5
+
6
+ # Configure notification email from name
7
+ # config.email_from_name = <%= Refinery::Authentication::Devise.email_from_name.inspect %>
8
+ end
@@ -0,0 +1,36 @@
1
+ require "refinery/core/authorisation_adapter"
2
+
3
+ module Refinery
4
+ module Authentication
5
+ module Devise
6
+ class AuthorisationAdapter < Refinery::Core::AuthorisationAdapter
7
+
8
+ # If no user exists, we use a NilUser (non-admin).
9
+ def current_user
10
+ @current_user ||= Refinery::Authentication::Devise::NilUser.new
11
+ end
12
+
13
+ # This method has been added, it does not exist in the superclass.
14
+ def current_user=(set_to_this_user)
15
+ @current_user = set_to_this_user
16
+ end
17
+
18
+ def allow?(operation, resource)
19
+ case
20
+ when resource == :site_bar
21
+ current_user.has_role?(:refinery)
22
+ when operation == :plugin
23
+ current_user.active_plugins.names.include?(resource)
24
+ when operation == :controller
25
+ current_user.active_plugins.any? do |plugin|
26
+ Regexp.new(plugin.menu_match) === resource
27
+ end
28
+ else
29
+ false
30
+ end
31
+ end
32
+
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,30 @@
1
+ require "refinery/core/authorisation_manager"
2
+ require "refinery/authentication/devise/authorisation_adapter"
3
+
4
+ module Refinery
5
+ module Authentication
6
+ module Devise
7
+ class AuthorisationManager < Refinery::Core::AuthorisationManager
8
+
9
+ # The user needs the 'refinery' role to access the admin.
10
+ def authenticate!
11
+ unless adapter.current_user.has_role?(:refinery)
12
+ raise Zilch::Authorisation::NotAuthorisedException
13
+ end
14
+
15
+ adapter.current_user
16
+ end
17
+
18
+ # Override the default adapter specified in the superclass.
19
+ def default_adapter
20
+ @default_adapter ||= Refinery::Authentication::Devise::AuthorisationAdapter.new
21
+ end
22
+
23
+ # This allows a user to be supplied, bypassing the usual detection.
24
+ def set_user!(user)
25
+ adapter.current_user = user
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,22 @@
1
+ module Refinery
2
+ module Authentication
3
+ module Devise
4
+ include ActiveSupport::Configurable
5
+
6
+ config_accessor :superuser_can_assign_roles, :email_from_name
7
+
8
+ self.superuser_can_assign_roles = false
9
+ self.email_from_name = "no-reply"
10
+
11
+ class << self
12
+ def email_from_name
13
+ ::I18n.t(
14
+ 'email_from_name',
15
+ scope: 'refinery.authentication.config',
16
+ default: config.email_from_name
17
+ )
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,43 @@
1
+ module Refinery
2
+ module Authentication
3
+ module Devise
4
+ class Engine < ::Rails::Engine
5
+ include Refinery::Engine
6
+
7
+ isolate_namespace Refinery::Authentication::Devise
8
+ engine_name :refinery_authentication
9
+
10
+ config.autoload_paths += %W( #{config.root}/lib )
11
+
12
+ before_inclusion do
13
+ Refinery::Plugin.register do |plugin|
14
+ plugin.pathname = root
15
+ plugin.name = 'refinery_authentication_devise'
16
+ plugin.menu_match = %r{refinery/(authentication/devise/)?users$}
17
+ plugin.url = proc {
18
+ Refinery::Core::Engine.routes.url_helpers.authentication_devise_admin_users_path
19
+ }
20
+ end
21
+ end
22
+
23
+ before_inclusion do
24
+ [Refinery::AdminController, ::ApplicationController].each do |c|
25
+ Refinery.include_once(c, Refinery::Authentication::Devise::System)
26
+ end
27
+ end
28
+
29
+ config.before_configuration do
30
+ require 'refinery/authentication/devise/initialiser'
31
+ end
32
+
33
+ config.after_initialize do
34
+ Refinery.register_extension(Refinery::Authentication::Devise)
35
+
36
+ Rails.application.reload_routes!
37
+ Refinery::Core.refinery_logout_path =
38
+ Refinery::Core::Engine.routes.url_helpers.logout_path
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end