revise_auth 0.2.0 → 0.3.0

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: 9fac687711be2bb236ceab0cb252c397a71775ccd00bf3e2b77ab61888555d16
4
- data.tar.gz: 4ce79cc15599316b649ea7e8ef3c1c54cd1c74f4ce0bb26685932b7c4c4e3303
3
+ metadata.gz: f5d5afd1201c6a751a50e0c153589fa552e949c45cad6da9f3147670e6aaf274
4
+ data.tar.gz: 9d546d451af57bbc97d4e6dbae0dc83b00b6818fa14210f1a32735f79295686e
5
5
  SHA512:
6
- metadata.gz: 9cb6ca3ca5f50d741c5e5ee319f438f1912496ab4c1f025c6225f6b6297f5dc94b06d025ed2f95e75bc56f8dc2915e81f8cf05af2faa08fc8dc537f811fc0428
7
- data.tar.gz: 5c861bee5d4506055a967a8d755ac6b3959ccdcd5b399544f00444330ef52fa99e83abe536bed22be4868fca47202332bec38e8dfa0ad75a442acfb11798d296
6
+ metadata.gz: 39331cdedcd79bc56c9237436bbf844ea5b1b863242b3cf4b5935a48bc492e2ebfdc8d5e5bc987f92b22556f58558876e418e94c2850d1eb0be659e54067ec1e
7
+ data.tar.gz: d1a39f4b6f81989be85657b540fcad3f0fbcb0a52ea3b184ea86263391ea204e192adf7038e164da190c03d6837da4c2ce8f3157779b6489cad65981e78f877f
data/README.md CHANGED
@@ -14,7 +14,7 @@ bundle add "revise_auth"
14
14
 
15
15
  And then execute the following to generate a `User` model (optionally adding other fields such as `first_name` and `last_name`):
16
16
  ```bash
17
- $ rails g revise_auth:model first_name last_name
17
+ $ rails g revise_auth:model User first_name last_name
18
18
  $ rails db:migrate
19
19
  ```
20
20
 
@@ -3,9 +3,8 @@ class ReviseAuth::EmailController < ReviseAuthController
3
3
 
4
4
  # GET /profile/email?confirmation_token=abcdef
5
5
  def show
6
- if User.find_by(confirmation_token: params[:confirmation_token])&.confirm_email_change
6
+ if User.find_by_token_for(:email_verification, params[:confirmation_token])&.confirm_email_change
7
7
  flash[:notice] = I18n.t("revise_auth.email_confirmed")
8
- user_signed_in?
9
8
  redirect_to(user_signed_in? ? profile_path : root_path)
10
9
  else
11
10
  redirect_to root_path, alert: I18n.t("revise_auth.email_confirm_failed")
@@ -1,5 +1,8 @@
1
1
  class ReviseAuth::Mailer < ApplicationMailer
2
2
  def confirm_email
3
- mail to: params[:user].unconfirmed_email
3
+ @user = params[:user]
4
+ @token = params[:token]
5
+
6
+ mail to: @user.unconfirmed_email
4
7
  end
5
8
  end
@@ -1,7 +1,7 @@
1
- <p>Welcome <%= params[:user].unconfirmed_email %>!</p>
1
+ <p>Welcome <%= @user.unconfirmed_email %>!</p>
2
2
 
3
3
  <p>You can confirm your account email through the link below:</p>
4
4
 
5
- <p><%= link_to 'Confirm my account', profile_email_url(confirmation_token: params[:user].confirmation_token) %></p>
5
+ <p><%= link_to "Confirm my account", profile_email_url(confirmation_token: @token) %></p>
6
6
 
7
7
  <p>This link will expire in 24 hours.</p>
@@ -47,9 +47,7 @@ module ReviseAuth
47
47
  [
48
48
  "email:string:index",
49
49
  "password_digest:string",
50
- "confirmation_token:string",
51
50
  "confirmed_at:datetime",
52
- "confirmation_sent_at:datetime",
53
51
  "unconfirmed_email:string"
54
52
  ] + @original_attributes
55
53
  end
@@ -2,12 +2,16 @@ module ReviseAuth
2
2
  module Model
3
3
  extend ActiveSupport::Concern
4
4
 
5
- included do
6
- include Backports if Rails.gem_version < Gem::Version.new("7.1")
5
+ included do |base|
6
+ base.const_set :EMAIL_VERIFICATION_TOKEN_VALIDITY, 1.day
7
7
 
8
8
  has_secure_password
9
9
  has_secure_token :confirmation_token
10
10
 
11
+ generates_token_for :email_verification, expires_in: base.const_get(:EMAIL_VERIFICATION_TOKEN_VALIDITY) do
12
+ email
13
+ end
14
+
11
15
  validates :email, format: {with: URI::MailTo::EMAIL_REGEXP}, presence: true, uniqueness: true
12
16
  validates :unconfirmed_email, format: {with: URI::MailTo::EMAIL_REGEXP}, allow_blank: true
13
17
  validates_length_of :password, minimum: 12, allow_nil: true
@@ -20,29 +24,12 @@ module ReviseAuth
20
24
 
21
25
  # Generates a confirmation token and send email to the user
22
26
  def send_confirmation_instructions
23
- update!(
24
- confirmation_token: self.class.generate_unique_secure_token(length: ActiveRecord::SecureToken::MINIMUM_TOKEN_LENGTH),
25
- confirmation_sent_at: Time.current
26
- )
27
- ReviseAuth::Mailer.with(user: self).confirm_email.deliver_later
27
+ token = generate_token_for(:email_verification)
28
+ ReviseAuth::Mailer.with(user: self, token: token).confirm_email.deliver_later
28
29
  end
29
30
 
30
- # Confirms an email address change
31
31
  def confirm_email_change
32
- if confirmation_period_expired?
33
- false
34
- else
35
- update(
36
- confirmed_at: Time.current,
37
- email: unconfirmed_email,
38
- unconfirmed_email: nil
39
- )
40
- end
41
- end
42
-
43
- # Checks whether the confirmation token is within the valid time
44
- def confirmation_period_expired?
45
- confirmation_sent_at.before?(1.day.ago)
32
+ update(confirmed_at: Time.current, email: unconfirmed_email)
46
33
  end
47
34
  end
48
35
  end
@@ -1,3 +1,3 @@
1
1
  module ReviseAuth
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/revise_auth.rb CHANGED
@@ -4,7 +4,6 @@ require "revise_auth/routes"
4
4
 
5
5
  module ReviseAuth
6
6
  autoload :Authentication, "revise_auth/authentication"
7
- autoload :Backports, "revise_auth/backports"
8
7
  autoload :Current, "revise_auth/current"
9
8
  autoload :Model, "revise_auth/model"
10
9
  autoload :RouteConstraint, "revise_auth/route_constraint"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: revise_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Oliver
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-05 00:00:00.000000000 Z
11
+ date: 2023-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 7.0.4
19
+ version: 7.1.0.beta1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 7.0.4
26
+ version: 7.1.0.beta1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bcrypt
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -70,7 +70,6 @@ files:
70
70
  - lib/generators/revise_auth/views_generator.rb
71
71
  - lib/revise_auth.rb
72
72
  - lib/revise_auth/authentication.rb
73
- - lib/revise_auth/backports.rb
74
73
  - lib/revise_auth/current.rb
75
74
  - lib/revise_auth/engine.rb
76
75
  - lib/revise_auth/model.rb
@@ -100,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
99
  - !ruby/object:Gem::Version
101
100
  version: '0'
102
101
  requirements: []
103
- rubygems_version: 3.4.7
102
+ rubygems_version: 3.4.19
104
103
  signing_key:
105
104
  specification_version: 4
106
105
  summary: Simple authentication for Ruby on Rails apps
@@ -1,24 +0,0 @@
1
- module ReviseAuth
2
- module Backports
3
- extend ActiveSupport::Concern
4
-
5
- class_methods do
6
- # Prevent timing-based enumeration attacks.
7
- # This can be removed when Rails 7.1 is released.
8
- def authenticate_by(attributes)
9
- passwords, identifiers = attributes.to_h.partition do |name, value|
10
- !has_attribute?(name) && has_attribute?("#{name}_digest")
11
- end.map(&:to_h)
12
-
13
- raise ArgumentError, "One or more password arguments are required" if passwords.empty?
14
- raise ArgumentError, "One or more finder arguments are required" if identifiers.empty?
15
- if (record = find_by(identifiers))
16
- record if passwords.count { |name, value| record.send(:"authenticate_#{name}", value) } == passwords.size
17
- else
18
- new(passwords)
19
- nil
20
- end
21
- end
22
- end
23
- end
24
- end