minimalist_authentication 3.2.0 → 3.2.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b81e23298baa784d92be34aa1b6b372f585c5ea8bba51d953a85ee39ec44db5
|
4
|
+
data.tar.gz: 2cad820418a3869931fad968063d3f97e7302686b1fd534daf3a1c9f0d5dda15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b5cd0f9f672f3084884b5385d333705d21d9835738e0b79ba8bc10853bc8bf5cbec88451ff07db26844a601fc69e685fe3f5e3961c5dbcd3616033d9cfe781a
|
7
|
+
data.tar.gz: 183194ef85c0ed224f9550c95779ecc5d37b6437ea0b05cd2e2cc32c43785d6718639bc1e4b74997df0fedf93432366e7240bc1e1d6b440008210ce64f277134
|
@@ -14,7 +14,7 @@ class PasswordsController < ApplicationController
|
|
14
14
|
|
15
15
|
# Update user's password
|
16
16
|
def update
|
17
|
-
if user.update(password_params
|
17
|
+
if user.update(password_params)
|
18
18
|
redirect_to new_session_path, notice: t(".notice")
|
19
19
|
else
|
20
20
|
render :edit, status: :unprocessable_entity
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class PasswordExclusivityValidator < ActiveModel::EachValidator
|
4
|
+
# Ensure password does not match username or email.
|
5
|
+
def validate_each(record, attribute, value)
|
6
|
+
%w[username email].each do |field|
|
7
|
+
record.errors.add(attribute, "can not match #{field}") if value.casecmp?(record.try(field))
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -15,9 +15,6 @@ module MinimalistAuthentication
|
|
15
15
|
password_salt.last(10)
|
16
16
|
end
|
17
17
|
|
18
|
-
# Force validations for a blank password.
|
19
|
-
attribute :password_required, :boolean, default: false
|
20
|
-
|
21
18
|
# Email validations
|
22
19
|
validates(
|
23
20
|
:email,
|
@@ -29,10 +26,13 @@ module MinimalistAuthentication
|
|
29
26
|
|
30
27
|
# Password validations
|
31
28
|
# Adds validations for minimum password length and exclusivity.
|
32
|
-
# has_secure_password
|
33
|
-
|
34
|
-
|
35
|
-
|
29
|
+
# has_secure_password includes validations for presence, maximum length, confirmation, and password_challenge.
|
30
|
+
validates(
|
31
|
+
:password,
|
32
|
+
password_exclusivity: true,
|
33
|
+
length: { minimum: :password_minimum },
|
34
|
+
allow_blank: true
|
35
|
+
)
|
36
36
|
|
37
37
|
# Active scope
|
38
38
|
scope :active, ->(state = true) { where(active: state) }
|
@@ -74,15 +74,9 @@ module MinimalistAuthentication
|
|
74
74
|
active?
|
75
75
|
end
|
76
76
|
|
77
|
-
# Remove the has_secure_password password blank error if
|
77
|
+
# Remove the has_secure_password password blank error if user is inactive.
|
78
78
|
def errors
|
79
|
-
super.tap { |errors| errors.delete(:password, :blank)
|
80
|
-
end
|
81
|
-
|
82
|
-
# Returns true if the user is not active.
|
83
|
-
def inactive?
|
84
|
-
MinimalistAuthentication.deprecator.warn("Calling #inactive? is deprecated.")
|
85
|
-
!active?
|
79
|
+
super.tap { |errors| errors.delete(:password, :blank) if inactive? }
|
86
80
|
end
|
87
81
|
|
88
82
|
# Returns true if password matches the hashed_password, otherwise returns false.
|
@@ -98,37 +92,23 @@ module MinimalistAuthentication
|
|
98
92
|
email == GUEST_USER_EMAIL
|
99
93
|
end
|
100
94
|
|
95
|
+
# Returns true if the user is not active.
|
96
|
+
def inactive?
|
97
|
+
!active?
|
98
|
+
end
|
99
|
+
|
101
100
|
# Sets #last_logged_in_at to the current time without updating the updated_at timestamp.
|
102
101
|
def logged_in
|
103
102
|
update_column(:last_logged_in_at, Time.current)
|
104
103
|
end
|
105
104
|
|
106
|
-
# Checks for password presence
|
107
|
-
def password?
|
108
|
-
password.present?
|
109
|
-
end
|
110
|
-
|
111
105
|
private
|
112
106
|
|
113
|
-
# Ensure password does not match username or email.
|
114
|
-
def password_exclusivity
|
115
|
-
%w[username email].each do |field|
|
116
|
-
errors.add(:password, "can not match #{field}") if password.casecmp?(try(field))
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
107
|
# Return true if the user matches the owner of the provided token.
|
121
108
|
def token_owner?(purpose, token)
|
122
109
|
self.class.find_by_token_for(purpose, token) == self
|
123
110
|
end
|
124
111
|
|
125
|
-
# Require password for active users that either do no have a password hash
|
126
|
-
# stored OR are attempting to set a new password. Set **password_required**
|
127
|
-
# to true to force validations even when the password field is blank.
|
128
|
-
def validate_password?
|
129
|
-
active? && (password_digest.blank? || password? || password_required?)
|
130
|
-
end
|
131
|
-
|
132
112
|
# Validate email for all users.
|
133
113
|
# Applications can turn off email validation by setting the validate_email
|
134
114
|
# configuration attribute to false.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minimalist_authentication
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.2.
|
4
|
+
version: 3.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Baldwin
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-11-
|
12
|
+
date: 2024-11-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bcrypt
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- app/helpers/minimalist_authentication/application_helper.rb
|
64
64
|
- app/mailers/application_mailer.rb
|
65
65
|
- app/mailers/minimalist_authentication_mailer.rb
|
66
|
+
- app/validators/password_exclusivity_validator.rb
|
66
67
|
- app/views/email_verifications/new.html.erb
|
67
68
|
- app/views/email_verifications/show.html.erb
|
68
69
|
- app/views/emails/edit.html.erb
|