Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I blacklist usernames with Devise?

I have Devise setup to allow login with email or username. With your username you can have a vanity URL like so: vanity.com/username. My User model thus has attr_accessible :username as well as attr_accessor :login.

To prevent usernames from colliding with future features, I want to implement a blacklist on certain usernames. You can see a nice example list in use by GitHub here.

I'm new to Devise and have searched the how-to's in their wiki to see if this use case or anything like it is covered there. It doesn't seem to be.

How can I blacklist certain usernames for registration in Devise?

like image 618
Josh Smith Avatar asked Jan 15 '23 06:01

Josh Smith


1 Answers

There was an easier way to do this than having to modify Devise's controllers.

In the User model all I had to do was:

validates :username, :exclusion => %w(about blog ...)

Way too simple.

like image 138
Josh Smith Avatar answered Jan 31 '23 10:01

Josh Smith