valid_email 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -0
- data/lib/valid_email/ban_disposable_email_validator.rb +13 -3
- data/lib/valid_email/email_validator.rb +1 -1
- data/lib/valid_email/validate_email.rb +10 -0
- data/lib/valid_email/version.rb +1 -1
- data/spec/email_validator_spec.rb +20 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e0da2f8d6e1b69a777c0d9a6bb14632fa577ecfa55acb7128d436e1543a6842
|
4
|
+
data.tar.gz: c8a125e2971de31cd1e43a49827af99cb1a44130082c555b448083aa1fc6bbaf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 736072b973d66828d1f2cd78b6248599a5ecc3d054d0cbbd1354a4735447a97024575649c7bbe110edb576f18cedd647d378ceb12a9d8344639179c3c8d8ade0
|
7
|
+
data.tar.gz: 52fa87c50d4bf5570779706a39dea8c803b894256d7a92563b0b02009f92b262b6439565d4efd5345b65974f41dbd899085c6349f7c1cb4a5e9c82abcf21efe1
|
data/README.md
CHANGED
@@ -74,6 +74,17 @@ validates :email,
|
|
74
74
|
}
|
75
75
|
```
|
76
76
|
|
77
|
+
You can also detect a partial match on disposable accounts, good for services that use subdomains.
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
validates :email,
|
81
|
+
email: {
|
82
|
+
message: I18n.t('validations.errors.models.user.invalid_email')
|
83
|
+
ban_disposable_email: true,
|
84
|
+
partial: true
|
85
|
+
}
|
86
|
+
```
|
87
|
+
|
77
88
|
If you don't want the MX validator stuff, just require the right file
|
78
89
|
|
79
90
|
```ruby
|
@@ -15,9 +15,19 @@ class BanDisposableEmailValidator < ActiveModel::EachValidator
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def validate_each(record, attribute, value)
|
18
|
-
|
19
|
-
|
18
|
+
# Check if part of domain is in disposable_email_services yml list
|
19
|
+
if options[:partial]
|
20
|
+
r = ValidateEmail.ban_partial_disposable_email?(value)
|
21
|
+
record.errors.add attribute, (options[:message] ||
|
22
|
+
I18n.t(:invalid, :scope => "valid_email.validations.email")) unless r
|
20
23
|
|
21
|
-
|
24
|
+
r
|
25
|
+
else
|
26
|
+
r = ValidateEmail.ban_disposable_email?(value)
|
27
|
+
record.errors.add attribute, (options[:message] ||
|
28
|
+
I18n.t(:invalid, :scope => "valid_email.validations.email")) unless r
|
29
|
+
|
30
|
+
r
|
31
|
+
end
|
22
32
|
end
|
23
33
|
end
|
@@ -18,7 +18,7 @@ class EmailValidator < ActiveModel::EachValidator
|
|
18
18
|
# Check if domain is disposable
|
19
19
|
if r && options[:ban_disposable_email]
|
20
20
|
require 'valid_email/ban_disposable_email_validator'
|
21
|
-
r = BanDisposableEmailValidator.new(:attributes => attributes, message: options[:message]).validate(record)
|
21
|
+
r = BanDisposableEmailValidator.new(:attributes => attributes, message: options[:message], partial: options[:partial]).validate(record)
|
22
22
|
end
|
23
23
|
unless r
|
24
24
|
msg = (options[:message] || I18n.t(:invalid, :scope => "valid_email.validations.email"))
|
@@ -128,5 +128,15 @@ class ValidateEmail
|
|
128
128
|
rescue Mail::Field::ParseError
|
129
129
|
false
|
130
130
|
end
|
131
|
+
|
132
|
+
def ban_partial_disposable_email?(value)
|
133
|
+
m = Mail::Address.new(value)
|
134
|
+
m.domain && !BanDisposableEmailValidator.config.any? do |bde|
|
135
|
+
next if bde == nil
|
136
|
+
m.domain.end_with?(bde)
|
137
|
+
end
|
138
|
+
rescue Mail::Field::ParseError
|
139
|
+
false
|
140
|
+
end
|
131
141
|
end
|
132
142
|
end
|
data/lib/valid_email/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ValidEmailVersion = "0.2.
|
1
|
+
ValidEmailVersion = "0.2.1"
|
@@ -43,6 +43,10 @@ describe EmailValidator do
|
|
43
43
|
validates :email, :email => {:ban_disposable_email => true}
|
44
44
|
end
|
45
45
|
|
46
|
+
person_class_partial_disposable_email = Class.new(email_class) do
|
47
|
+
validates :email, :email => {:ban_disposable_email => true, :partial => true}
|
48
|
+
end
|
49
|
+
|
46
50
|
person_class_nil_allowed = Class.new(email_class) do
|
47
51
|
validates :email, :email => {:allow_nil => true}
|
48
52
|
end
|
@@ -147,7 +151,6 @@ describe EmailValidator do
|
|
147
151
|
expect(subject.valid?).to be_falsey
|
148
152
|
expect(subject).to have_error_messages(:email, errors)
|
149
153
|
end
|
150
|
-
|
151
154
|
end
|
152
155
|
|
153
156
|
describe "validating email with MX and fallback to A" do
|
@@ -248,6 +251,22 @@ describe EmailValidator do
|
|
248
251
|
end
|
249
252
|
end
|
250
253
|
|
254
|
+
describe "validating email against partial disposable service match" do
|
255
|
+
subject { person_class_partial_disposable_email.new }
|
256
|
+
|
257
|
+
it "passes when email from trusted email services" do
|
258
|
+
subject.email = 'john@test.mail.ru'
|
259
|
+
expect(subject.valid?).to be_truthy
|
260
|
+
expect(subject.errors[:email]).to be_empty
|
261
|
+
end
|
262
|
+
|
263
|
+
it "fails when disposable email services partially matches email domain" do
|
264
|
+
subject.email = 'john@sub.grr.la'
|
265
|
+
expect(subject.valid?).to be_falsey
|
266
|
+
expect(subject.errors[:email]).to eq errors
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
251
270
|
describe "validating domain" do
|
252
271
|
subject { person_class_domain.new }
|
253
272
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: valid_email
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ramihajamalala Hery
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -145,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
145
|
- !ruby/object:Gem::Version
|
146
146
|
version: '0'
|
147
147
|
requirements: []
|
148
|
-
rubygems_version: 3.
|
148
|
+
rubygems_version: 3.5.6
|
149
149
|
signing_key:
|
150
150
|
specification_version: 4
|
151
151
|
summary: ActiveModel Validation for email
|