Rails + Devise - Is there a way to BAN a user so they can't login or reset their password? -


i have lot of users devise , want ban few problem makers. devise have support built in?

thanks

i implemented in project myself. did similar kleber above, defined in app/controllers/sessions_controller.rb (overriding devise)...

class sessionscontroller < devise::sessionscontroller  protected    def after_sign_in_path_for(resource)     if resource.is_a?(user) && resource.banned?       sign_out resource       flash[:error] = "this account has been suspended violation of...."       root_path     else       super     end    end  end 

and added boolean column users called 'banned,' moderators check checkbox when editing user in backend, , boolean return true.

but there 1 flaw...if user logged in , banned, still had access doing stuff on site (comments, etc) @ least until session expired or logged out. did in app/controllers/application_controller.rb...

class applicationcontroller < actioncontroller::base   before_filter :banned?    def banned?     if current_user.present? && current_user.banned?       sign_out current_user       flash[:error] = "this account has been suspended...."       root_path     end   end end 

that'll automatically log them out if ban detected. anyway, not sure whole thing "best" way factor whole thing i'm newer rails, whole thing works me , hope @ least give start.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -