thecore_auth_commons 3.3.0 → 3.3.2
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/app/models/user.rb +39 -2
- data/config/initializers/after_initialize.rb +0 -4
- data/config/locales/en.thecore_auth_commons.yml +1 -0
- data/config/locales/it.thecore_auth_commons.yml +1 -0
- data/lib/thecore_auth_commons/version.rb +1 -1
- metadata +2 -3
- data/config/initializers/concern_user.rb +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6658e7b11fc2130ad0e983ec82108eeb8b05b06cde2805066eb4f28ff56940f1
|
4
|
+
data.tar.gz: 0da3f0a0ce0e21eb8200e66d139ae4cbeda186ac2af3d2242455aeede8fcbbea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e364680b74013a0c40c0f10f1bfb008fcd79273e2be3b94ac1ca60fa6ffae78927115fa1bf8c1ce26b1e68d31780515527dfb36e958badfe68d5c825af167964
|
7
|
+
data.tar.gz: a747a61fe39467eb57c0f7edf4742dad4a49eda842398b92deaf32a678c2e40a3e3a119367d5c3c37d4814425309a65082968bf23327c5d3275934be3bbcf57e
|
data/app/models/user.rb
CHANGED
@@ -1,4 +1,41 @@
|
|
1
1
|
class User < ApplicationRecord
|
2
|
-
|
3
|
-
|
2
|
+
# Get the minimum password length from the Environemnt or set it to 8
|
3
|
+
devise :database_authenticatable, :rememberable, :trackable, :timeoutable, :validatable, password_length: ENV.fetch('MIN_PASSWORD_LENGTH', 8).to_i..128, timeout_in: ENV.fetch('SESSION_TIMEOUT_IN_MINUTES', 31).to_i.minutes
|
4
|
+
|
5
|
+
# REFERENCES
|
6
|
+
has_many :role_users, dependent: :destroy, inverse_of: :user
|
7
|
+
has_many :roles, through: :role_users, inverse_of: :users
|
8
|
+
# VALIDATIONS
|
9
|
+
validates :email, uniqueness: { case_sensitive: false }, presence: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i }
|
10
|
+
validates :password, presence: true, on: :create
|
11
|
+
validates :password_confirmation, presence: true, on: :create
|
12
|
+
validate :check_password_and_confirmation_equal
|
13
|
+
validates_each :password do |record, attr, value|
|
14
|
+
# Password must contain at least one uppercase letter, one lowercase letter, one number, and one special character or be blank
|
15
|
+
record.errors.add(attr, I18n.t("validation.errors.password_must_contain_uppercase_lowercase_number_special_character")) unless value.blank? || (value =~ /[A-Z]/ && value =~ /[a-z]/ && value =~ /[0-9]/ && value =~ /[^A-Za-z0-9]/)
|
16
|
+
end
|
17
|
+
validates_each :admin do |record, attr, value|
|
18
|
+
# Don't want admin == false if the current user is the only admin
|
19
|
+
record.errors.add(attr, I18n.t("validation.errors.cannot_unadmin_last_admin")) if record.admin_changed? && record.admin_was == true && User.where(admin: true).count == 1
|
20
|
+
end
|
21
|
+
validates_each :locked do |record, attr, value|
|
22
|
+
# Don't want locked == true if the current user is the only admin
|
23
|
+
record.errors.add(attr, I18n.t("validation.errors.cannot_lock_last_admin")) if record.locked_changed? && record.locked_was == false && User.where(locked: false).count == 1
|
24
|
+
end
|
25
|
+
|
26
|
+
def display_name
|
27
|
+
email
|
28
|
+
end
|
29
|
+
|
30
|
+
def has_role? role
|
31
|
+
roles.include? role.to_s
|
32
|
+
end
|
33
|
+
|
34
|
+
def authenticate password
|
35
|
+
self&.valid_password?(password) ? self : nil
|
36
|
+
end
|
37
|
+
|
38
|
+
def check_password_and_confirmation_equal
|
39
|
+
errors.add(:password, I18n.t("validation.errors.password_and_confirm_must_be_the_same")) unless password == password_confirmation
|
40
|
+
end
|
4
41
|
end
|
@@ -3,11 +3,7 @@ Rails.application.configure do
|
|
3
3
|
# In development be sure to load all the namespaces
|
4
4
|
# in order to have working reflection
|
5
5
|
Zeitwerk::Loader.eager_load_all if Rails.env.development?
|
6
|
-
|
7
|
-
# Devise.timeout_in = ENV.fetch('SESSION_TIMEOUT_IN_MINUTES', 31).to_i.minutes
|
8
|
-
# Devise.password_length = ENV.fetch('MIN_PASSWORD_LENGTH', 8).to_i..128
|
9
6
|
|
10
7
|
Ability.send(:include, ThecoreAuthCommonsCanCanCanConcern)
|
11
|
-
User.send(:include, ThecoreAuthCommonsUserConcern)
|
12
8
|
end
|
13
9
|
end
|
@@ -5,6 +5,7 @@ en:
|
|
5
5
|
password_requires_special_characters: "must contain at least one special character"
|
6
6
|
validation:
|
7
7
|
errors:
|
8
|
+
password_and_confirm_must_be_the_same: "passwords must be the same"
|
8
9
|
password_must_contain_uppercase_lowercase_number_special_character: "must contain at least one uppercase letter, one lowercase letter, one number and one special character"
|
9
10
|
cannot_unadmin_last_admin: "at least one user must be an administrator"
|
10
11
|
cannot_unlock_last_admin: "at least one user must be unlocked"
|
@@ -5,6 +5,7 @@ it:
|
|
5
5
|
password_requires_special_characters: "deve contenere almeno un carattere speciale"
|
6
6
|
validation:
|
7
7
|
errors:
|
8
|
+
password_and_confirm_must_be_the_same: "le password devono essere uguali"
|
8
9
|
password_must_contain_uppercase_lowercase_number_special_character: "deve contenere almeno una lettera maiuscola, una lettera minuscola, un numero e un carattere speciale"
|
9
10
|
cannot_unadmin_last_admin: "almeno un utente deve essere un amministratore"
|
10
11
|
cannot_unlock_last_admin: "almeno un utente deve essere sbloccato"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thecore_auth_commons
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.3.
|
4
|
+
version: 3.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriele Tassoni
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-03-24 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: devise
|
@@ -191,7 +191,6 @@ files:
|
|
191
191
|
- config/initializers/add_to_db_migrations.rb
|
192
192
|
- config/initializers/after_initialize.rb
|
193
193
|
- config/initializers/concern_cancancan.rb
|
194
|
-
- config/initializers/concern_user.rb
|
195
194
|
- config/locales/en.permissions.yml
|
196
195
|
- config/locales/en.thecore_auth_commons.yml
|
197
196
|
- config/locales/it.permissions.yml
|
@@ -1,42 +0,0 @@
|
|
1
|
-
module ThecoreAuthCommonsUserConcern
|
2
|
-
extend ActiveSupport::Concern
|
3
|
-
|
4
|
-
included do
|
5
|
-
# REFERENCES
|
6
|
-
has_many :role_users, dependent: :destroy, inverse_of: :user
|
7
|
-
has_many :roles, through: :role_users, inverse_of: :users
|
8
|
-
# VALIDATIONS
|
9
|
-
validates :email, uniqueness: { case_sensitive: false }, presence: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i }
|
10
|
-
validates :password, presence: true, on: :create
|
11
|
-
validates :password_confirmation, presence: true, on: :create
|
12
|
-
validate :check_password_and_confirmation_equal
|
13
|
-
validates_each :password do |record, attr, value|
|
14
|
-
# Password must contain at least one uppercase letter, one lowercase letter, one number, and one special character or be blank
|
15
|
-
record.errors.add(attr, I18n.t("validation.errors.password_must_contain_uppercase_lowercase_number_special_character")) unless value.blank? || (value =~ /[A-Z]/ && value =~ /[a-z]/ && value =~ /[0-9]/ && value =~ /[^A-Za-z0-9]/)
|
16
|
-
end
|
17
|
-
validates_each :admin do |record, attr, value|
|
18
|
-
# Don't want admin == false if the current user is the only admin
|
19
|
-
record.errors.add(attr, I18n.t("validation.errors.cannot_unadmin_last_admin")) if record.admin_changed? && record.admin_was == true && User.where(admin: true).count == 1
|
20
|
-
end
|
21
|
-
validates_each :locked do |record, attr, value|
|
22
|
-
# Don't want locked == true if the current user is the only admin
|
23
|
-
record.errors.add(attr, I18n.t("validation.errors.cannot_lock_last_admin")) if record.locked_changed? && record.locked_was == false && User.where(locked: false).count == 1
|
24
|
-
end
|
25
|
-
|
26
|
-
def display_name
|
27
|
-
email
|
28
|
-
end
|
29
|
-
|
30
|
-
def has_role? role
|
31
|
-
roles.include? role.to_s
|
32
|
-
end
|
33
|
-
|
34
|
-
def authenticate password
|
35
|
-
self&.valid_password?(password) ? self : nil
|
36
|
-
end
|
37
|
-
|
38
|
-
def check_password_and_confirmation_equal
|
39
|
-
errors.add(:password, I18n.t("validation.errors.password_and_confirm_must_be_the_same")) unless password == password_confirmation
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|