Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent user registration based on blacklists in Rails [closed]

Is there a way to create a blacklist to disallow certain users from signing up by filter through their parameters during the registration process?

The idea is to prevent users that use displosable email addresses (e.g. 10minutemail) from signing up.

like image 906
Nuno Silva Avatar asked Mar 05 '14 15:03

Nuno Silva


3 Answers

There is a gem for that:

https://github.com/lisinge/valid_email2

Install it and add:

validates :email, email: { mx: true, disposable: true }
like image 76
user3692873 Avatar answered Nov 08 '22 19:11

user3692873


Not sure of a gem but I think it's pretty simple to roll your own. Just place a before_filter that calls up a method :permitted?

You could use a table on the db or a yaml file depending on your needs. - Use yaml file if the contents are statics (also it's much faster)

in the permitted method check use a regex to check if it matches

def permitted?
 config=YAML.load_file('file.yml')
 config.each do |domain|
   email.match(domain)
end

You can use different regex to do the matches

like image 26
lsaffie Avatar answered Nov 08 '22 17:11

lsaffie


Here is JavaScript solution: https://github.com/AppBeat-io/JavaScript

Usage example:

AppBeat.Email.isDisposable('[email protected]'); //returns true
AppBeat.Email.isDisposable('[email protected]'); //returns true
AppBeat.Email.isDisposable('   [email protected]   '); //returns true
AppBeat.Email.isDisposable('@mailinator.com'); //returns true
AppBeat.Email.isDisposable('mailinator.com'); //returns true
AppBeat.Email.isDisposable('unknown-domain.some-domain'); //returns false
AppBeat.Email.isDisposable('[email protected]'); //returns false
AppBeat.Email.isDisposable('[email protected]'); //returns false (whitelisted)
AppBeat.Email.isDisposable('[email protected]'); //returns false (whitelisted)
like image 40
Mark Avatar answered Nov 08 '22 18:11

Mark