How can I blacklist usernames with Devise?

扶醉桌前 提交于 2019-12-05 02:43:56

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/13003546/how-can-i-blacklist-usernames-with-devise

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!