-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump rails from 7.0.8 to 7.1.1 (#60)
* Bump rails from 7.0.8 to 7.1.1 Bumps [rails](https://github.com/rails/rails) from 7.0.8 to 7.1.1. - [Release notes](https://github.com/rails/rails/releases) - [Commits](rails/rails@v7.0.8...v7.1.1) --- updated-dependencies: - dependency-name: rails dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * Update gemset.nix * Opt-in to new rails 7.1 features --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: robbe[bot] <[email protected]> Co-authored-by: Robbe Van Petegem <[email protected]>
- Loading branch information
1 parent
1847b1d
commit b623899
Showing
10 changed files
with
234 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
class User < ApplicationRecord | ||
# NOTE: Delete when upgrading to rails 7.1 | ||
attr_accessor :password_challenge | ||
|
||
has_secure_password | ||
|
||
generates_token_for :password_reset, expires_in: 1.hour do | ||
BCrypt::Password.new(password_digest).salt.last(10) | ||
end | ||
|
||
has_many :feeds, dependent: :destroy | ||
|
||
before_validation :normalize_email | ||
normalizes :email, with: ->(email) { email&.strip&.downcase } | ||
|
||
validates :email, presence: true, uniqueness: { case_sensitive: false }, | ||
# The basic regex to validate emails was taken from devise | ||
# See: https://github.com/heartcombo/devise/blob/9f80dc2562524f744e8633b8562f2a0114efb32b/lib/generators/templates/devise.rb#L186 | ||
format: { with: /\A[^@\s]+@[^@\s]+\z/ } | ||
validates :password_digest, presence: true | ||
validates :password, length: { minimum: 12 }, allow_nil: true | ||
# NOTE: Delete when upgrading to rails 7.1 | ||
validate :check_password_challenge | ||
|
||
# Reset password | ||
# NOTE: Replace with `generates_token_for` when upgrading to rails 7.1 | ||
def self.token_verifier | ||
@token_verifier ||= Rails.application.message_verifier('feed_reader/user_token') | ||
end | ||
|
||
def self.find_by_password_reset_token(password_reset_token) | ||
payload = token_verifier.verified(password_reset_token) | ||
user = find_by(id: payload && payload[0]) | ||
return nil if user.nil? | ||
|
||
salt = BCrypt::Password.new(user.password_digest).salt[-10..] | ||
user if payload == [user.id, salt] | ||
end | ||
|
||
def password_reset_token(expires_in: nil) | ||
# We use the current password digest to generate a token | ||
# This way a changed password, will cause the token to be invalid | ||
salt = BCrypt::Password.new(password_digest).salt[-10..] | ||
self.class.token_verifier.generate([id, salt], expires_in:) | ||
end | ||
|
||
private | ||
|
||
def normalize_email | ||
email&.strip!&.downcase! | ||
end | ||
|
||
def check_password_challenge | ||
return if password_challenge.nil? | ||
return if password_digest_was.present? && BCrypt::Password.new(password_digest_was).is_password?(password_challenge) | ||
|
||
errors.add(:password_challenge) | ||
end | ||
end |
Oops, something went wrong.