email_check 0.1.3 → 0.1.4

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
  SHA1:
3
- metadata.gz: 4bf533c13a6a88356fa0a63c9b0a28c615c7cb83
4
- data.tar.gz: 9733241a0b509581d08337596b1d85791c3f3a31
3
+ metadata.gz: 2fa37a71c436036dacc36c1bf38d1fc276e3a644
4
+ data.tar.gz: 56c787b14b00b78172b51d0b12a58252d1de5d00
5
5
  SHA512:
6
- metadata.gz: 2f7475efee8831a063a73743191bbf8bb0cb151c0280fe28a032cbd2e0bafce7e94c51a24001dc288e3e774b20c1a1ab468e28d9c1803685aa07fe811d3466a9
7
- data.tar.gz: 42c62d74ddf63ce8969966def0032cc5644676d38984fbfc496f97d338b2d958975f3cebc58515f4dc61e7706f68225b36f18cc74fc69b58273a4c91723d1bbc
6
+ metadata.gz: 4837b5e6772915a42264e22a54e8d656cb5a30f596d899f74b0e97d199b620e68822e6eb73156a3fa5e25c9127e74af7ad4ba7b7051565f53d7da7a4b4200e32
7
+ data.tar.gz: e9c9d583eecec2a3395261f285fd53815875f9269539f4ae3f424faedf94c21b2a587e292b14c65c23b489a1afdd84cfe099d51ba03f018e0408994d2b909bb4
data/README.md CHANGED
@@ -13,6 +13,8 @@ This gem provides a robust mechanism to validate email addresses and restrict ac
13
13
  This gem also ships with a data-set of free and [disposable](http://en.wikipedia.org/wiki/Disposable_email_address)
14
14
  email domains which are used for validation checks.
15
15
 
16
+ You can also block certain usernames from creating accounts. Examples: admin, root
17
+
16
18
  ### Validation mechanisms
17
19
  - Uses the mail gem.
18
20
  - Checks the domain's MX record
@@ -47,9 +49,20 @@ To validate that the domain is not blacklisted:
47
49
  ```ruby
48
50
  validates :email, email: { blacklist:true}
49
51
  ```
52
+
53
+ To validate that the username is not blocked
54
+ ```ruby
55
+ validates :email, email: { blocked_usernames:true }
56
+
50
57
  Everything together:
51
58
  ```ruby
52
- validates :email, email: { mx: true, disposable:true, free:true, blacklist:true}
59
+ validates :email, email: {
60
+ mx: true,
61
+ disposable:true,
62
+ free:true,
63
+ blacklist:true,
64
+ blocked_usernames:true,
65
+ message: "Please register with your corporate email" }
53
66
  ```
54
67
 
55
68
  ### Modifying inbuilt lists
@@ -64,17 +77,18 @@ EmailCheck.whitelisted_domains << 'gmail.com'
64
77
  EmailCheck.free_email_domains << 'thenewgmail.com'
65
78
  # Setting a domain in the blacklist also will blacklist all subdomains
66
79
  EmailCheck.blacklisted_domains << 'lvh.me'
80
+ EmailCheck.blocked_usernames << 'anonymous'
67
81
  ```
68
82
 
69
83
  ## Requirements
70
- This gem is tested with Rails 4.0. Ruby versions tested:
84
+ This gem is tested with Rails 4.0+. Ruby versions tested:
71
85
  - Ruby 2.0
72
86
  - Ruby 2.1
73
87
  - Ruby 2.2
74
88
 
75
89
  ## Credits
76
- This code is heavily based upon: [lisinge/valid_email2](https://github.com/lisinge/valid_email2)
77
- Data is from: [lavab/disposable](https://github.com/lavab/disposable/blob/master/domains.txt) and
90
+ - This code is heavily based upon: [lisinge/valid_email2](https://github.com/lisinge/valid_email2)
91
+ - Data is from: [lavab/disposable](https://github.com/lavab/disposable/blob/master/domains.txt) and
78
92
  [willwhite/freemail](https://github.com/willwhite/freemail/blob/master/data/free.txt)
79
93
 
80
94
  [Gem Version]: https://rubygems.org/gems/email_check
@@ -6,6 +6,7 @@ module EmailCheck
6
6
  @@disposable_email_domains ||= YAML.load_file(File.expand_path("../../vendor/disposable.yml", __FILE__))
7
7
  @@free_email_domains ||= YAML.load_file(File.expand_path("../../vendor/free.yml", __FILE__))
8
8
  @@blacklisted_domains ||= YAML.load_file(File.expand_path("../../vendor/blacklist.yml", __FILE__))
9
+ @@blocked_usernames ||= YAML.load_file(File.expand_path("../../vendor/blocked_usernames.yml", __FILE__))
9
10
 
10
11
  # Disposable email providers
11
12
  def self.disposable_email_domains
@@ -42,4 +43,12 @@ module EmailCheck
42
43
  def self.whitelisted_domains=(list)
43
44
  @@whitelisted_domains = list
44
45
  end
46
+
47
+ def self.blocked_usernames
48
+ @@blocked_usernames ||= []
49
+ end
50
+
51
+ def self.blocked_usernames=(list)
52
+ @@blocked_usernames = list
53
+ end
45
54
  end
@@ -33,6 +33,10 @@ module EmailCheck
33
33
  EmailCheck.whitelisted_domains.include?(@email.domain)
34
34
  end
35
35
 
36
+ def blocked_username?
37
+ EmailCheck.blocked_usernames.include?(@email.local.downcase)
38
+ end
39
+
36
40
  def domain_has_mx?
37
41
  return false unless format_valid?
38
42
 
@@ -12,6 +12,10 @@ class EmailValidator < ActiveModel::EachValidator
12
12
 
13
13
  return if address.whitelisted?
14
14
 
15
+ if options[:blocked_usernames]
16
+ error(record, attribute) && return if address.blocked_username?
17
+ end
18
+
15
19
  if options[:disposable]
16
20
  error(record, attribute) && return if address.disposable?
17
21
  end
@@ -1,3 +1,3 @@
1
1
  module EmailCheck
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -0,0 +1,21 @@
1
+ ---
2
+ - abuse
3
+ - admin
4
+ - api
5
+ - create
6
+ - delete
7
+ - destroy
8
+ - feedback
9
+ - help
10
+ - hostmaster
11
+ - index
12
+ - new
13
+ - noreply
14
+ - postmaster
15
+ - root
16
+ - show
17
+ - support
18
+ - unsubscribe
19
+ - unknown
20
+ - update
21
+ - workfeed
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: email_check
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darshan Patil
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-04-28 00:00:00.000000000 Z
11
+ date: 2015-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -132,6 +132,7 @@ files:
132
132
  - lib/email_check/email_validator.rb
133
133
  - lib/email_check/version.rb
134
134
  - vendor/blacklist.yml
135
+ - vendor/blocked_usernames.yml
135
136
  - vendor/disposable.yml
136
137
  - vendor/free.yml
137
138
  homepage: https://github.com/dapatil/email_check