casein 5.3.0.0 → 5.5.1.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.
@@ -1,31 +1,31 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Casein
2
-
3
4
  class CaseinNotification < ActionMailer::Base
4
-
5
- self.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
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
- @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://", "")
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,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Casein
2
4
  end
@@ -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,79 @@ $CASEIN_USER_ACCESS_LEVEL_USER = 10
5
7
 
6
8
  module Casein
7
9
  class AdminUser < ActiveRecord::Base
8
-
9
- def self.table_name
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
- c.validate_email_field = false
15
- c.transition_from_crypto_providers = [Authlogic::CryptoProviders::Sha512]
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
- def self.has_more_than_one_admin
29
+
30
+ # These default validations come from authlogic:
31
+ # https://github.com/binarylogic/authlogic/blob/master/doc/use_normal_rails_validation.md
32
+ # Note that Casein uses a case-sensitive uniqueness validation for :login, so we remove that config
33
+ validates :login,
34
+ format: {
35
+ with: /\A[a-zA-Z0-9_][a-zA-Z0-9\.+\-_@ ]+\z/,
36
+ message: proc {
37
+ ::Authlogic::I18n.t(
38
+ 'error_messages.login_invalid',
39
+ default: 'should use only letters, numbers, spaces, and .-_@+ please.'
40
+ )
41
+ }
42
+ },
43
+ length: { within: 3..100 }
44
+
45
+ validates :password,
46
+ confirmation: { if: :require_password? },
47
+ length: {
48
+ minimum: 8,
49
+ if: :require_password?
50
+ }
51
+ validates :password_confirmation,
52
+ length: {
53
+ minimum: 8,
54
+ if: :require_password?
55
+ }
56
+
57
+ def self.has_more_than_one_admin
31
58
  Casein::AdminUser.where(access_level: $CASEIN_USER_ACCESS_LEVEL_ADMIN).count > 1
32
59
  end
33
-
34
- def send_create_notification
60
+
61
+ def send_create_notification
35
62
  Casein::CaseinNotification.new_user_information(casein_config_email_from_address, self, casein_config_hostname, @password).deliver
36
63
  end
37
-
64
+
38
65
  def send_update_notification
39
66
  if notify_of_new_password
40
67
  notify_of_new_password = false
41
68
  Casein::CaseinNotification.generate_new_password(casein_config_email_from_address, self, casein_config_hostname, @password).deliver
42
69
  end
43
70
  end
44
-
71
+
45
72
  def send_password_reset_instructions
46
73
  reset_perishable_token!
47
74
  Casein::CaseinNotification.password_reset_instructions(casein_config_email_from_address, self, casein_config_hostname).deliver
48
75
  end
49
-
76
+
50
77
  def check_time_zone
51
- self.time_zone = Rails.configuration.time_zone unless self.time_zone
78
+ self.time_zone = Rails.configuration.time_zone unless time_zone
79
+ end
80
+
81
+ def is_admin?
82
+ access_level == $CASEIN_USER_ACCESS_LEVEL_ADMIN
52
83
  end
53
-
54
- def is_admin?
55
- access_level == $CASEIN_USER_ACCESS_LEVEL_ADMIN
56
- end
57
-
58
84
  end
59
85
  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
- options, collection = collection, nil if collection.is_a? Hash
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: "pagination"), container_attributes
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
- class: [(classname[0..3] if @options[:page_links]), (classname if @options[:page_links]), ('disabled' unless page)].join(' ')
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
- match "/admin" => redirect("/casein"), via: :get
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: [:new, :create, :destroy]
14
- resource :password_reset, only: [:create, :edit, :update]
15
-
16
- match "/blank" => "casein#blank", via: :get
17
- root to: "casein#index"
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
- require 'casein/engine'
3
- require 'casein/version'
4
- require 'will_paginate'
5
- require 'authlogic'
4
+ require 'casein/engine'
5
+ require 'casein/version'
6
+ require 'will_paginate'
7
+ require 'authlogic'
6
8
  else
7
- puts("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
8
- puts("!!! WARNING! This version of Casein requires Rails >= 5.x !!!")
9
- puts("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
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
- require "casein"
2
- require "rails"
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
- initializer "casein.assets.precompile" do |app|
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 "railties/tasks.rake"
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
- def matches?(request)
29
- return false if request.fullpath.include?("/casein")
30
- return false if request.fullpath.include?("/admin")
31
- true
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
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Casein
2
- VERSION_HASH = { major: 5, minor: 3, patch: 0, build: 0 }
3
- VERSION = VERSION_HASH.values.join(".")
4
+ VERSION_HASH = { major: 5, minor: 5, patch: 1, build: 0 }
5
+ VERSION = VERSION_HASH.values.join('.')
4
6
  end
@@ -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
- include Rails::Generators::Migration
5
- source_root File.expand_path('../templates', __FILE__)
6
-
7
- def self.next_migration_number dirname
8
- if ActiveRecord::Base.timestamped_migrations
9
- Time.now.utc.strftime("%Y%m%d%H%M%S")
10
- else
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
- def generate_files
16
- puts "*** WARNING - Generating configuration files. Make sure you have backed up any files before overwriting them. ***"
17
-
18
- #config helper
19
- copy_file "app/helpers/casein/config_helper.rb", "app/helpers/casein/config_helper.rb"
20
-
21
- #initial view partials
22
- copy_file "app/views/casein/layouts/_tab_navigation.html.erb", "app/views/casein/layouts/_tab_navigation.html.erb"
23
- copy_file "app/views/casein/layouts/_top_navigation.html.erb", "app/views/casein/layouts/_top_navigation.html.erb"
24
-
25
- #robots.txt
26
- puts " ** Overwrite if you haven't yet modified your robots.txt, otherwise add disallow rules for /casein and /admin manually **"
27
- copy_file "public/robots.txt", "public/robots.txt"
28
-
29
- #blank stylesheets and JavaScript files
30
- copy_file "app/assets/stylesheets/casein/custom.scss", "app/assets/stylesheets/casein/custom.scss"
31
- copy_file "app/assets/javascripts/casein/custom.js", "app/assets/javascripts/casein/custom.js"
32
- copy_file "app/assets/stylesheets/casein/auth_custom.scss", "app/assets/stylesheets/casein/auth_custom.scss"
33
- copy_file "app/assets/javascripts/casein/auth_custom.js", "app/assets/javascripts/casein/auth_custom.js"
34
-
35
- #migrations
36
- migration_template 'db/migrate/casein_create_admin_users.rb', "db/migrate/casein_create_admin_users.rb"
37
- end
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
- # 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
+ # 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