casein 5.3.2.0 → 5.4.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.
- checksums.yaml +4 -4
- data/README.rdoc +6 -6
- data/Rakefile +5 -4
- data/app/controllers/casein/admin_user_sessions_controller.rb +12 -14
- data/app/controllers/casein/admin_users_controller.rb +49 -50
- data/app/controllers/casein/casein_controller.rb +26 -24
- data/app/controllers/casein/password_resets_controller.rb +18 -21
- data/app/helpers/casein/casein_helper.rb +146 -155
- data/app/mailers/casein/casein_notification.rb +26 -27
- data/app/models/casein.rb +2 -0
- data/app/models/casein/admin_user.rb +50 -21
- data/app/models/casein/admin_user_session.rb +5 -3
- data/config/initializers/will_paginate.rb +12 -8
- data/config/routes.rb +10 -11
- data/lib/casein.rb +10 -8
- data/lib/casein/engine.rb +13 -14
- data/lib/casein/version.rb +4 -2
- data/lib/casein/version.rb.orig +10 -0
- data/lib/generators/casein/install/install_generator.rb +36 -35
- data/lib/generators/casein/install/templates/app/helpers/casein/config_helper.rb +8 -8
- data/lib/generators/casein/install/templates/db/migrate/casein_create_admin_users.rb +4 -4
- data/lib/generators/casein/scaffold/scaffold_generator.rb +31 -30
- data/lib/railties/tasks.rake +10 -12
- metadata +40 -39
@@ -1,31 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Casein
|
2
|
-
|
3
4
|
class CaseinNotification < ActionMailer::Base
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
def new_user_information from, casein_admin_user, host, pass
|
5
|
+
prepend_view_path File.join(File.dirname(__FILE__), '..', 'views', 'casein')
|
6
|
+
|
7
|
+
def generate_new_password(from, casein_admin_user, host, pass)
|
8
|
+
@name = casein_admin_user.name
|
9
|
+
@host = host
|
10
|
+
@login = casein_admin_user.login
|
11
|
+
@pass = pass
|
12
|
+
@from_text = casein_config_website_name
|
13
|
+
|
14
|
+
mail(to: casein_admin_user.email, from: from, subject: "[#{casein_config_website_name}] New password")
|
15
|
+
end
|
16
|
+
|
17
|
+
def new_user_information(from, casein_admin_user, host, pass)
|
18
18
|
@name = casein_admin_user.name
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
19
|
+
@host = host
|
20
|
+
@login = casein_admin_user.login
|
21
|
+
@pass = pass
|
22
|
+
@from_text = casein_config_website_name
|
23
|
+
|
24
|
+
mail(to: casein_admin_user.email, from: from, subject: "[#{casein_config_website_name}] New user account")
|
25
|
+
end
|
26
|
+
|
27
|
+
def password_reset_instructions(from, casein_admin_user, host)
|
28
|
+
ActionMailer::Base.default_url_options[:host] = host.gsub('http://', '')
|
29
29
|
@name = casein_admin_user.name
|
30
30
|
@host = host
|
31
31
|
@login = casein_admin_user.login
|
@@ -34,6 +34,5 @@ module Casein
|
|
34
34
|
|
35
35
|
mail(to: casein_admin_user.email, from: from, subject: "[#{casein_config_website_name}] Password reset instructions")
|
36
36
|
end
|
37
|
-
|
38
37
|
end
|
39
|
-
end
|
38
|
+
end
|
data/app/models/casein.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
include Casein::ConfigHelper
|
2
4
|
|
3
5
|
$CASEIN_USER_ACCESS_LEVEL_ADMIN = 0
|
@@ -5,55 +7,82 @@ $CASEIN_USER_ACCESS_LEVEL_USER = 10
|
|
5
7
|
|
6
8
|
module Casein
|
7
9
|
class AdminUser < ActiveRecord::Base
|
8
|
-
|
9
|
-
|
10
|
-
self.to_s.gsub("::", "_").tableize
|
10
|
+
def self.table_name
|
11
|
+
to_s.gsub('::', '_').tableize
|
11
12
|
end
|
12
13
|
|
13
14
|
acts_as_authentic do |c|
|
14
|
-
|
15
|
-
|
16
|
-
c.crypto_provider = Authlogic::CryptoProviders::SCrypt
|
15
|
+
c.transition_from_crypto_providers = [Authlogic::CryptoProviders::Sha512]
|
16
|
+
c.crypto_provider = Authlogic::CryptoProviders::SCrypt
|
17
17
|
end
|
18
18
|
|
19
19
|
attr_accessor :notify_of_new_password
|
20
|
-
|
20
|
+
|
21
21
|
after_create :send_create_notification
|
22
22
|
after_update :send_update_notification
|
23
23
|
before_validation :check_time_zone
|
24
|
-
|
24
|
+
|
25
25
|
validates_presence_of :login, :name, :email
|
26
26
|
validates_uniqueness_of :login
|
27
27
|
validates_format_of :email, with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
|
28
28
|
validates_presence_of :time_zone
|
29
|
-
|
30
|
-
|
29
|
+
|
30
|
+
# These default validations come from authlogic:
|
31
|
+
# https://github.com/binarylogic/authlogic/blob/master/doc/use_normal_rails_validation.md
|
32
|
+
validates :login,
|
33
|
+
format: {
|
34
|
+
with: /\A[a-zA-Z0-9_][a-zA-Z0-9\.+\-_@ ]+\z/,
|
35
|
+
message: proc {
|
36
|
+
::Authlogic::I18n.t(
|
37
|
+
'error_messages.login_invalid',
|
38
|
+
default: 'should use only letters, numbers, spaces, and .-_@+ please.'
|
39
|
+
)
|
40
|
+
}
|
41
|
+
},
|
42
|
+
length: { within: 3..100 },
|
43
|
+
uniqueness: {
|
44
|
+
case_sensitive: false,
|
45
|
+
if: :will_save_change_to_login?
|
46
|
+
}
|
47
|
+
|
48
|
+
validates :password,
|
49
|
+
confirmation: { if: :require_password? },
|
50
|
+
length: {
|
51
|
+
minimum: 8,
|
52
|
+
if: :require_password?
|
53
|
+
}
|
54
|
+
validates :password_confirmation,
|
55
|
+
length: {
|
56
|
+
minimum: 8,
|
57
|
+
if: :require_password?
|
58
|
+
}
|
59
|
+
|
60
|
+
def self.has_more_than_one_admin
|
31
61
|
Casein::AdminUser.where(access_level: $CASEIN_USER_ACCESS_LEVEL_ADMIN).count > 1
|
32
62
|
end
|
33
|
-
|
34
|
-
|
63
|
+
|
64
|
+
def send_create_notification
|
35
65
|
Casein::CaseinNotification.new_user_information(casein_config_email_from_address, self, casein_config_hostname, @password).deliver
|
36
66
|
end
|
37
|
-
|
67
|
+
|
38
68
|
def send_update_notification
|
39
69
|
if notify_of_new_password
|
40
70
|
notify_of_new_password = false
|
41
71
|
Casein::CaseinNotification.generate_new_password(casein_config_email_from_address, self, casein_config_hostname, @password).deliver
|
42
72
|
end
|
43
73
|
end
|
44
|
-
|
74
|
+
|
45
75
|
def send_password_reset_instructions
|
46
76
|
reset_perishable_token!
|
47
77
|
Casein::CaseinNotification.password_reset_instructions(casein_config_email_from_address, self, casein_config_hostname).deliver
|
48
78
|
end
|
49
|
-
|
79
|
+
|
50
80
|
def check_time_zone
|
51
|
-
self.time_zone = Rails.configuration.time_zone unless
|
81
|
+
self.time_zone = Rails.configuration.time_zone unless time_zone
|
82
|
+
end
|
83
|
+
|
84
|
+
def is_admin?
|
85
|
+
access_level == $CASEIN_USER_ACCESS_LEVEL_ADMIN
|
52
86
|
end
|
53
|
-
|
54
|
-
def is_admin?
|
55
|
-
access_level == $CASEIN_USER_ACCESS_LEVEL_ADMIN
|
56
|
-
end
|
57
|
-
|
58
87
|
end
|
59
88
|
end
|
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Casein
|
2
4
|
class AdminUserSession < ::Authlogic::Session::Base
|
3
|
-
include ActiveModel::Conversion
|
5
|
+
include ActiveModel::Conversion
|
4
6
|
extend ActiveModel::Naming
|
5
|
-
def persisted?
|
6
|
-
false
|
7
|
+
def persisted?
|
8
|
+
false
|
7
9
|
end
|
8
10
|
end
|
9
11
|
end
|
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# config/initializers/will_paginate.rb
|
2
|
-
#
|
4
|
+
#
|
3
5
|
# This extension code was written by Isaac Bowen, originally found
|
4
6
|
# at http://isaacbowen.com/blog/using-will_paginate-action_view-and-bootstrap/
|
5
7
|
|
@@ -7,20 +9,22 @@ require 'will_paginate/view_helpers/action_view'
|
|
7
9
|
|
8
10
|
module WillPaginate
|
9
11
|
module ActionView
|
10
|
-
|
11
12
|
def will_paginate(collection = nil, options = {})
|
12
|
-
|
13
|
+
if collection.is_a? Hash
|
14
|
+
options = collection
|
15
|
+
collection = nil
|
16
|
+
end
|
13
17
|
# Taken from original will_paginate code to handle if the helper is not passed a collection object.
|
14
|
-
collection ||= infer_collection_from_controller
|
18
|
+
collection ||= infer_collection_from_controller
|
15
19
|
options[:renderer] ||= BootstrapLinkRenderer
|
16
20
|
super.try :html_safe
|
17
21
|
end
|
18
22
|
|
19
23
|
class BootstrapLinkRenderer < LinkRenderer
|
20
24
|
protected
|
21
|
-
|
25
|
+
|
22
26
|
def html_container(html)
|
23
|
-
tag :div, tag(:ul, html, class:
|
27
|
+
tag :div, tag(:ul, html, class: 'pagination'), container_attributes
|
24
28
|
end
|
25
29
|
|
26
30
|
def page_number(page)
|
@@ -33,8 +37,8 @@ module WillPaginate
|
|
33
37
|
|
34
38
|
def previous_or_next_page(page, text, classname)
|
35
39
|
tag :li, link(text, page || '#'),
|
36
|
-
|
40
|
+
class: [(classname[0..3] if @options[:page_links]), (classname if @options[:page_links]), ('disabled' unless page)].join(' ')
|
37
41
|
end
|
38
42
|
end
|
39
43
|
end
|
40
|
-
end
|
44
|
+
end
|
data/config/routes.rb
CHANGED
@@ -1,20 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
Rails.application.routes.draw do
|
2
|
-
|
3
|
-
|
4
|
-
|
4
|
+
match '/admin' => redirect('/casein'), via: :get
|
5
|
+
|
5
6
|
namespace :casein do
|
6
|
-
|
7
7
|
resources :admin_users do
|
8
8
|
member do
|
9
9
|
patch :update_password, :reset_password
|
10
10
|
end
|
11
11
|
end
|
12
|
-
|
13
|
-
resource :admin_user_session, only: [
|
14
|
-
resource :password_reset, only: [
|
15
|
-
|
16
|
-
match
|
17
|
-
root to:
|
12
|
+
|
13
|
+
resource :admin_user_session, only: %i[new create destroy]
|
14
|
+
resource :password_reset, only: %i[create edit update]
|
15
|
+
|
16
|
+
match '/blank' => 'casein#blank', via: :get
|
17
|
+
root to: 'casein#index'
|
18
18
|
end
|
19
|
-
|
20
19
|
end
|
data/lib/casein.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
if defined?(Rails) && Rails::VERSION::MAJOR >= 5
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
require 'casein/engine'
|
5
|
+
require 'casein/version'
|
6
|
+
require 'will_paginate'
|
7
|
+
require 'authlogic'
|
6
8
|
else
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
9
|
+
puts('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
|
10
|
+
puts('!!! WARNING! This version of Casein requires Rails >= 5.x !!!')
|
11
|
+
puts('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
|
12
|
+
end
|
data/lib/casein/engine.rb
CHANGED
@@ -1,17 +1,18 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'casein'
|
4
|
+
require 'rails'
|
3
5
|
require 'bootstrap-sass'
|
4
6
|
require 'jquery-rails'
|
5
7
|
|
6
8
|
module Casein
|
7
9
|
class Engine < Rails::Engine
|
8
|
-
|
9
|
-
|
10
|
-
app.config.assets.precompile += %w(casein/login.css casein/casein.css casein/casein.js casein/html5shiv.js casein/custom.css casein/custom.js casein/auth_custom.css casein/auth_custom.js casein/*.png)
|
10
|
+
initializer 'casein.assets.precompile' do |app|
|
11
|
+
app.config.assets.precompile += %w[casein/login.css casein/casein.css casein/casein.js casein/html5shiv.js casein/custom.css casein/custom.js casein/auth_custom.css casein/auth_custom.js casein/*.png]
|
11
12
|
end
|
12
13
|
|
13
14
|
rake_tasks do
|
14
|
-
load
|
15
|
+
load 'railties/tasks.rake'
|
15
16
|
end
|
16
17
|
|
17
18
|
config.generators do |g|
|
@@ -20,16 +21,14 @@ module Casein
|
|
20
21
|
g.assets false
|
21
22
|
g.helper false
|
22
23
|
end
|
23
|
-
|
24
24
|
end
|
25
|
-
|
26
|
-
class RouteConstraint
|
27
25
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
26
|
+
class RouteConstraint
|
27
|
+
def matches?(request)
|
28
|
+
return false if request.fullpath.include?('/casein')
|
29
|
+
return false if request.fullpath.include?('/admin')
|
33
30
|
|
31
|
+
true
|
32
|
+
end
|
34
33
|
end
|
35
34
|
end
|
data/lib/casein/version.rb
CHANGED
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Casein
|
4
|
+
<<<<<<< HEAD
|
5
|
+
VERSION_HASH = { major: 5, minor: 4, patch: 0, build: 0 }
|
6
|
+
=======
|
7
|
+
VERSION_HASH = { major: 5, minor: 5, patch: 0, build: 0 }.freeze
|
8
|
+
>>>>>>> e30a2164a5c79f1cf607075d5e6a99dc014b74b6
|
9
|
+
VERSION = VERSION_HASH.values.join('.')
|
10
|
+
end
|
@@ -1,39 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Casein
|
2
4
|
class InstallGenerator < Rails::Generators::Base
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
"%.3d" % (current_migration_number(dirname) + 1)
|
12
|
-
end
|
5
|
+
include Rails::Generators::Migration
|
6
|
+
source_root File.expand_path('templates', __dir__)
|
7
|
+
|
8
|
+
def self.next_migration_number(dirname)
|
9
|
+
if ActiveRecord::Base.timestamped_migrations
|
10
|
+
Time.now.utc.strftime('%Y%m%d%H%M%S')
|
11
|
+
else
|
12
|
+
format('%.3d', (current_migration_number(dirname) + 1))
|
13
13
|
end
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
14
|
+
end
|
15
|
+
|
16
|
+
def generate_files
|
17
|
+
puts '*** WARNING - Generating configuration files. Make sure you have backed up any files before overwriting them. ***'
|
18
|
+
|
19
|
+
# config helper
|
20
|
+
copy_file 'app/helpers/casein/config_helper.rb', 'app/helpers/casein/config_helper.rb'
|
21
|
+
|
22
|
+
# initial view partials
|
23
|
+
copy_file 'app/views/casein/layouts/_tab_navigation.html.erb', 'app/views/casein/layouts/_tab_navigation.html.erb'
|
24
|
+
copy_file 'app/views/casein/layouts/_top_navigation.html.erb', 'app/views/casein/layouts/_top_navigation.html.erb'
|
25
|
+
|
26
|
+
# robots.txt
|
27
|
+
puts " ** Overwrite if you haven't yet modified your robots.txt, otherwise add disallow rules for /casein and /admin manually **"
|
28
|
+
copy_file 'public/robots.txt', 'public/robots.txt'
|
29
|
+
|
30
|
+
# blank stylesheets and JavaScript files
|
31
|
+
copy_file 'app/assets/stylesheets/casein/custom.scss', 'app/assets/stylesheets/casein/custom.scss'
|
32
|
+
copy_file 'app/assets/javascripts/casein/custom.js', 'app/assets/javascripts/casein/custom.js'
|
33
|
+
copy_file 'app/assets/stylesheets/casein/auth_custom.scss', 'app/assets/stylesheets/casein/auth_custom.scss'
|
34
|
+
copy_file 'app/assets/javascripts/casein/auth_custom.js', 'app/assets/javascripts/casein/auth_custom.js'
|
35
|
+
|
36
|
+
# migrations
|
37
|
+
migration_template 'db/migrate/casein_create_admin_users.rb', 'db/migrate/casein_create_admin_users.rb'
|
38
|
+
end
|
38
39
|
end
|
39
|
-
end
|
40
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Casein
|
2
4
|
module ConfigHelper
|
3
|
-
|
4
5
|
# Name of website or client — used throughout Casein.
|
5
6
|
def casein_config_website_name
|
6
7
|
'Casein'
|
@@ -24,32 +25,31 @@ module Casein
|
|
24
25
|
def casein_config_email_from_address
|
25
26
|
'donotreply@caseincms.com'
|
26
27
|
end
|
27
|
-
|
28
|
+
|
28
29
|
# The initial page the user is shown after they sign in or click the logo. Probably this should be set to the first tab.
|
29
30
|
# Do not point this at casein/index!
|
30
31
|
def casein_config_dashboard_url
|
31
32
|
url_for controller: :casein, action: :blank
|
32
33
|
end
|
33
|
-
|
34
|
+
|
34
35
|
# A list of stylesheets to include. Do not remove the core casein/casein, but you can change the load order, if required.
|
35
36
|
def casein_config_stylesheet_includes
|
36
37
|
%w[casein/casein casein/custom]
|
37
38
|
end
|
38
|
-
|
39
|
+
|
39
40
|
# A list of JavaScript files to include. Do not remove the core casein/casein, but you can change the load order, if required.
|
40
41
|
def casein_config_javascript_includes
|
41
42
|
%w[casein/casein casein/custom]
|
42
43
|
end
|
43
44
|
|
44
|
-
|
45
|
+
# A list of stylesheets to include in the authentication layout. Do not remove the core casein/login, but you can change the load order, if required.
|
45
46
|
def casein_config_auth_stylesheet_includes
|
46
47
|
%w[casein/login casein/auth_custom]
|
47
48
|
end
|
48
|
-
|
49
|
+
|
49
50
|
# A list of JavaScript files to includein the authentication layout. Do not remove the core casein/casein, but you can change the load order, if required.
|
50
51
|
def casein_config_auth_javascript_includes
|
51
52
|
%w[casein/casein casein/auth_custom]
|
52
53
|
end
|
53
|
-
|
54
54
|
end
|
55
|
-
end
|
55
|
+
end
|