minimalist_authentication 2.5.2 → 2.6.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: 84db557ccbc7f085f52ff84ffedd5f174e8e3b14e7a2364389fe256b8373c120
4
- data.tar.gz: fec50087c8cb8098e16d57fbf429096dbc43c87d66d9155947dd807cc54e5c99
3
+ metadata.gz: 7729e88f86ac9b5f9a20bc3ea20376c3ca4357cba72ee64fd9ff6b43f303d33f
4
+ data.tar.gz: 263033c938eabe257b2059d0d04ca032b5f7ff49d718c78146e125fd719dcb6e
5
5
  SHA512:
6
- metadata.gz: bca2d80847868c1929355733baab209436d7cfb0caa09289371626fa199924171e13359e2b3c38403cb30e8038614652cd042f903321622dfaca3d1582e179f3
7
- data.tar.gz: ceed88e53ee975e757c9fd939e2e68a838f9219cfe8afd7b4a266f907521ecc5c70f15b68376f4f2764f52944709e9e0ef4a6f7a9554ae54ca3b87ce97a8a001
6
+ metadata.gz: a722621655bbd7edaf447364ecd240239a2178824d503a152f2d420080eed6735f4f701a43ff2d9476fc1cf20f1875b1519c075a6cfea5a7f8f81a0816a425d3
7
+ data.tar.gz: a0b0879d07451c6c0567578d199746326524c38c36d55aaf3315f7f9f355d05d98884628a7df30ec8befd79c29751a6ea6440f983512cb9953f89a3b931d9e9f
data/README.md CHANGED
@@ -62,7 +62,7 @@ end
62
62
  ```
63
63
 
64
64
  ## Configuration
65
- Customize the configuration with an initializer. Create a **minimalist_authentication.rb** file in /Users/baldwina/git/brightways/config/initializers.
65
+ Customize the configuration with an initializer. Create a **minimalist_authentication.rb** file in config/initializers.
66
66
  ```ruby
67
67
  MinimalistAuthentication.configure do |configuration|
68
68
  configuration.user_model_name = 'CustomModelName' # default is '::User'
@@ -84,7 +84,7 @@ fixture users.
84
84
  ```yaml
85
85
  example_user:
86
86
  email: user@example.com
87
- password_hash: <%= MinimalistAuthentication::Password.create('password') %>
87
+ password_hash: <%= MinimalistAuthentication::Password.create("test-password") %>
88
88
  ```
89
89
 
90
90
 
@@ -25,7 +25,7 @@ class PasswordResetsController < ApplicationController
25
25
  def user
26
26
  return unless URI::MailTo::EMAIL_REGEXP.match?(email)
27
27
 
28
- @user ||= MinimalistAuthentication.configuration.user_model.active.email_verified.find_by(email: email)
28
+ @user ||= MinimalistAuthentication.configuration.user_model.active.email_verified.find_by(email:)
29
29
  end
30
30
 
31
31
  def email
@@ -21,7 +21,7 @@ module MinimalistAuthentication
21
21
  field = (hash.keys & LOGIN_FIELDS).first
22
22
 
23
23
  # Attempt to authenticate user
24
- new(field: field, value: hash[field], password: hash["password"]).authenticated_user
24
+ new(field:, value: hash[field], password: hash["password"]).authenticated_user
25
25
  end
26
26
 
27
27
  def initialize(field:, value:, password:)
@@ -15,7 +15,7 @@ module MinimalistAuthentication
15
15
  private
16
16
 
17
17
  def current_user
18
- @current_user ||= (find_session_user || MinimalistAuthentication.configuration.user_model.guest)
18
+ @current_user ||= find_session_user || MinimalistAuthentication.configuration.user_model.guest
19
19
  end
20
20
 
21
21
  def find_session_user
@@ -5,7 +5,7 @@ module MinimalistAuthentication
5
5
  class MergePasswordHash
6
6
  class << self
7
7
  def run!
8
- user_model.where(using_digest_version: 3, password_hash: nil).each do |user|
8
+ user_model.where(using_digest_version: 3, password_hash: nil).find_each do |user|
9
9
  new(user).update!
10
10
  end
11
11
  end
@@ -66,12 +66,12 @@ module MinimalistAuthentication
66
66
  end
67
67
 
68
68
  def attempting_to_verify?
69
- # check if user is attpting to verify their email
69
+ # check if user is attempting to verify their email
70
70
  session["return_to"].to_s[/token/]
71
71
  end
72
72
 
73
73
  def after_authentication_failure
74
- flash.now.alert = t(".alert", identifier: identifier)
74
+ flash.now.alert = t(".alert", identifier:)
75
75
  user
76
76
  render :new, status: :unprocessable_entity
77
77
  end
@@ -2,8 +2,10 @@
2
2
 
3
3
  module MinimalistAuthentication
4
4
  module TestHelper
5
- def login_as(user_fixture_name, password = "password")
6
- post session_path, params: { user: { email: users(user_fixture_name).email, password: password } }
5
+ PASSWORD = "test-password"
6
+
7
+ def login_as(user_fixture_name, password = PASSWORD)
8
+ post session_path, params: { user: { email: users(user_fixture_name).email, password: } }
7
9
  end
8
10
 
9
11
  def current_user
@@ -6,16 +6,14 @@ module MinimalistAuthentication
6
6
  module User
7
7
  extend ActiveSupport::Concern
8
8
 
9
- GUEST_USER_EMAIL = "guest"
10
- PASSWORD_MIN = 8
11
- PASSWORD_MAX = 40
9
+ GUEST_USER_EMAIL = "guest"
12
10
 
13
11
  included do
14
12
  # Stores the plain text password.
15
- attr_accessor :password
13
+ attribute :password, :string
16
14
 
17
15
  # Force validations for a blank password.
18
- attr_accessor :password_required
16
+ attribute :password_required, :boolean, default: false
19
17
 
20
18
  # Hashes and stores the password on save.
21
19
  before_save :hash_password
@@ -33,7 +31,7 @@ module MinimalistAuthentication
33
31
  validates(
34
32
  :password,
35
33
  confirmation: true,
36
- length: { within: PASSWORD_MIN..PASSWORD_MAX },
34
+ length: { minimum: :password_minimum, maximum: :password_maximum },
37
35
  presence: true,
38
36
  if: :validate_password?
39
37
  )
@@ -87,11 +85,19 @@ module MinimalistAuthentication
87
85
  guest?
88
86
  end
89
87
 
88
+ # Minimum password length
89
+ def password_minimum = 12
90
+
91
+ # Maximum password length
92
+ def password_maximum = 40
93
+
90
94
  private
91
95
 
92
- # Set self.password to password, hash, and save
96
+ # Set self.password to password, hash, and save if user is valid.
93
97
  def update_hash!(password)
94
98
  self.password = password
99
+ return unless valid?
100
+
95
101
  hash_password
96
102
  save
97
103
  end
@@ -103,7 +109,7 @@ module MinimalistAuthentication
103
109
  self.password_hash = Password.create(password)
104
110
  end
105
111
 
106
- # Retuns a MinimalistAuthentication::Password object.
112
+ # Returns a MinimalistAuthentication::Password object.
107
113
  def password_object
108
114
  Password.new(password_hash)
109
115
  end
@@ -112,7 +118,7 @@ module MinimalistAuthentication
112
118
  # stored OR are attempting to set a new password. Set **password_required**
113
119
  # to true to force validations even when the password field is blank.
114
120
  def validate_password?
115
- active? && (password_hash.blank? || password.present? || password_required)
121
+ active? && (password_hash.blank? || password? || password_required?)
116
122
  end
117
123
 
118
124
  # Validate email for active users.
@@ -15,7 +15,7 @@ module MinimalistAuthentication
15
15
  if matches_verification_token?(token)
16
16
  update(attributes) && clear_token
17
17
  else
18
- errors.add(:base, "Verfication token check failed")
18
+ errors.add(:base, "Verification token check failed")
19
19
  false
20
20
  end
21
21
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MinimalistAuthentication
4
- VERSION = "2.5.2"
4
+ VERSION = "2.6.1"
5
5
  end
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: 2.5.2
4
+ version: 2.6.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: 2023-10-19 00:00:00.000000000 Z
12
+ date: 2024-07-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bcrypt
@@ -106,14 +106,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
106
  requirements:
107
107
  - - ">="
108
108
  - !ruby/object:Gem::Version
109
- version: 2.7.0
109
+ version: 3.1.0
110
110
  required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  requirements:
112
112
  - - ">="
113
113
  - !ruby/object:Gem::Version
114
114
  version: '0'
115
115
  requirements: []
116
- rubygems_version: 3.4.15
116
+ rubygems_version: 3.5.11
117
117
  signing_key:
118
118
  specification_version: 4
119
119
  summary: A Rails authentication plugin that takes a minimalist approach.