使用 Devise for Rails 禁止/阻止用户的最佳方法是什么? [英] What is the best way to ban/block users with Devise for Rails?

查看:20
本文介绍了使用 Devise for Rails 禁止/阻止用户的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Rails 应用中使用 Devise 进行身份验证,我希望能够阻止某些帐户并防止用户使用被阻止的电子邮件重新注册.我只是不确定最好的方法是什么.

I'm using Devise for authentication in my rails app and I'd like to be able to block certain accounts and prevent users from reregistering with a blocked email. I'm just not sure what the best way is to go about it.

我的第一个想法是覆盖会话和注册控制器以检查具有阻塞位的用户的模型,但我觉得可能有更优雅的方法.

My first thought was to override the sessions and registrations controllers to check the model for a user with a blocked bit, but I have a feeling there might be a more elegant way.

推荐答案

我会这样做:

def after_sign_in_path_for(resource)
  if resource.is_a?(User) && resource.banned?
    sign_out resource
    banned_user_path
  else
   super
  end
end

这篇关于使用 Devise for Rails 禁止/阻止用户的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆