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 +4 -4
- data/README.md +1 -1
- data/app/controllers/revise_auth/email_controller.rb +1 -2
- data/app/mailers/revise_auth/mailer.rb +4 -1
- data/app/views/revise_auth/mailer/confirm_email.html.erb +2 -2
- data/lib/generators/revise_auth/model_generator.rb +0 -2
- data/lib/revise_auth/model.rb +9 -22
- data/lib/revise_auth/version.rb +1 -1
- data/lib/revise_auth.rb +0 -1
- metadata +5 -6
- data/lib/revise_auth/backports.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5d5afd1201c6a751a50e0c153589fa552e949c45cad6da9f3147670e6aaf274
|
4
|
+
data.tar.gz: 9d546d451af57bbc97d4e6dbae0dc83b00b6818fa14210f1a32735f79295686e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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,7 +1,7 @@
|
|
1
|
-
<p>Welcome <%=
|
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
|
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>
|
data/lib/revise_auth/model.rb
CHANGED
@@ -2,12 +2,16 @@ module ReviseAuth
|
|
2
2
|
module Model
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
|
-
included do
|
6
|
-
|
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
|
-
|
24
|
-
|
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
|
-
|
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
|
data/lib/revise_auth/version.rb
CHANGED
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.
|
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-
|
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.
|
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.
|
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.
|
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
|